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
16 #include <string>
17 #include <iostream>
18
19 #include "test.hpp"
20
21 using namespace spirit_test;
22 using namespace boost::spirit;
23 using namespace boost::spirit::ascii;
24
25 typedef spirit_test::output_iterator<char>::type outiter_type;
26
27 struct num_list : karma::grammar<outiter_type, space_type>
28 {
num_listnum_list29 num_list() : num_list::base_type(start)
30 {
31 using boost::spirit::int_;
32 num1 = int_(123);
33 num2 = int_(456);
34 num3 = int_(789);
35 start = num1 << ',' << num2 << ',' << num3;
36 }
37
38 karma::rule<outiter_type, space_type> start, num1, num2, num3;
39 };
40
41 int
main()42 main()
43 {
44 { // simple grammar test
45 num_list nlist;
46 BOOST_TEST(test_delimited("123 , 456 , 789 ", nlist, space));
47 }
48
49 { // direct access to the rules
50 num_list def;
51 BOOST_TEST(test_delimited("123 ", def.num1, space));
52 BOOST_TEST(test_delimited("123 , 456 , 789 ", def.start, space));
53 }
54
55 return boost::report_errors();
56 }
57
58