1 // Copyright (c) 2001-2011 Joel de Guzman
2 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
7 #if !defined(BOOST_SPIRIT_KARMA_GRAMMAR_MAR_05_2007_0542PM)
8 #define BOOST_SPIRIT_KARMA_GRAMMAR_MAR_05_2007_0542PM
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/karma/domain.hpp>
18 #include <boost/spirit/home/karma/nonterminal/rule.hpp>
19 #include <boost/spirit/home/karma/nonterminal/nonterminal_fwd.hpp>
20 #include <boost/spirit/home/karma/reference.hpp>
21 #include <boost/noncopyable.hpp>
22 #include <boost/type_traits/is_same.hpp>
24 namespace boost { namespace spirit { namespace karma
27 typename OutputIterator, typename T1, typename T2, typename T3
31 typename proto::terminal<
32 reference<rule<OutputIterator, T1, T2, T3, T4> const>
34 , grammar<OutputIterator, T1, T2, T3, T4>
36 , generator<grammar<OutputIterator, T1, T2, T3, T4> >
39 typedef OutputIterator iterator_type;
40 typedef rule<OutputIterator, T1, T2, T3, T4> start_type;
41 typedef typename start_type::properties properties;
42 typedef typename start_type::sig_type sig_type;
43 typedef typename start_type::locals_type locals_type;
44 typedef typename start_type::delimiter_type delimiter_type;
45 typedef typename start_type::encoding_type encoding_type;
46 typedef grammar<OutputIterator, T1, T2, T3, T4> base_type;
47 typedef reference<start_type const> reference_;
48 typedef typename proto::terminal<reference_>::type terminal;
50 static size_t const params_size = start_type::params_size;
52 template <typename Context, typename Unused>
55 typedef typename start_type::attr_type type;
58 // the output iterator is always wrapped by karma
59 typedef detail::output_iterator<OutputIterator, properties>
62 grammar(start_type const& start
63 , std::string const& name_ = "unnamed-grammar")
64 : proto::extends<terminal, base_type>(terminal::make(reference_(start)))
68 // This constructor is used to catch if the start rule is not
69 // compatible with the grammar.
70 template <typename Iterator_, typename T1_, typename T2_, typename T3_,
72 grammar(rule<Iterator_, T1_, T2_, T3_, T4_> const&
73 , std::string const& = "unnamed-grammar")
75 // If you see the assertion below failing then the start rule
76 // passed to the constructor of the grammar is not compatible with
77 // the grammar (i.e. it uses different template parameters).
78 BOOST_SPIRIT_ASSERT_MSG(
79 (is_same<start_type, rule<Iterator_, T1_, T2_, T3_, T4_> >::value)
80 , incompatible_start_rule, (rule<Iterator_, T1_, T2_, T3_, T4_>));
83 std::string name() const
88 void name(std::string const& str)
93 template <typename Context, typename Delimiter, typename Attribute>
94 bool generate(output_iterator& sink, Context& context
95 , Delimiter const& delim, Attribute const& attr) const
97 return this->proto_base().child0.generate(
98 sink, context, delim, attr);
101 template <typename Context>
102 info what(Context&) const
107 // bring in the operator() overloads
108 start_type const& get_parameterized_subject() const
109 { return this->proto_base().child0.ref.get(); }
110 typedef start_type parameterized_subject_type;
111 #include <boost/spirit/home/karma/nonterminal/detail/fcall.hpp>
117 namespace boost { namespace spirit { namespace traits
119 ///////////////////////////////////////////////////////////////////////////
121 typename IteratorA, typename IteratorB, typename Attribute
122 , typename Context, typename T1, typename T2, typename T3, typename T4>
123 struct handles_container<
124 karma::grammar<IteratorA, T1, T2, T3, T4>, Attribute, Context
126 : detail::nonterminal_handles_container<
127 typename attribute_of<
128 karma::grammar<IteratorA, T1, T2, T3, T4>