Chris@16: /*============================================================================= Chris@16: Copyright (c) 2001-2011 Joel de Guzman 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_GRAMMAR_FEBRUARY_19_2007_0236PM) Chris@16: #define BOOST_SPIRIT_GRAMMAR_FEBRUARY_19_2007_0236PM 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 qi Chris@16: { Chris@16: template < Chris@16: typename Iterator, 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: , parser > Chris@16: , noncopyable Chris@16: { Chris@16: typedef Iterator iterator_type; Chris@16: typedef rule start_type; 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::skipper_type skipper_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: grammar( Chris@16: 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( Chris@16: 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 parse(Iterator& first, Iterator const& last Chris@16: , Context& context, Skipper const& skipper Chris@16: , Attribute& attr_) const Chris@16: { Chris@16: return this->proto_base().child0.parse( Chris@16: first, last, context, skipper, 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: 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: qi::grammar, Attribute, Context, IteratorB> Chris@16: : traits::is_container< Chris@16: typename attribute_of< Chris@16: qi::grammar, Context, IteratorB Chris@16: >::type Chris@16: > Chris@16: {}; Chris@16: }}} Chris@16: Chris@16: #endif