1 | /*============================================================================= |
---|
2 | Boost.Wave: A Standard compliant C++ preprocessor library |
---|
3 | |
---|
4 | http://www.boost.org/ |
---|
5 | |
---|
6 | Copyright (c) 2001-2007 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(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED) |
---|
12 | #define CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED |
---|
13 | |
---|
14 | #include <boost/assert.hpp> |
---|
15 | #include <boost/spirit/core.hpp> |
---|
16 | #include <boost/spirit/attribute/closure.hpp> |
---|
17 | #if SPIRIT_VERSION >= 0x1700 |
---|
18 | #include <boost/spirit/actor/assign_actor.hpp> |
---|
19 | #include <boost/spirit/actor/push_back_actor.hpp> |
---|
20 | #endif // SPIRIT_VERSION >= 0x1700 |
---|
21 | |
---|
22 | #include <boost/wave/wave_config.hpp> |
---|
23 | #include <boost/wave/token_ids.hpp> |
---|
24 | #include <boost/wave/util/pattern_parser.hpp> |
---|
25 | #include <boost/wave/grammars/cpp_defined_grammar_gen.hpp> |
---|
26 | |
---|
27 | #if !defined(spirit_append_actor) |
---|
28 | #if SPIRIT_VERSION >= 0x1700 |
---|
29 | #define spirit_append_actor(actor) boost::spirit::push_back_a(actor) |
---|
30 | #define spirit_assign_actor(actor) boost::spirit::assign_a(actor) |
---|
31 | #else |
---|
32 | #define spirit_append_actor(actor) boost::spirit::append(actor) |
---|
33 | #define spirit_assign_actor(actor) boost::spirit::assign(actor) |
---|
34 | #endif // SPIRIT_VERSION >= 0x1700 |
---|
35 | #endif // !defined(spirit_append_actor) |
---|
36 | |
---|
37 | // this must occur after all of the includes and before any code appears |
---|
38 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
39 | #include BOOST_ABI_PREFIX |
---|
40 | #endif |
---|
41 | |
---|
42 | /////////////////////////////////////////////////////////////////////////////// |
---|
43 | namespace boost { |
---|
44 | namespace wave { |
---|
45 | namespace grammars { |
---|
46 | |
---|
47 | /////////////////////////////////////////////////////////////////////////////// |
---|
48 | // define, whether the rule's should generate some debug output |
---|
49 | #define TRACE_CPP_DEFINED_GRAMMAR \ |
---|
50 | bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_DEFINED_GRAMMAR) \ |
---|
51 | /**/ |
---|
52 | |
---|
53 | template <typename ContainerT> |
---|
54 | struct defined_grammar : |
---|
55 | public boost::spirit::grammar<defined_grammar<ContainerT> > |
---|
56 | { |
---|
57 | defined_grammar(ContainerT &result_seq_) |
---|
58 | : result_seq(result_seq_) |
---|
59 | { |
---|
60 | BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "defined_grammar", |
---|
61 | TRACE_CPP_DEFINED_GRAMMAR); |
---|
62 | } |
---|
63 | |
---|
64 | template <typename ScannerT> |
---|
65 | struct definition |
---|
66 | { |
---|
67 | typedef boost::spirit::rule<ScannerT> rule_t; |
---|
68 | |
---|
69 | rule_t defined_op; |
---|
70 | rule_t identifier; |
---|
71 | |
---|
72 | definition(defined_grammar const &self) |
---|
73 | { |
---|
74 | using namespace boost::spirit; |
---|
75 | using namespace boost::wave; |
---|
76 | using namespace boost::wave::util; |
---|
77 | |
---|
78 | defined_op // parens not required, see C++ standard 16.1.1 |
---|
79 | = ch_p(T_IDENTIFIER) // token contains 'defined' |
---|
80 | >> ( |
---|
81 | ( ch_p(T_LEFTPAREN) |
---|
82 | >> identifier |
---|
83 | >> ch_p(T_RIGHTPAREN) |
---|
84 | ) |
---|
85 | | identifier |
---|
86 | ) |
---|
87 | ; |
---|
88 | |
---|
89 | identifier |
---|
90 | = ch_p(T_IDENTIFIER) |
---|
91 | [ |
---|
92 | spirit_append_actor(self.result_seq) |
---|
93 | ] |
---|
94 | | pattern_p(KeywordTokenType, TokenTypeMask) |
---|
95 | [ |
---|
96 | spirit_append_actor(self.result_seq) |
---|
97 | ] |
---|
98 | | pattern_p(OperatorTokenType|AltExtTokenType, ExtTokenTypeMask) |
---|
99 | [ |
---|
100 | spirit_append_actor(self.result_seq) |
---|
101 | ] |
---|
102 | | pattern_p(BoolLiteralTokenType, TokenTypeMask) |
---|
103 | [ |
---|
104 | spirit_append_actor(self.result_seq) |
---|
105 | ] |
---|
106 | ; |
---|
107 | |
---|
108 | BOOST_SPIRIT_DEBUG_TRACE_RULE(defined_op, TRACE_CPP_DEFINED_GRAMMAR); |
---|
109 | BOOST_SPIRIT_DEBUG_TRACE_RULE(identifier, TRACE_CPP_DEFINED_GRAMMAR); |
---|
110 | } |
---|
111 | |
---|
112 | // start rule of this grammar |
---|
113 | rule_t const& start() const |
---|
114 | { return defined_op; } |
---|
115 | }; |
---|
116 | |
---|
117 | ContainerT &result_seq; |
---|
118 | }; |
---|
119 | |
---|
120 | /////////////////////////////////////////////////////////////////////////////// |
---|
121 | #undef TRACE_CPP_DEFINED_GRAMMAR |
---|
122 | |
---|
123 | /////////////////////////////////////////////////////////////////////////////// |
---|
124 | // |
---|
125 | // The following parse function is defined here, to allow the separation of |
---|
126 | // the compilation of the defined_grammar from the function |
---|
127 | // using it. |
---|
128 | // |
---|
129 | /////////////////////////////////////////////////////////////////////////////// |
---|
130 | |
---|
131 | #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0 |
---|
132 | #define BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE |
---|
133 | #else |
---|
134 | #define BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE inline |
---|
135 | #endif |
---|
136 | |
---|
137 | // The parse_operator_define function is instantiated manually twice to |
---|
138 | // simplify the explicit specialization of this template. This way the user |
---|
139 | // has only to specify one template parameter (the lexer type) to correctly |
---|
140 | // formulate the required explicit specialization. |
---|
141 | // This results in no code overhead, because otherwise the function would be |
---|
142 | // generated by the compiler twice anyway. |
---|
143 | |
---|
144 | template <typename LexIteratorT> |
---|
145 | BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE |
---|
146 | boost::spirit::parse_info< |
---|
147 | typename defined_grammar_gen<LexIteratorT>::iterator1_t |
---|
148 | > |
---|
149 | defined_grammar_gen<LexIteratorT>::parse_operator_defined ( |
---|
150 | iterator1_t const &first, iterator1_t const &last, |
---|
151 | token_sequence_type &found_qualified_name) |
---|
152 | { |
---|
153 | using namespace boost::spirit; |
---|
154 | using namespace boost::wave; |
---|
155 | |
---|
156 | defined_grammar<token_sequence_type> g(found_qualified_name); |
---|
157 | return boost::spirit::parse ( |
---|
158 | first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT)); |
---|
159 | } |
---|
160 | |
---|
161 | template <typename LexIteratorT> |
---|
162 | BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE |
---|
163 | boost::spirit::parse_info< |
---|
164 | typename defined_grammar_gen<LexIteratorT>::iterator2_t |
---|
165 | > |
---|
166 | defined_grammar_gen<LexIteratorT>::parse_operator_defined ( |
---|
167 | iterator2_t const &first, iterator2_t const &last, |
---|
168 | token_sequence_type &found_qualified_name) |
---|
169 | { |
---|
170 | using namespace boost::spirit; |
---|
171 | using namespace boost::wave; |
---|
172 | |
---|
173 | defined_grammar<token_sequence_type> g(found_qualified_name); |
---|
174 | return boost::spirit::parse ( |
---|
175 | first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT)); |
---|
176 | } |
---|
177 | |
---|
178 | #undef BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE |
---|
179 | |
---|
180 | /////////////////////////////////////////////////////////////////////////////// |
---|
181 | } // namespace grammars |
---|
182 | } // namespace wave |
---|
183 | } // namespace boost |
---|
184 | |
---|
185 | // the suffix header occurs after all of the code |
---|
186 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
187 | #include BOOST_ABI_SUFFIX |
---|
188 | #endif |
---|
189 | |
---|
190 | #endif // !defined(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED) |
---|