1 #ifndef CommonTools_Utils_Grammar_h
2 #define CommonTools_Utils_Grammar_h
13 #include "boost/spirit/include/classic_core.hpp"
14 #include "boost/spirit/include/classic_grammar_def.hpp"
15 #include "boost/spirit/include/classic_chset.hpp"
45 struct Grammar :
public boost::spirit::classic::grammar<Grammar> {
72 template <
typename ScannerT>
74 public boost::spirit::classic::grammar_def<boost::spirit::classic::rule<ScannerT>,
75 boost::spirit::classic::same,
76 boost::spirit::classic::same>{
77 typedef boost::spirit::classic::rule<ScannerT>
rule;
78 rule number,
var,
arrayAccess,
metharg,
method,
term,
power,
factor,
function1,
function2,
function4,
expression,
83 using namespace boost::spirit::classic;
127 BOOST_SPIRIT_DEBUG_RULE(
var);
129 BOOST_SPIRIT_DEBUG_RULE(
method);
134 BOOST_SPIRIT_DEBUG_RULE(
number);
135 BOOST_SPIRIT_DEBUG_RULE(
metharg);
140 BOOST_SPIRIT_DEBUG_RULE(
term);
141 BOOST_SPIRIT_DEBUG_RULE(
power);
142 BOOST_SPIRIT_DEBUG_RULE(
factor);
143 BOOST_SPIRIT_DEBUG_RULE(
or_op);
144 BOOST_SPIRIT_DEBUG_RULE(
and_op);
148 BOOST_SPIRIT_DEBUG_RULE(
cut);
149 BOOST_SPIRIT_DEBUG_RULE(
fun);
152 boost::spirit::classic::assertion<SyntaxErrors> expect(
kSyntaxError);
156 metharg = ( strict_real_p [ methodArg_s ] ) |
157 ( int_p [ methodArg_s ] ) |
158 ( ch_p(
'"' ) >> *(~ch_p(
'"' )) >> ch_p(
'"' ) ) [ methodArg_s ] |
159 ( ch_p(
'\'') >> *(~ch_p(
'\'')) >> ch_p(
'\'') ) [ methodArg_s ];
161 (lexeme_d[alpha_p >> * chset<>(
"a-zA-Z0-9_")] >>
162 ch_p(
'(') >>
metharg >> * (ch_p(
',') >>
metharg ) >> expectParenthesis(ch_p(
')'))) [ method_s ] |
163 ( (lexeme_d[alpha_p >> * chset<>(
"a-zA-Z0-9_")]) [ method_s ] >> ! (ch_p(
'(') >> ch_p(
')')) ) ;
168 chseq_p(
"abs") [ abs_s ] | chseq_p(
"acos") [ acos_s ] | chseq_p(
"asin") [ asin_s ] |
169 chseq_p(
"atan") [ atan_s ] | chseq_p(
"cosh") [ cosh_s ] | chseq_p(
"cos") [ cos_s ] |
170 chseq_p(
"exp") [ exp_s ] | chseq_p(
"log") [ log_s ] | chseq_p(
"log10") [ log10_s ] |
171 chseq_p(
"sinh") [ sinh_s ] | chseq_p(
"sin") [ sin_s ] | chseq_p(
"sqrt") [ sqrt_s ] |
172 chseq_p(
"tanh") [ tanh_s ] | chseq_p(
"tan") [ tan_s ];
174 chseq_p(
"atan2") [ atan2_s ] | chseq_p(
"chi2prob") [ chi2prob_s ] | chseq_p(
"pow") [ pow_s ] |
175 chseq_p(
"min") [ min_s ] | chseq_p(
"max") [ max_s ] | chseq_p(
"deltaPhi") [deltaPhi_s] | chseq_p(
"hypot") [hypot_s] | chseq_p(
"test_bit") [test_bit_s] ;
177 chseq_p(
"deltaR") [deltaR_s];
182 term >> (* ((
'+' >> expect(
term)) [ plus_s ] |
183 (
'-' >> expect(
term)) [ minus_s ]));
187 power >> * ((
'*' >> expect(
power)) [ multiplies_s ] |
188 (
'/' >> expect(
power)) [ divides_s ]);
193 (
function1 >> ch_p(
'(') [funOk_s ] >> expect(
expression) >> expectParenthesis(ch_p(
')'))) [ fun_s ] |
195 expect(ch_p(
',')) >> expect(
expression) >> expectParenthesis(ch_p(
')'))) [ fun_s ] |
197 expect(ch_p(
',')) >> expect(
expression) >> expectParenthesis(ch_p(
')'))) [ fun_s ] |
208 (ch_p(
'-') >>
factor) [ negate_s ] |
211 (ch_p(
'<') >> ch_p(
'=') [ less_equal_s ]) |
212 (ch_p(
'<') [ less_s ]) |
213 (ch_p(
'=') >> ch_p(
'=') [ equal_to_s ]) |
214 (ch_p(
'=') [ equal_to_s ]) |
215 (ch_p(
'>') >> ch_p(
'=') [ greater_equal_s ]) |
216 (ch_p(
'>') [ greater_s ]) |
217 (ch_p(
'!') >> ch_p(
'=') [ not_equal_to_s ]);
222 or_op = ch_p(
'|') >> ch_p(
'|') | ch_p(
'|');
223 and_op = ch_p(
'&') >> ch_p(
'&') | ch_p(
'&');
237 this->start_parsers(
cut,
fun);
Grammar(SelectorPtr &sel, const edm::TypeWithDict &iType, bool lazy=false)
LazyMethodStack lazyMethStack
std::vector< edm::TypeWithDict > TypeStack
FunctionStack finalFunStack
boost::shared_ptr< ExpressionBase > ExpressionPtr
Grammar(ExpressionPtr &expr, const edm::TypeWithDict &iType, bool lazy=false)
std::vector< AnyMethodArgument > MethodArgumentStack
boost::spirit::classic::rule< ScannerT > rule
std::vector< boost::shared_ptr< ExpressionBase > > ExpressionStack
std::vector< SelectorPtr > SelectorStack
std::vector< LazyInvoker > LazyMethodStack
std::vector< int > IntStack
boost::shared_ptr< SelectorBase > SelectorPtr
MethodArgumentStack methArgStack
definition(const Grammar &self)
std::vector< MethodInvoker > MethodStack
ExpressionStack exprStack
std::vector< boost::shared_ptr< ComparisonBase > > ComparisonStack
std::vector< Function > FunctionStack