]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/grammar.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2010 Joel de Guzman
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/detail/lightweight_test.hpp>
8 #include <boost/spirit/include/qi_operator.hpp>
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_nonterminal.hpp>
13 #include <boost/spirit/include/qi_action.hpp>
14 #include <boost/spirit/include/phoenix_core.hpp>
15 #include <boost/spirit/include/phoenix_operator.hpp>
21 using spirit_test::test
;
22 using spirit_test::test_attr
;
24 using boost::spirit::ascii::space_type
;
25 using boost::spirit::ascii::space
;
26 using boost::spirit::int_
;
27 using boost::spirit::qi::grammar
;
28 using boost::spirit::qi::rule
;
29 using boost::spirit::_val
;
30 using boost::spirit::_r1
;
31 using boost::spirit::lit
;
33 struct num_list
: grammar
<char const*, space_type
>
35 num_list() : base_type(start
)
37 using boost::spirit::int_
;
39 start
= num
>> *(',' >> num
);
42 rule
<char const*, space_type
> start
, num
;
45 struct inh_g
: grammar
<char const*, int(int), space_type
>
47 inh_g() : base_type(start
)
49 start
= lit("inherited")[_val
= _r1
];
52 rule
<char const*, int(int), space_type
> start
, num
;
55 struct my_skipper
: grammar
<char const*>
57 my_skipper() : base_type(start
)
62 rule
<char const*> start
, num
;
65 struct num_list2
: grammar
<char const*, my_skipper
>
67 num_list2() : base_type(start
)
69 using boost::spirit::int_
;
71 start
= num
>> *(',' >> num
);
74 rule
<char const*, my_skipper
> start
, num
;
77 template <typename Iterator
, typename Skipper
>
78 struct num_list3
: grammar
<Iterator
, Skipper
>
80 template <typename Class
>
81 num_list3(Class
&) : grammar
<Iterator
, Skipper
>(start
)
83 using boost::spirit::int_
;
85 start
= num
>> *(',' >> num
);
88 rule
<Iterator
, Skipper
> start
, num
;
94 { // simple grammar test
97 BOOST_TEST(test("123, 456, 789", nlist
, space
));
100 { // simple grammar test with user-skipper
104 BOOST_TEST(test("123, 456, 789", nlist
, skip
));
107 { // direct access to the rules
110 BOOST_TEST(test("123", g
.num
, space
));
111 BOOST_TEST(test("123, 456, 789", g
.start
, space
));
114 { // grammar with inherited attributes
118 BOOST_TEST(test_attr("inherited", g
.start(123), n
, space
)); // direct to the rule
119 BOOST_TEST(n
== 123);
120 BOOST_TEST(test_attr("inherited", g(123), n
, space
)); // using the grammar
121 BOOST_TEST(n
== 123);
124 return boost::report_errors();