1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Joel de Guzman |
3 | |
4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | =============================================================================*/ |
7 | #include <boost/spirit/include/qi_lazy.hpp> |
8 | |
9 | #include <boost/spirit/include/qi_char.hpp> |
10 | #include <boost/spirit/include/qi_string.hpp> |
11 | #include <boost/spirit/include/qi_numeric.hpp> |
12 | #include <boost/spirit/include/qi_auxiliary.hpp> |
13 | #include <boost/spirit/include/qi_action.hpp> |
14 | #include <boost/spirit/include/qi_nonterminal.hpp> |
15 | #include <boost/spirit/include/qi_operator.hpp> |
16 | #include <boost/spirit/include/support_argument.hpp> |
17 | #include <boost/phoenix/core.hpp> |
18 | #include <boost/phoenix/operator.hpp> |
19 | |
20 | #include <iostream> |
21 | #include "test.hpp" |
22 | |
23 | int |
24 | main() |
25 | { |
26 | using spirit_test::test; |
27 | using spirit_test::test_attr; |
28 | |
29 | namespace qi = boost::spirit::qi; |
30 | using boost::spirit::qi::_1; |
31 | using boost::spirit::qi::_val; |
32 | using boost::spirit::qi::int_; |
33 | using boost::spirit::qi::rule; |
34 | using boost::spirit::ascii::char_; |
35 | |
36 | using boost::phoenix::val; |
37 | using boost::phoenix::ref; |
38 | |
39 | { |
40 | BOOST_TEST(test("123" , val(int_))); |
41 | } |
42 | |
43 | { |
44 | int result; |
45 | BOOST_TEST(test("123" , qi::lazy(val(int_))[ref(result) = _1])); |
46 | BOOST_TEST((result == 123)); |
47 | } |
48 | |
49 | { |
50 | rule<char const*, char()> r; |
51 | |
52 | r = char_[_val = _1] >> *qi::lazy(f: _val); |
53 | |
54 | BOOST_TEST(test("aaaaaaaaaaaa" , r)); |
55 | BOOST_TEST(!test("abbbbbbbbbb" , r)); |
56 | BOOST_TEST(test("bbbbbbbbbbb" , r)); |
57 | } |
58 | |
59 | { |
60 | rule<char const*, std::string()> r; |
61 | |
62 | r = |
63 | '<' >> *(char_ - '>')[_val += _1] >> '>' |
64 | >> "</" >> qi::lazy(f: _val) >> '>' |
65 | ; |
66 | |
67 | BOOST_TEST(test("<tag></tag>" , r)); |
68 | BOOST_TEST(!test("<foo></bar>" , r)); |
69 | } |
70 | |
71 | return boost::report_errors(); |
72 | } |
73 | |