]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/grammar.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / grammar.cpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 //
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)
5
6 #include <boost/config/warning_disable.hpp>
7 #include <boost/detail/lightweight_test.hpp>
8
9 #include <boost/spirit/include/karma_operator.hpp>
10 #include <boost/spirit/include/karma_char.hpp>
11 #include <boost/spirit/include/karma_string.hpp>
12 #include <boost/spirit/include/karma_numeric.hpp>
13 #include <boost/spirit/include/karma_nonterminal.hpp>
14 #include <boost/spirit/include/karma_action.hpp>
15 #include <boost/spirit/include/phoenix_core.hpp>
16 #include <boost/spirit/include/phoenix_operator.hpp>
17
18 #include <string>
19 #include <iostream>
20
21 #include "test.hpp"
22
23 using namespace spirit_test;
24 using namespace boost::spirit;
25 using namespace boost::spirit::ascii;
26
27 typedef spirit_test::output_iterator<char>::type outiter_type;
28
29 struct num_list : karma::grammar<outiter_type, space_type>
30 {
31 num_list() : num_list::base_type(start)
32 {
33 using boost::spirit::int_;
34 num1 = int_(123);
35 num2 = int_(456);
36 num3 = int_(789);
37 start = num1 << ',' << num2 << ',' << num3;
38 }
39
40 karma::rule<outiter_type, space_type> start, num1, num2, num3;
41 };
42
43 int
44 main()
45 {
46 { // simple grammar test
47 num_list nlist;
48 BOOST_TEST(test_delimited("123 , 456 , 789 ", nlist, space));
49 }
50
51 { // direct access to the rules
52 num_list def;
53 BOOST_TEST(test_delimited("123 ", def.num1, space));
54 BOOST_TEST(test_delimited("123 , 456 , 789 ", def.start, space));
55 }
56
57 return boost::report_errors();
58 }
59