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