]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/pattern1.cpp
f141b3d9c8c56338b772050351fb82062862a025
1 // Copyright (c) 2001-2010 Hartmut Kaiser
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)
6 #include <boost/config/warning_disable.hpp>
7 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/include/karma_operator.hpp>
10 #include <boost/spirit/include/karma_char.hpp>
11 #include <boost/spirit/include/karma_auxiliary.hpp>
12 #include <boost/spirit/include/karma_string.hpp>
13 #include <boost/spirit/include/karma_numeric.hpp>
14 #include <boost/spirit/include/karma_nonterminal.hpp>
15 #include <boost/spirit/include/karma_action.hpp>
16 #include <boost/spirit/include/phoenix_core.hpp>
17 #include <boost/spirit/include/phoenix_operator.hpp>
18 #include <boost/spirit/include/phoenix_statement.hpp>
19 #include <boost/spirit/include/phoenix_fusion.hpp>
23 using namespace spirit_test
;
25 ///////////////////////////////////////////////////////////////////////////////
28 using namespace boost
;
29 using namespace boost::spirit
;
30 using namespace boost::spirit::ascii
;
32 typedef spirit_test::output_iterator
<char>::type outiter_type
;
34 // test rule parameter propagation
36 using boost::phoenix::at_c
;
38 karma::rule
<outiter_type
, fusion::vector
<char, int, double>()> start
;
39 fusion::vector
<char, int, double> vec('a', 10, 12.4);
41 start
%= char_
<< int_
<< double_
;
42 BOOST_TEST(test("a1012.4", start
, vec
));
44 karma::rule
<outiter_type
, char()> a
;
45 karma::rule
<outiter_type
, int()> b
;
46 karma::rule
<outiter_type
, double()> c
;
51 start
= a
[_1
= at_c
<0>(_r0
)] << b
[_1
= at_c
<1>(_r0
)] << c
[_1
= at_c
<2>(_r0
)];
52 BOOST_TEST(test("a1012.4", start
, vec
));
54 start
= (a
<< b
<< c
)[_1
= at_c
<0>(_r0
), _2
= at_c
<1>(_r0
), _3
= at_c
<2>(_r0
)];
55 BOOST_TEST(test("a1012.4", start
, vec
));
58 BOOST_TEST(test("a1012.4", start
, vec
));
61 BOOST_TEST(test("a1012.4", start
, vec
));
65 using boost::phoenix::at_c
;
67 karma::rule
<outiter_type
, space_type
, fusion::vector
<char, int, double>()> start
;
68 fusion::vector
<char, int, double> vec('a', 10, 12.4);
70 start
%= char_
<< int_
<< double_
;
71 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
73 karma::rule
<outiter_type
, space_type
, char()> a
;
74 karma::rule
<outiter_type
, space_type
, int()> b
;
75 karma::rule
<outiter_type
, space_type
, double()> c
;
80 start
= a
[_1
= at_c
<0>(_r0
)] << b
[_1
= at_c
<1>(_r0
)] << c
[_1
= at_c
<2>(_r0
)];
81 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
83 start
= (a
<< b
<< c
)[_1
= at_c
<0>(_r0
), _2
= at_c
<1>(_r0
), _3
= at_c
<2>(_r0
)];
84 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
87 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
90 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
93 // test direct initalization
95 using boost::phoenix::at_c
;
97 fusion::vector
<char, int, double> vec('a', 10, 12.4);
98 karma::rule
<outiter_type
, space_type
, fusion::vector
<char, int, double>()>
99 start
= char_
<< int_
<< double_
;;
101 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
103 karma::rule
<outiter_type
, space_type
, char()> a
= char_
<< eps
;
104 karma::rule
<outiter_type
, space_type
, int()> b
= int_
;
105 karma::rule
<outiter_type
, space_type
, double()> c
= double_
;
107 start
= a
[_1
= at_c
<0>(_r0
)] << b
[_1
= at_c
<1>(_r0
)] << c
[_1
= at_c
<2>(_r0
)];
108 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
111 return boost::report_errors();