]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/wave/grammars/cpp_predef_macros_grammar.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / wave / grammars / cpp_predef_macros_grammar.hpp
1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
3
4 http://www.boost.org/
5
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 =============================================================================*/
10
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
13
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>
18
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>
23
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
27 #endif
28
29 ///////////////////////////////////////////////////////////////////////////////
30 namespace boost {
31 namespace wave {
32 namespace grammars {
33
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) \
38 /**/
39
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>
44 {
45 template <typename ScannerT>
46 struct definition
47 {
48 // 'normal' (parse_tree generating) rule type
49 typedef boost::spirit::classic::rule<
50 ScannerT, boost::spirit::classic::dynamic_parser_tag>
51 rule_type;
52
53 rule_type plain_define, macro_definition, macro_parameters;
54
55 definition(predefined_macros_grammar const &/*self*/)
56 {
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;
61
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);
66
67 // recognizes command line defined macro syntax, i.e.
68 // -DMACRO
69 // -DMACRO=
70 // -DMACRO=value
71 // -DMACRO(x)
72 // -DMACRO(x)=
73 // -DMACRO(x)=value
74
75 // This grammar resembles the overall structure of the cpp_grammar to
76 // make it possible to reuse the parse tree traversal code
77 plain_define
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
85 )
86 >> !macro_parameters
87 >> !macro_definition
88 ;
89
90 // parameter list
91 macro_parameters
92 = confix_p(
93 no_node_d[ch_p(T_LEFTPAREN) >> *ch_p(T_SPACE)],
94 !list_p(
95 ( ch_p(T_IDENTIFIER)
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
102
103 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
104 | ch_p(T_ELLIPSIS)
105 #endif
106 ),
107 no_node_d
108 [
109 *ch_p(T_SPACE) >> ch_p(T_COMMA) >> *ch_p(T_SPACE)
110 ]
111 ),
112 no_node_d[*ch_p(T_SPACE) >> ch_p(T_RIGHTPAREN)]
113 )
114 ;
115
116 // macro body (anything left until eol)
117 macro_definition
118 = no_node_d[ch_p(T_ASSIGN)]
119 >> *anychar_p
120 ;
121
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);
125 }
126
127 // start rule of this grammar
128 rule_type const& start() const
129 { return plain_define; }
130 };
131
132 predefined_macros_grammar()
133 {
134 BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this,
135 "predefined_macros_grammar", TRACE_PREDEF_MACROS_GRAMMAR);
136 }
137
138 };
139
140 ///////////////////////////////////////////////////////////////////////////////
141 #undef TRACE_PREDEF_MACROS_GRAMMAR
142
143 ///////////////////////////////////////////////////////////////////////////////
144 //
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
147 // using it.
148 //
149 ///////////////////////////////////////////////////////////////////////////////
150
151 #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
152 #define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
153 #else
154 #define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE inline
155 #endif
156
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)
162 {
163 predefined_macros_grammar g;
164 return boost::spirit::classic::pt_parse (first, last, g);
165 }
166
167 #undef BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
168
169 ///////////////////////////////////////////////////////////////////////////////
170 } // namespace grammars
171 } // namespace wave
172 } // namespace boost
173
174 // the suffix header occurs after all of the code
175 #ifdef BOOST_HAS_ABI_HEADERS
176 #include BOOST_ABI_SUFFIX
177 #endif
178
179 #endif // !defined(BOOST_CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED)