Chris@16: /*============================================================================= Chris@16: Boost.Wave: A Standard compliant C++ preprocessor library Chris@16: Chris@16: http://www.boost.org/ Chris@16: Chris@16: Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost Chris@16: Software License, Version 1.0. (See accompanying file Chris@16: LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: Chris@16: #if !defined(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED) Chris@16: #define CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if !defined(spirit_append_actor) Chris@16: #define spirit_append_actor(actor) boost::spirit::classic::push_back_a(actor) Chris@16: #define spirit_assign_actor(actor) boost::spirit::classic::assign_a(actor) Chris@16: #endif // !defined(spirit_append_actor) Chris@16: Chris@16: // this must occur after all of the includes and before any code appears Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_PREFIX Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: namespace boost { Chris@16: namespace wave { Chris@16: namespace grammars { Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // define, whether the rule's should generate some debug output Chris@16: #define TRACE_CPP_DEFINED_GRAMMAR \ Chris@16: bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_DEFINED_GRAMMAR) \ Chris@16: /**/ Chris@16: Chris@16: template Chris@16: struct defined_grammar : Chris@16: public boost::spirit::classic::grammar > Chris@16: { Chris@16: defined_grammar(ContainerT &result_seq_) Chris@16: : result_seq(result_seq_) Chris@16: { Chris@16: BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "defined_grammar", Chris@16: TRACE_CPP_DEFINED_GRAMMAR); Chris@16: } Chris@16: Chris@16: template Chris@16: struct definition Chris@16: { Chris@16: typedef boost::spirit::classic::rule rule_t; Chris@16: Chris@16: rule_t defined_op; Chris@16: rule_t identifier; Chris@16: Chris@16: definition(defined_grammar const &self) Chris@16: { Chris@16: using namespace boost::spirit::classic; Chris@16: using namespace boost::wave; Chris@16: using namespace boost::wave::util; Chris@16: Chris@16: defined_op // parens not required, see C++ standard 16.1.1 Chris@16: = ch_p(T_IDENTIFIER) // token contains 'defined' Chris@16: >> ( Chris@16: ( ch_p(T_LEFTPAREN) Chris@16: >> identifier Chris@16: >> ch_p(T_RIGHTPAREN) Chris@16: ) Chris@16: | identifier Chris@16: ) Chris@16: ; Chris@16: Chris@16: identifier Chris@16: = ch_p(T_IDENTIFIER) Chris@16: [ Chris@16: spirit_append_actor(self.result_seq) Chris@16: ] Chris@16: | pattern_p(KeywordTokenType, TokenTypeMask|PPTokenFlag) Chris@16: [ Chris@16: spirit_append_actor(self.result_seq) Chris@16: ] Chris@16: | pattern_p(OperatorTokenType|AltExtTokenType, Chris@16: ExtTokenTypeMask|PPTokenFlag) Chris@16: [ Chris@16: spirit_append_actor(self.result_seq) Chris@16: ] Chris@16: | pattern_p(BoolLiteralTokenType, TokenTypeMask|PPTokenFlag) Chris@16: [ Chris@16: spirit_append_actor(self.result_seq) Chris@16: ] Chris@16: ; Chris@16: Chris@16: BOOST_SPIRIT_DEBUG_TRACE_RULE(defined_op, TRACE_CPP_DEFINED_GRAMMAR); Chris@16: BOOST_SPIRIT_DEBUG_TRACE_RULE(identifier, TRACE_CPP_DEFINED_GRAMMAR); Chris@16: } Chris@16: Chris@16: // start rule of this grammar Chris@16: rule_t const& start() const Chris@16: { return defined_op; } Chris@16: }; Chris@16: Chris@16: ContainerT &result_seq; Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: #undef TRACE_CPP_DEFINED_GRAMMAR Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // The following parse function is defined here, to allow the separation of Chris@16: // the compilation of the defined_grammar from the function Chris@16: // using it. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0 Chris@16: #define BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE Chris@16: #else Chris@16: #define BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE inline Chris@16: #endif Chris@16: Chris@16: // The parse_operator_define function is instantiated manually twice to Chris@16: // simplify the explicit specialization of this template. This way the user Chris@16: // has only to specify one template parameter (the lexer type) to correctly Chris@16: // formulate the required explicit specialization. Chris@16: // This results in no code overhead, because otherwise the function would be Chris@16: // generated by the compiler twice anyway. Chris@16: Chris@16: template Chris@16: BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE Chris@16: boost::spirit::classic::parse_info< Chris@16: typename defined_grammar_gen::iterator1_type Chris@16: > Chris@16: defined_grammar_gen::parse_operator_defined ( Chris@16: iterator1_type const &first, iterator1_type const &last, Chris@16: token_sequence_type &found_qualified_name) Chris@16: { Chris@16: using namespace boost::spirit::classic; Chris@16: using namespace boost::wave; Chris@16: Chris@16: defined_grammar g(found_qualified_name); Chris@16: return boost::spirit::classic::parse ( Chris@16: first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT)); Chris@16: } Chris@16: Chris@16: template Chris@16: BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE Chris@16: boost::spirit::classic::parse_info< Chris@16: typename defined_grammar_gen::iterator2_type Chris@16: > Chris@16: defined_grammar_gen::parse_operator_defined ( Chris@16: iterator2_type const &first, iterator2_type const &last, Chris@16: token_sequence_type &found_qualified_name) Chris@16: { Chris@16: using namespace boost::spirit::classic; Chris@16: using namespace boost::wave; Chris@16: Chris@16: defined_grammar g(found_qualified_name); Chris@16: return boost::spirit::classic::parse ( Chris@16: first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT)); Chris@16: } Chris@16: Chris@16: #undef BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: } // namespace grammars Chris@16: } // namespace wave Chris@16: } // namespace boost Chris@16: Chris@16: // the suffix header occurs after all of the code Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_SUFFIX Chris@16: #endif Chris@16: Chris@16: #endif // !defined(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED)