]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/lex/set_token_value_phoenix.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / lex / set_token_value_phoenix.cpp
1 // Copyright (c) 2009 Carl Barron
2 //
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)
5
6 #include <string>
7 #include <iostream>
8
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>
13
14 namespace lex = boost::spirit::lex;
15 namespace phoenix = boost::phoenix;
16
17 ///////////////////////////////////////////////////////////////////////////////
18 struct square_impl
19 {
20 template <class>
21 struct result { typedef int type; };
22
23 template <class A>
24 int operator () (const A &x) const
25 { return (x) * (x); }
26 };
27
28 phoenix::function<square_impl> const square = square_impl();
29
30 ///////////////////////////////////////////////////////////////////////////////
31 template <class Lexer>
32 struct test_tokens : lex::lexer<Lexer>
33 {
34 test_tokens()
35 {
36 a = "a";
37 this->self = a [lex::_val = square(*lex::_start)];
38 }
39
40 lex::token_def<int> a;
41 };
42
43 struct catch_result
44 {
45 template <class Token>
46 bool operator() (Token const& x) const
47 {
48 BOOST_TEST(x.value().which() == 1);
49 BOOST_TEST(boost::get<int>(x.value()) == 9409); // 9409 == 'a' * 'a'
50 return true;
51 }
52 };
53
54 ///////////////////////////////////////////////////////////////////////////////
55 int main()
56 {
57 typedef lex::lexertl::token<std::string::iterator
58 , boost::mpl::vector<int> > token_type;
59
60 std::string in = "a";
61 std::string::iterator first(in.begin());
62
63 test_tokens<lex::lexertl::actor_lexer<token_type> > the_lexer;
64 BOOST_TEST(lex::tokenize(first, in.end(), the_lexer, catch_result()));
65
66 return boost::report_errors();
67 }