1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #if !defined(BOOST_SPIRIT_GRAMMAR_FEBRUARY_19_2007_0236PM)
8 #define BOOST_SPIRIT_GRAMMAR_FEBRUARY_19_2007_0236PM
14 #include <boost/spirit/home/support/unused.hpp>
15 #include <boost/spirit/home/support/info.hpp>
16 #include <boost/spirit/home/support/assert_msg.hpp>
17 #include <boost/spirit/home/qi/domain.hpp>
18 #include <boost/spirit/home/qi/nonterminal/rule.hpp>
19 #include <boost/spirit/home/qi/nonterminal/nonterminal_fwd.hpp>
20 #include <boost/spirit/home/qi/reference.hpp>
21 #include <boost/noncopyable.hpp>
22 #include <boost/type_traits/is_same.hpp>
24 namespace boost { namespace spirit { namespace qi
27 typename Iterator, typename T1, typename T2, typename T3
31 typename proto::terminal<
32 reference<rule<Iterator, T1, T2, T3, T4> const>
34 , grammar<Iterator, T1, T2, T3, T4>
36 , parser<grammar<Iterator, T1, T2, T3, T4> >
39 typedef Iterator iterator_type;
40 typedef rule<Iterator, T1, T2, T3, T4> start_type;
41 typedef typename start_type::sig_type sig_type;
42 typedef typename start_type::locals_type locals_type;
43 typedef typename start_type::skipper_type skipper_type;
44 typedef typename start_type::encoding_type encoding_type;
45 typedef grammar<Iterator, T1, T2, T3, T4> base_type;
46 typedef reference<start_type const> reference_;
47 typedef typename proto::terminal<reference_>::type terminal;
49 static size_t const params_size = start_type::params_size;
51 template <typename Context, typename Iterator_>
54 typedef typename start_type::attr_type type;
58 start_type const& start
59 , std::string const& name = "unnamed-grammar")
60 : proto::extends<terminal, base_type>(terminal::make(reference_(start)))
64 // This constructor is used to catch if the start rule is not
65 // compatible with the grammar.
66 template <typename Iterator_,
67 typename T1_, typename T2_, typename T3_, typename T4_>
69 rule<Iterator_, T1_, T2_, T3_, T4_> const&
70 , std::string const& = "unnamed-grammar")
72 // If you see the assertion below failing then the start rule
73 // passed to the constructor of the grammar is not compatible with
74 // the grammar (i.e. it uses different template parameters).
75 BOOST_SPIRIT_ASSERT_MSG(
76 (is_same<start_type, rule<Iterator_, T1_, T2_, T3_, T4_> >::value)
77 , incompatible_start_rule, (rule<Iterator_, T1_, T2_, T3_, T4_>));
80 std::string name() const
85 void name(std::string const& str)
90 template <typename Context, typename Skipper, typename Attribute>
91 bool parse(Iterator& first, Iterator const& last
92 , Context& context, Skipper const& skipper
93 , Attribute& attr_) const
95 return this->proto_base().child0.parse(
96 first, last, context, skipper, attr_);
99 template <typename Context>
100 info what(Context&) const
105 // bring in the operator() overloads
106 start_type const& get_parameterized_subject() const
107 { return this->proto_base().child0.ref.get(); }
108 typedef start_type parameterized_subject_type;
109 #include <boost/spirit/home/qi/nonterminal/detail/fcall.hpp>
116 namespace boost { namespace spirit { namespace traits
118 ///////////////////////////////////////////////////////////////////////////
120 typename IteratorA, typename IteratorB, typename Attribute
121 , typename Context, typename T1, typename T2, typename T3, typename T4>
122 struct handles_container<
123 qi::grammar<IteratorA, T1, T2, T3, T4>, Attribute, Context, IteratorB>
124 : traits::is_container<
125 typename attribute_of<
126 qi::grammar<IteratorA, T1, T2, T3, T4>, Context, IteratorB