]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/lex/dedent_handling_phoenix.cpp
1 // Copyright (c) 2009 Carl Barron
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/spirit/include/lex.hpp>
11 #include <boost/spirit/include/lex_lexertl.hpp>
12 #include <boost/spirit/include/phoenix_core.hpp>
13 #include <boost/spirit/include/phoenix_operator.hpp>
14 #include <boost/spirit/include/phoenix_statement.hpp>
16 namespace lex
= boost::spirit::lex
;
17 namespace phoenix
= boost::phoenix
;
19 ///////////////////////////////////////////////////////////////////////////////
20 template <typename Lexer
>
21 struct multi_tokens
: lex::lexer
<Lexer
>
25 multi_tokens() : level(0)
31 using lex::pass_flags
;
37 a
[ ++phoenix::ref(level
) ]
40 _state
= "in_dedenting",
42 _pass
= pass_flags::pass_ignore
47 this->self("in_dedenting") =
49 if_(--phoenix::ref(level
)) [
59 lex::token_def
<> a
, b
, c
, d
;
64 typedef bool result_type
;
66 dumper(std::stringstream
& strm
) : strm(strm
) {}
68 template <typename Token
>
69 bool operator () (Token
const &t
)
71 strm
<< (char)(t
.id() - lex::min_token_id
+ 'a');
75 std::stringstream
& strm
;
77 // silence MSVC warning C4512: assignment operator could not be generated
78 BOOST_DELETED_FUNCTION(dumper
& operator= (dumper
const&));
81 ///////////////////////////////////////////////////////////////////////////////
84 typedef lex::lexertl::token
<std::string::iterator
> token_type
;
85 typedef lex::lexertl::actor_lexer
<token_type
> base_lexer_type
;
86 typedef multi_tokens
<base_lexer_type
> lexer_type
;
88 std::string
in("AAABBC");
89 std::string::iterator
first(in
.begin());
90 std::stringstream strm
;
93 BOOST_TEST(lex::tokenize(first
, in
.end(), the_lexer
, dumper(strm
)));
94 BOOST_TEST(strm
.str() == "aaabbddd");
96 return boost::report_errors();