Chris@16: // Copyright (c) 2001-2011 Joel de Guzman Chris@16: // Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #if !defined(BOOST_SPIRIT_KARMA_GRAMMAR_MAR_05_2007_0542PM) Chris@16: #define BOOST_SPIRIT_KARMA_GRAMMAR_MAR_05_2007_0542PM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit { namespace karma Chris@16: { Chris@16: template < Chris@16: typename OutputIterator, typename T1, typename T2, typename T3 Chris@16: , typename T4> Chris@16: struct grammar Chris@16: : proto::extends< Chris@16: typename proto::terminal< Chris@16: reference const> Chris@16: >::type Chris@16: , grammar Chris@16: > Chris@16: , generator > Chris@16: , noncopyable Chris@16: { Chris@16: typedef OutputIterator iterator_type; Chris@16: typedef rule start_type; Chris@16: typedef typename start_type::properties properties; Chris@16: typedef typename start_type::sig_type sig_type; Chris@16: typedef typename start_type::locals_type locals_type; Chris@16: typedef typename start_type::delimiter_type delimiter_type; Chris@16: typedef typename start_type::encoding_type encoding_type; Chris@16: typedef grammar base_type; Chris@16: typedef reference reference_; Chris@16: typedef typename proto::terminal::type terminal; Chris@16: Chris@16: static size_t const params_size = start_type::params_size; Chris@16: Chris@16: template Chris@16: struct attribute Chris@16: { Chris@16: typedef typename start_type::attr_type type; Chris@16: }; Chris@16: Chris@16: // the output iterator is always wrapped by karma Chris@16: typedef detail::output_iterator Chris@16: output_iterator; Chris@16: Chris@16: grammar(start_type const& start Chris@16: , std::string const& name_ = "unnamed-grammar") Chris@16: : proto::extends(terminal::make(reference_(start))) Chris@16: , name_(name_) Chris@16: {} Chris@16: Chris@16: // This constructor is used to catch if the start rule is not Chris@16: // compatible with the grammar. Chris@16: template Chris@16: grammar(rule const& Chris@16: , std::string const& = "unnamed-grammar") Chris@16: { Chris@16: // If you see the assertion below failing then the start rule Chris@16: // passed to the constructor of the grammar is not compatible with Chris@16: // the grammar (i.e. it uses different template parameters). Chris@16: BOOST_SPIRIT_ASSERT_MSG( Chris@16: (is_same >::value) Chris@16: , incompatible_start_rule, (rule)); Chris@16: } Chris@16: Chris@16: std::string name() const Chris@16: { Chris@16: return name_; Chris@16: } Chris@16: Chris@16: void name(std::string const& str) Chris@16: { Chris@16: name_ = str; Chris@16: } Chris@16: Chris@16: template Chris@16: bool generate(output_iterator& sink, Context& context Chris@16: , Delimiter const& delim, Attribute const& attr) const Chris@16: { Chris@16: return this->proto_base().child0.generate( Chris@16: sink, context, delim, attr); Chris@16: } Chris@16: Chris@16: template Chris@16: info what(Context&) const Chris@16: { Chris@16: return info(name_); Chris@16: } Chris@16: Chris@16: // bring in the operator() overloads Chris@16: start_type const& get_parameterized_subject() const Chris@16: { return this->proto_base().child0.ref.get(); } Chris@16: typedef start_type parameterized_subject_type; Chris@16: #include Chris@16: Chris@16: std::string name_; Chris@16: }; Chris@16: }}} Chris@16: Chris@16: namespace boost { namespace spirit { namespace traits Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template < Chris@16: typename IteratorA, typename IteratorB, typename Attribute Chris@16: , typename Context, typename T1, typename T2, typename T3, typename T4> Chris@16: struct handles_container< Chris@16: karma::grammar, Attribute, Context Chris@16: , IteratorB> Chris@16: : detail::nonterminal_handles_container< Chris@16: typename attribute_of< Chris@16: karma::grammar Chris@16: , Context, IteratorB Chris@16: >::type, Attribute> Chris@16: {}; Chris@16: }}} Chris@16: Chris@16: #endif