summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/karma/grammar.cpp
blob: d95956de624c2fa4645ba3f975585de92fbcd6bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//  Copyright (c) 2001-2011 Hartmut Kaiser
// 
//  Distributed under the Boost Software License, Version 1.0. (See accompanying 
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>

#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_string.hpp>
#include <boost/spirit/include/karma_numeric.hpp>
#include <boost/spirit/include/karma_nonterminal.hpp>
#include <boost/spirit/include/karma_action.hpp>

#include <string>
#include <iostream>

#include "test.hpp"

using namespace spirit_test;
using namespace boost::spirit;
using namespace boost::spirit::ascii;

typedef spirit_test::output_iterator<char>::type outiter_type;

struct num_list : karma::grammar<outiter_type, space_type>
{
    num_list() : num_list::base_type(start)
    {
        using boost::spirit::int_;
        num1 = int_(123);
        num2 = int_(456);
        num3 = int_(789);
        start = num1 << ',' << num2 << ',' << num3;
    }

    karma::rule<outiter_type, space_type> start, num1, num2, num3;
};

int
main()
{
    { // simple grammar test
        num_list nlist;
        BOOST_TEST(test_delimited("123 , 456 , 789 ", nlist, space));
    }

    { // direct access to the rules
        num_list def;
        BOOST_TEST(test_delimited("123 ", def.num1, space));
        BOOST_TEST(test_delimited("123 , 456 , 789 ", def.start, space));
    }

    return boost::report_errors();
}