]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/repository/test/karma/subrule.cpp
1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 // Copyright (c) 2009 Francois Barel
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)
7 #include <boost/config/warning_disable.hpp>
8 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/spirit/include/karma_operator.hpp>
11 #include <boost/spirit/include/karma_char.hpp>
12 #include <boost/spirit/include/karma_auxiliary.hpp>
13 #include <boost/spirit/include/karma_string.hpp>
14 #include <boost/spirit/include/karma_numeric.hpp>
15 #include <boost/spirit/include/karma_nonterminal.hpp>
16 #include <boost/spirit/include/karma_action.hpp>
17 #include <boost/spirit/include/phoenix_core.hpp>
18 #include <boost/spirit/include/phoenix_operator.hpp>
19 #include <boost/spirit/include/phoenix_statement.hpp>
20 #include <boost/spirit/include/phoenix_fusion.hpp>
22 #include <boost/spirit/repository/include/karma_subrule.hpp>
26 using namespace spirit_test
;
28 ///////////////////////////////////////////////////////////////////////////////
31 using namespace boost
;
32 using namespace boost::spirit
;
33 using namespace boost::spirit::karma
;
34 // using namespace boost::spirit::ascii;
35 using boost::spirit::repository::karma::subrule
;
37 typedef spirit_test::output_iterator
<char>::type outiter_type
;
41 rule
<outiter_type
> start
;
45 sr
= char_
[_1
= 'a'] << int_
[_1
= 10] << double_
[_1
= 12.4]
47 BOOST_TEST(test("a1012.4", start
));
49 BOOST_TEST(test("a1012.4", (
50 sr
= (char_
<< int_
<< double_
)[(_1
= 'a', _2
= 10, _3
= 12.4)]
61 , c
= double_
[_1
= 12.4]
63 BOOST_TEST(test("a1012.4", start
));
66 // basic tests with delimiter
68 rule
<outiter_type
, space_type
> start
;
72 sr
= char_
[_1
= 'a'] << int_
[_1
= 10] << double_
[_1
= 12.4]
74 BOOST_TEST(test_delimited("a 10 12.4 ", start
, space
));
76 BOOST_TEST(test_delimited("a 10 12.4 ", (
77 sr
= (char_
<< int_
<< double_
)[(_1
= 'a', _2
= 10, _3
= 12.4)]
88 , c
= double_
[_1
= 12.4]
90 BOOST_TEST(test_delimited("a 10 12.4 ", start
, space
));
93 // basic tests involving a direct parameter
95 typedef variant
<char, int, double> var_type
;
97 rule
<outiter_type
, var_type()> start
;
98 subrule
<0, var_type()> sr
;
101 sr
= (char_
| int_
| double_
)[_1
= _r0
]
105 BOOST_TEST(test("a", start
, v
));
107 BOOST_TEST(test("10", start
, v
));
109 BOOST_TEST(test("12.4", start
, v
));
113 typedef variant
<char, int, double> var_type
;
115 rule
<outiter_type
, space_type
, var_type()> start
;
116 subrule
<0, var_type()> sr
;
119 sr
= (char_
| int_
| double_
)[_1
= _r0
]
123 BOOST_TEST(test_delimited("a ", start
, v
, space
));
125 BOOST_TEST(test_delimited("10 ", start
, v
, space
));
127 BOOST_TEST(test_delimited("12.4 ", start
, v
, space
));
131 rule
<outiter_type
, void(char, int, double)> start
;
132 subrule
<0, void(char, int, double)> sr
;
135 sr
= char_
[_1
= _r1
] << int_
[_1
= _r2
] << double_
[_1
= _r3
]
137 BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
139 BOOST_TEST(test("a1012.4", (
140 sr
= (char_
<< int_
<< double_
)[(_1
= _r1
, _2
= _r2
, _3
= _r3
)]
143 subrule
<1, void(char, int, double)> entry
;
144 subrule
<2, void(char)> a
;
145 subrule
<3, void(int)> b
;
146 subrule
<4, void(double)> c
;
149 entry
= a(_r1
) << b(_r2
) << c(_r3
)
150 , a
= char_
[_1
= _r1
]
152 , c
= double_
[_1
= _r1
]
154 BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
158 rule
<outiter_type
, space_type
, void(char, int, double)> start
;
159 subrule
<0, void(char, int, double)> sr
;
162 sr
= char_
[_1
= _r1
] << int_
[_1
= _r2
] << double_
[_1
= _r3
]
164 BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space
));
166 BOOST_TEST(test_delimited("a 10 12.4 ", (
167 sr
= (char_
<< int_
<< double_
)[(_1
= _r1
, _2
= _r2
, _3
= _r3
)]
168 )('a', 10, 12.4), space
));
170 subrule
<1, void(char, int, double)> entry
;
171 subrule
<2, void(char)> a
;
172 subrule
<3, void(int)> b
;
173 subrule
<4, void(double)> c
;
176 entry
= a(_r1
) << b(_r2
) << c(_r3
)
177 , a
= char_
[_1
= _r1
]
179 , c
= double_
[_1
= _r1
]
181 BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space
));
184 return boost::report_errors();