Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/spirit/test/grammar_def_test.cpp @ 33

Last change on this file since 33 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.0 KB
Line 
1//
2//  Copyright (c) 2005 João Abecasis
3//
4//  Distributed under the Boost Software License, Version 1.0. (See
5//  accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7//
8
9#include <boost/spirit/core.hpp>
10#include <boost/spirit/attribute.hpp>
11#include <boost/spirit/utility/grammar_def.hpp> 
12
13struct my_grammar1
14    : boost::spirit::grammar<my_grammar1>
15{
16    template <typename Scanner>
17    struct definition
18        : boost::spirit::grammar_def<
19            boost::spirit::rule<Scanner>,
20            boost::spirit::same
21        >
22    {
23        definition(my_grammar1 const &)
24        {
25            BOOST_SPIRIT_DEBUG_NODE(start_rule1);
26            BOOST_SPIRIT_DEBUG_NODE(start_rule2);
27
28            start_rule1 = boost::spirit::str_p("int");
29            start_rule2 = boost::spirit::int_p;
30
31            this->start_parsers(start_rule1, start_rule2);
32        }
33
34        boost::spirit::rule<Scanner>
35            start_rule1,
36            start_rule2;
37    };
38};
39
40struct my_closure : boost::spirit::closure<my_closure, int>
41{
42    member1 value;
43};
44
45struct my_grammar2
46    : boost::spirit::grammar<my_grammar2, my_closure::context_t>
47{
48    template <typename Scanner>
49    struct definition
50        : boost::spirit::grammar_def<
51            boost::spirit::rule<Scanner>,
52            boost::spirit::same
53        >
54    {
55        definition(my_grammar2 const &)
56        {
57            BOOST_SPIRIT_DEBUG_NODE(start_rule1);
58            BOOST_SPIRIT_DEBUG_NODE(start_rule2);
59
60            start_rule1 = boost::spirit::str_p("int");
61            start_rule2 = boost::spirit::int_p;
62
63            this->start_parsers(start_rule1, start_rule2);
64        }
65
66        boost::spirit::rule<Scanner>
67            start_rule1,
68            start_rule2;
69    };
70};
71
72int main()
73{
74    my_grammar1 g1;
75    my_grammar2 g2;
76
77    BOOST_SPIRIT_DEBUG_NODE(g1);
78    BOOST_SPIRIT_DEBUG_NODE(g2);
79
80    parse(
81        "int 5",
82        g1.use_parser<0>() >> g2.use_parser<1>(),
83        boost::spirit::space_p
84    );
85}
Note: See TracBrowser for help on using the repository browser.