]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/pattern2.cpp
1 // Copyright (c) 2001-2011 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
;
36 karma::rule
<outiter_type
, locals
<std::string
> > start
;
38 start
= string
[_1
= "abc", _a
= _1
] << int_
[_1
= 10] << string
[_1
= _a
];
39 BOOST_TEST(test("abc10abc", start
));
43 karma::rule
<outiter_type
, space_type
, locals
<std::string
> > start
;
45 start
= string
[_1
= "abc", _a
= _1
] << int_
[_1
= 10] << string
[_1
= _a
];
46 BOOST_TEST(test_delimited("abc 10 abc ", start
, space
));
51 typedef variant
<char, int, double> var_type
;
53 karma::rule
<outiter_type
, var_type()> d
, start
;
55 d
= start
.alias(); // d will always track start
57 start
= (char_
| int_
| double_
)[_1
= _val
];
60 BOOST_TEST(test("a", d
, v
));
62 BOOST_TEST(test("10", d
, v
));
64 BOOST_TEST(test("12.4", d
, v
));
68 typedef variant
<char, int, double> var_type
;
70 karma::rule
<outiter_type
, space_type
, var_type()> d
, start
;
72 d
= start
.alias(); // d will always track start
74 start
= (char_
| int_
| double_
)[_1
= _val
];
77 BOOST_TEST(test_delimited("a ", d
, v
, space
));
79 BOOST_TEST(test_delimited("10 ", d
, v
, space
));
81 BOOST_TEST(test_delimited("12.4 ", d
, v
, space
));
85 typedef variant
<char, int, double> var_type
;
87 karma::rule
<outiter_type
, var_type()> d
, start
;
89 d
= start
.alias(); // d will always track start
91 start
%= char_
| int_
| double_
;
94 BOOST_TEST(test("a", d
, v
));
96 BOOST_TEST(test("10", d
, v
));
98 BOOST_TEST(test("12.4", d
, v
));
100 start
= char_
| int_
| double_
;
103 BOOST_TEST(test("a", d
, v
));
105 BOOST_TEST(test("10", d
, v
));
107 BOOST_TEST(test("12.4", d
, v
));
111 typedef variant
<char, int, double> var_type
;
113 karma::rule
<outiter_type
, space_type
, var_type()> d
, start
;
115 d
= start
.alias(); // d will always track start
117 start
%= char_
| int_
| double_
;
120 BOOST_TEST(test_delimited("a ", d
, v
, space
));
122 BOOST_TEST(test_delimited("10 ", d
, v
, space
));
124 BOOST_TEST(test_delimited("12.4 ", d
, v
, space
));
126 start
= char_
| int_
| double_
;
129 BOOST_TEST(test_delimited("a ", d
, v
, space
));
131 BOOST_TEST(test_delimited("10 ", d
, v
, space
));
133 BOOST_TEST(test_delimited("12.4 ", d
, v
, space
));
136 ///////////////////////////////////////////////////////////////////////////
138 using boost::spirit::karma::int_
;
139 using boost::spirit::karma::_1
;
140 using boost::spirit::karma::_val
;
141 using boost::spirit::karma::space
;
142 using boost::spirit::karma::space_type
;
144 karma::rule
<outiter_type
, int()> r1
= int_
;
145 karma::rule
<outiter_type
, space_type
, int()> r2
= int_
;
149 BOOST_TEST(test("123", r1
[_1
= _val
], i
));
150 BOOST_TEST(test_delimited("456 ", r2
[_1
= _val
], j
, space
));
153 return boost::report_errors();