1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
6 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
7 Software License, Version 1.0. (See accompanying file
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
11 #if !defined(BOOST_CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED)
12 #define BOOST_CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED
14 #include <boost/spirit/include/classic_core.hpp>
15 #include <boost/spirit/include/classic_parse_tree.hpp>
16 #include <boost/spirit/include/classic_confix.hpp>
17 #include <boost/spirit/include/classic_lists.hpp>
19 #include <boost/wave/wave_config.hpp>
20 #include <boost/wave/token_ids.hpp>
21 #include <boost/wave/grammars/cpp_predef_macros_gen.hpp>
22 #include <boost/wave/util/pattern_parser.hpp>
24 // this must occur after all of the includes and before any code appears
25 #ifdef BOOST_HAS_ABI_HEADERS
26 #include BOOST_ABI_PREFIX
29 ///////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // define, whether the rule's should generate some debug output
36 #define TRACE_PREDEF_MACROS_GRAMMAR \
37 bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_PREDEF_MACROS_GRAMMAR) \
40 ///////////////////////////////////////////////////////////////////////////////
41 // Encapsulation of the grammar for command line driven predefined macros.
42 struct predefined_macros_grammar :
43 public boost::spirit::classic::grammar<predefined_macros_grammar>
45 template <typename ScannerT>
48 // 'normal' (parse_tree generating) rule type
49 typedef boost::spirit::classic::rule<
50 ScannerT, boost::spirit::classic::dynamic_parser_tag>
53 rule_type plain_define, macro_definition, macro_parameters;
55 definition(predefined_macros_grammar const &/*self*/)
57 // import the spirit and cpplexer namespaces here
58 using namespace boost::spirit::classic;
59 using namespace boost::wave;
60 using namespace boost::wave::util;
62 // set the rule id's for later use
63 plain_define.set_id(BOOST_WAVE_PLAIN_DEFINE_ID);
64 macro_parameters.set_id(BOOST_WAVE_MACRO_PARAMETERS_ID);
65 macro_definition.set_id(BOOST_WAVE_MACRO_DEFINITION_ID);
67 // recognizes command line defined macro syntax, i.e.
75 // This grammar resembles the overall structure of the cpp_grammar to
76 // make it possible to reuse the parse tree traversal code
78 = ( ch_p(T_IDENTIFIER)
79 | pattern_p(KeywordTokenType,
80 TokenTypeMask|PPTokenFlag)
81 | pattern_p(OperatorTokenType|AltExtTokenType,
82 ExtTokenTypeMask|PPTokenFlag) // and, bit_and etc.
83 | pattern_p(BoolLiteralTokenType,
84 TokenTypeMask|PPTokenFlag) // true/false
93 no_node_d[ch_p(T_LEFTPAREN) >> *ch_p(T_SPACE)],
96 | pattern_p(KeywordTokenType,
97 TokenTypeMask|PPTokenFlag)
98 | pattern_p(OperatorTokenType|AltExtTokenType,
99 ExtTokenTypeMask|PPTokenFlag) // and, bit_and etc.
100 | pattern_p(BoolLiteralTokenType,
101 TokenTypeMask|PPTokenFlag) // true/false
103 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
109 *ch_p(T_SPACE) >> ch_p(T_COMMA) >> *ch_p(T_SPACE)
112 no_node_d[*ch_p(T_SPACE) >> ch_p(T_RIGHTPAREN)]
116 // macro body (anything left until eol)
118 = no_node_d[ch_p(T_ASSIGN)]
122 BOOST_SPIRIT_DEBUG_TRACE_RULE(plain_define, TRACE_PREDEF_MACROS_GRAMMAR);
123 BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_definition, TRACE_PREDEF_MACROS_GRAMMAR);
124 BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_parameters, TRACE_PREDEF_MACROS_GRAMMAR);
127 // start rule of this grammar
128 rule_type const& start() const
129 { return plain_define; }
132 predefined_macros_grammar()
134 BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this,
135 "predefined_macros_grammar", TRACE_PREDEF_MACROS_GRAMMAR);
140 ///////////////////////////////////////////////////////////////////////////////
141 #undef TRACE_PREDEF_MACROS_GRAMMAR
143 ///////////////////////////////////////////////////////////////////////////////
145 // The following parse function is defined here, to allow the separation of
146 // the compilation of the cpp_predefined_macros_grammar from the function
149 ///////////////////////////////////////////////////////////////////////////////
151 #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
152 #define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
154 #define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE inline
157 template <typename LexIteratorT>
158 BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
159 boost::spirit::classic::tree_parse_info<LexIteratorT>
160 predefined_macros_grammar_gen<LexIteratorT>::parse_predefined_macro (
161 LexIteratorT const &first, LexIteratorT const &last)
163 predefined_macros_grammar g;
164 return boost::spirit::classic::pt_parse (first, last, g);
167 #undef BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
169 ///////////////////////////////////////////////////////////////////////////////
170 } // namespace grammars
174 // the suffix header occurs after all of the code
175 #ifdef BOOST_HAS_ABI_HEADERS
176 #include BOOST_ABI_SUFFIX
179 #endif // !defined(BOOST_CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED)