1 //
2 // Copyright (c) 2005 Joao 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/include/classic_core.hpp>
10 #include <boost/spirit/include/classic_attribute.hpp>
11 #include <boost/spirit/include/classic_grammar_def.hpp>
12
13 struct my_grammar1
14 : BOOST_SPIRIT_CLASSIC_NS::grammar<my_grammar1>
15 {
16 template <typename Scanner>
17 struct definition
18 : BOOST_SPIRIT_CLASSIC_NS::grammar_def<
19 BOOST_SPIRIT_CLASSIC_NS::rule<Scanner>,
20 BOOST_SPIRIT_CLASSIC_NS::same
21 >
22 {
definitionmy_grammar1::definition23 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_CLASSIC_NS::str_p("int");
29 start_rule2 = BOOST_SPIRIT_CLASSIC_NS::int_p;
30
31 this->start_parsers(start_rule1, start_rule2);
32 }
33
34 BOOST_SPIRIT_CLASSIC_NS::rule<Scanner>
35 start_rule1,
36 start_rule2;
37 };
38 };
39
40 struct my_closure : BOOST_SPIRIT_CLASSIC_NS::closure<my_closure, int>
41 {
42 member1 value;
43 };
44
45 struct my_grammar2
46 : BOOST_SPIRIT_CLASSIC_NS::grammar<my_grammar2, my_closure::context_t>
47 {
48 template <typename Scanner>
49 struct definition
50 : BOOST_SPIRIT_CLASSIC_NS::grammar_def<
51 BOOST_SPIRIT_CLASSIC_NS::rule<Scanner>,
52 BOOST_SPIRIT_CLASSIC_NS::same
53 >
54 {
definitionmy_grammar2::definition55 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_CLASSIC_NS::str_p("int");
61 start_rule2 = BOOST_SPIRIT_CLASSIC_NS::int_p;
62
63 this->start_parsers(start_rule1, start_rule2);
64 }
65
66 BOOST_SPIRIT_CLASSIC_NS::rule<Scanner>
67 start_rule1,
68 start_rule2;
69 };
70 };
71
main()72 int 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_CLASSIC_NS::space_p
84 );
85 }
86