]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
1e59de90 | 6 | #include <boost/spirit/include/karma_grammar.hpp> |
7c673cae FG |
7 | |
8 | #include <boost/spirit/include/karma_operator.hpp> | |
9 | #include <boost/spirit/include/karma_char.hpp> | |
10 | #include <boost/spirit/include/karma_string.hpp> | |
11 | #include <boost/spirit/include/karma_numeric.hpp> | |
12 | #include <boost/spirit/include/karma_nonterminal.hpp> | |
13 | #include <boost/spirit/include/karma_action.hpp> | |
7c673cae FG |
14 | |
15 | #include <string> | |
16 | #include <iostream> | |
17 | ||
18 | #include "test.hpp" | |
19 | ||
20 | using namespace spirit_test; | |
21 | using namespace boost::spirit; | |
22 | using namespace boost::spirit::ascii; | |
23 | ||
24 | typedef spirit_test::output_iterator<char>::type outiter_type; | |
25 | ||
26 | struct num_list : karma::grammar<outiter_type, space_type> | |
27 | { | |
28 | num_list() : num_list::base_type(start) | |
29 | { | |
30 | using boost::spirit::int_; | |
31 | num1 = int_(123); | |
32 | num2 = int_(456); | |
33 | num3 = int_(789); | |
34 | start = num1 << ',' << num2 << ',' << num3; | |
35 | } | |
36 | ||
37 | karma::rule<outiter_type, space_type> start, num1, num2, num3; | |
38 | }; | |
39 | ||
40 | int | |
41 | main() | |
42 | { | |
43 | { // simple grammar test | |
44 | num_list nlist; | |
45 | BOOST_TEST(test_delimited("123 , 456 , 789 ", nlist, space)); | |
46 | } | |
47 | ||
48 | { // direct access to the rules | |
49 | num_list def; | |
50 | BOOST_TEST(test_delimited("123 ", def.num1, space)); | |
51 | BOOST_TEST(test_delimited("123 , 456 , 789 ", def.start, space)); | |
52 | } | |
53 | ||
54 | return boost::report_errors(); | |
55 | } | |
56 |