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" 44 struct Grammar :
public boost::spirit::classic::grammar<Grammar> {
70 template <
typename ScannerT>
71 struct definition :
public boost::spirit::classic::grammar_def<boost::spirit::classic::rule<ScannerT>,
72 boost::spirit::classic::same,
73 boost::spirit::classic::same> {
74 typedef boost::spirit::classic::rule<ScannerT>
rule;
75 rule number,
var,
arrayAccess,
metharg,
method,
term,
power,
factor,
function1,
function2,
function4,
119 BOOST_SPIRIT_DEBUG_RULE(
var);
121 BOOST_SPIRIT_DEBUG_RULE(
method);
126 BOOST_SPIRIT_DEBUG_RULE(
number);
127 BOOST_SPIRIT_DEBUG_RULE(
metharg);
132 BOOST_SPIRIT_DEBUG_RULE(
term);
133 BOOST_SPIRIT_DEBUG_RULE(
power);
134 BOOST_SPIRIT_DEBUG_RULE(
factor);
135 BOOST_SPIRIT_DEBUG_RULE(
or_op);
136 BOOST_SPIRIT_DEBUG_RULE(
and_op);
140 BOOST_SPIRIT_DEBUG_RULE(
cut);
141 BOOST_SPIRIT_DEBUG_RULE(
fun);
144 boost::spirit::classic::assertion<SyntaxErrors> expect(
kSyntaxError);
146 number = real_p[number_s];
147 metharg = (strict_real_p[methodArg_s]) | (int_p[methodArg_s]) |
148 (ch_p(
'"') >> *(~ch_p(
'"')) >> ch_p(
'"'))[methodArg_s] |
149 (ch_p(
'\'') >> *(~ch_p(
'\'')) >> ch_p(
'\''))[methodArg_s];
151 (lexeme_d[alpha_p >> *chset<>(
"a-zA-Z0-9_")] >> ch_p(
'(') >>
metharg >> *(ch_p(
',') >>
metharg) >>
152 expectParenthesis(ch_p(
')')))[method_s] |
153 ((lexeme_d[alpha_p >> *chset<>(
"a-zA-Z0-9_")])[method_s] >> !(ch_p(
'(') >> ch_p(
')')));
156 function1 = chseq_p(
"abs")[abs_s] | chseq_p(
"acos")[acos_s] | chseq_p(
"asin")[asin_s] |
157 chseq_p(
"atan")[atan_s] | chseq_p(
"cosh")[cosh_s] | chseq_p(
"cos")[cos_s] |
158 chseq_p(
"exp")[exp_s] | chseq_p(
"log")[log_s] | chseq_p(
"log10")[log10_s] |
159 chseq_p(
"sinh")[sinh_s] | chseq_p(
"sin")[sin_s] | chseq_p(
"sqrt")[sqrt_s] |
160 chseq_p(
"tanh")[tanh_s] | chseq_p(
"tan")[tan_s];
161 function2 = chseq_p(
"atan2")[atan2_s] | chseq_p(
"chi2prob")[chi2prob_s] | chseq_p(
"pow")[pow_s] |
162 chseq_p(
"min")[min_s] | chseq_p(
"max")[max_s] | chseq_p(
"deltaPhi")[deltaPhi_s] |
163 chseq_p(
"hypot")[hypot_s] | chseq_p(
"test_bit")[test_bit_s];
169 term =
power >> *((
'*' >> expect(
power))[multiplies_s] | (
'/' >> expect(
power))[divides_s]);
174 expectParenthesis(ch_p(
')')))[fun_s] |
177 expectParenthesis(ch_p(
')')))[fun_s] |
188 comparison_op = (ch_p(
'<') >> ch_p(
'=')[less_equal_s]) | (ch_p(
'<')[less_s]) |
189 (ch_p(
'=') >> ch_p(
'=')[equal_to_s]) | (ch_p(
'=')[equal_to_s]) |
190 (ch_p(
'>') >> ch_p(
'=')[greater_equal_s]) | (ch_p(
'>')[greater_s]) |
191 (ch_p(
'!') >> ch_p(
'=')[not_equal_to_s]);
195 or_op = ch_p(
'|') >> ch_p(
'|') | ch_p(
'|');
196 and_op = ch_p(
'&') >> ch_p(
'&') | ch_p(
'&');
205 this->start_parsers(
cut,
fun);
std::vector< std::shared_ptr< ComparisonBase > > ComparisonStack
Grammar(SelectorPtr &sel, const edm::TypeWithDict &iType, bool lazy=false)
LazyMethodStack lazyMethStack
std::shared_ptr< ExpressionBase > ExpressionPtr
std::vector< edm::TypeWithDict > TypeStack
FunctionStack finalFunStack
Grammar(ExpressionPtr &expr, const edm::TypeWithDict &iType, bool lazy=false)
std::vector< std::shared_ptr< ExpressionBase > > ExpressionStack
std::vector< AnyMethodArgument > MethodArgumentStack
boost::spirit::classic::rule< ScannerT > rule
std::vector< SelectorPtr > SelectorStack
std::vector< LazyInvoker > LazyMethodStack
std::vector< int > IntStack
MethodArgumentStack methArgStack
definition(const Grammar &self)
std::vector< MethodInvoker > MethodStack
ExpressionStack exprStack
std::vector< Function > FunctionStack
std::shared_ptr< SelectorBase > SelectorPtr