1 /*============================================================================= 2 Copyright (c) 2001-2003 Joel de Guzman 3 Copyright (c) 2002-2003 Martin Wille 4 Copyright (c) 2003 Hartmut Kaiser 5 http://spirit.sourceforge.net/ 6 7 Distributed under the Boost Software License, Version 1.0. (See accompanying 8 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 =============================================================================*/ 10 #if !defined(BOOST_SPIRIT_GRAMMAR_HPP) 11 #define BOOST_SPIRIT_GRAMMAR_HPP 12 13 /////////////////////////////////////////////////////////////////////////////// 14 #if defined(BOOST_SPIRIT_THREADSAFE) && defined(BOOST_SPIRIT_SINGLE_GRAMMAR_INSTANCE) 15 #undef BOOST_SPIRIT_SINGLE_GRAMMAR_INSTANCE 16 #endif 17 18 #include <boost/spirit/home/classic/namespace.hpp> 19 #include <boost/spirit/home/classic/core/parser.hpp> 20 #include <boost/spirit/home/classic/core/non_terminal/parser_context.hpp> 21 #include <boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp> 22 23 /////////////////////////////////////////////////////////////////////////////// 24 namespace boost { namespace spirit { 25 26 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN 27 28 /////////////////////////////////////////////////////////////////////////////// 29 // 30 // grammar class 31 // 32 /////////////////////////////////////////////////////////////////////////////// 33 template <typename DerivedT, typename ContextT = parser_context<> > 34 struct grammar 35 : public parser<DerivedT> 36 , public ContextT::base_t 37 , public context_aux<ContextT, DerivedT> 38 BOOST_SPIRIT_GRAMMAR_ID 39 { 40 typedef grammar<DerivedT, ContextT> self_t; 41 typedef DerivedT const& embed_t; 42 typedef typename ContextT::context_linker_t context_t; 43 typedef typename context_t::attr_t attr_t; 44 45 template <typename ScannerT> 46 struct result 47 { 48 typedef typename match_result<ScannerT, attr_t>::type type; 49 }; 50 grammarboost::spirit::grammar51 grammar() {} ~grammarboost::spirit::grammar52 ~grammar() { impl::grammar_destruct(this); } 53 54 template <typename ScannerT> 55 typename parser_result<self_t, ScannerT>::type parse_mainboost::spirit::grammar56 parse_main(ScannerT const& scan) const 57 { return impl::grammar_parser_parse<0>(this, scan); } 58 59 template <typename ScannerT> 60 typename parser_result<self_t, ScannerT>::type parseboost::spirit::grammar61 parse(ScannerT const& scan) const 62 { 63 typedef typename parser_result<self_t, ScannerT>::type result_t; 64 typedef parser_scanner_linker<ScannerT> scanner_t; 65 BOOST_SPIRIT_CONTEXT_PARSE(scan, *this, scanner_t, context_t, result_t) 66 } 67 68 template <int N> 69 impl::entry_grammar<DerivedT, N, ContextT> use_parserboost::spirit::grammar70 use_parser() const 71 { return impl::entry_grammar<DerivedT, N, ContextT>( this->derived()); } 72 73 BOOST_SPIRIT_GRAMMAR_STATE 74 }; 75 76 /////////////////////////////////////////////////////////////////////////////// 77 BOOST_SPIRIT_CLASSIC_NAMESPACE_END 78 79 }} // namespace BOOST_SPIRIT_CLASSIC_NS 80 81 #undef BOOST_SPIRIT_GRAMMAR_ID 82 #undef BOOST_SPIRIT_GRAMMAR_STATE 83 #endif 84 85