]>
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.hpp>
14 namespace lex
= boost::spirit::lex
;
15 namespace phoenix
= boost::phoenix
;
17 ///////////////////////////////////////////////////////////////////////////////
18 template <typename Lexer
>
19 struct multi_tokens
: lex::lexer
<Lexer
>
23 multi_tokens() : level(0)
29 using lex::pass_flags
;
35 a
[ ++phoenix::ref(level
) ]
38 _state
= "in_dedenting",
40 _pass
= pass_flags::pass_ignore
45 this->self("in_dedenting") =
47 if_(--phoenix::ref(level
)) [
57 lex::token_def
<> a
, b
, c
, d
;
62 typedef bool result_type
;
64 dumper(std::stringstream
& strm
) : strm(strm
) {}
66 template <typename Token
>
67 bool operator () (Token
const &t
)
69 strm
<< (char)(t
.id() - lex::min_token_id
+ 'a');
73 std::stringstream
& strm
;
76 // silence MSVC warning C4512: assignment operator could not be generated
77 dumper
& operator= (dumper
const&);
80 ///////////////////////////////////////////////////////////////////////////////
83 typedef lex::lexertl::token
<std::string::iterator
> token_type
;
84 typedef lex::lexertl::actor_lexer
<token_type
> base_lexer_type
;
85 typedef multi_tokens
<base_lexer_type
> lexer_type
;
87 std::string
in("AAABBC");
88 std::string::iterator
first(in
.begin());
89 std::stringstream strm
;
92 BOOST_TEST(lex::tokenize(first
, in
.end(), the_lexer
, dumper(strm
)));
93 BOOST_TEST(strm
.str() == "aaabbddd");
95 return boost::report_errors();