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>
72 public boost::spirit::classic::grammar_def<boost::spirit::classic::rule<ScannerT>,
73 boost::spirit::classic::same,
74 boost::spirit::classic::same>{
75 typedef boost::spirit::classic::rule<ScannerT>
rule;
76 rule number,
var,
arrayAccess,
metharg,
method,
term,
power,
factor,
function1,
function2,
function4,
expression,
81 using namespace boost::spirit::classic;
125 BOOST_SPIRIT_DEBUG_RULE(
var);
127 BOOST_SPIRIT_DEBUG_RULE(
method);
132 BOOST_SPIRIT_DEBUG_RULE(
number);
133 BOOST_SPIRIT_DEBUG_RULE(
metharg);
138 BOOST_SPIRIT_DEBUG_RULE(
term);
139 BOOST_SPIRIT_DEBUG_RULE(
power);
140 BOOST_SPIRIT_DEBUG_RULE(
factor);
141 BOOST_SPIRIT_DEBUG_RULE(
or_op);
142 BOOST_SPIRIT_DEBUG_RULE(
and_op);
146 BOOST_SPIRIT_DEBUG_RULE(
cut);
147 BOOST_SPIRIT_DEBUG_RULE(
fun);
150 boost::spirit::classic::assertion<SyntaxErrors> expect(
kSyntaxError);
154 metharg = ( strict_real_p [ methodArg_s ] ) |
155 ( int_p [ methodArg_s ] ) |
156 ( ch_p(
'"' ) >> *(~ch_p(
'"' )) >> ch_p(
'"' ) ) [ methodArg_s ] |
157 ( ch_p(
'\'') >> *(~ch_p(
'\'')) >> ch_p(
'\'') ) [ methodArg_s ];
159 (lexeme_d[alpha_p >> * chset<>(
"a-zA-Z0-9_")] >>
160 ch_p(
'(') >>
metharg >> * (ch_p(
',') >>
metharg ) >> expectParenthesis(ch_p(
')'))) [ method_s ] |
161 ( (lexeme_d[alpha_p >> * chset<>(
"a-zA-Z0-9_")]) [ method_s ] >> ! (ch_p(
'(') >> ch_p(
')')) ) ;
166 chseq_p(
"abs") [ abs_s ] | chseq_p(
"acos") [ acos_s ] | chseq_p(
"asin") [ asin_s ] |
167 chseq_p(
"atan") [ atan_s ] | chseq_p(
"cosh") [ cosh_s ] | chseq_p(
"cos") [ cos_s ] |
168 chseq_p(
"exp") [ exp_s ] | chseq_p(
"log") [ log_s ] | chseq_p(
"log10") [ log10_s ] |
169 chseq_p(
"sinh") [ sinh_s ] | chseq_p(
"sin") [ sin_s ] | chseq_p(
"sqrt") [ sqrt_s ] |
170 chseq_p(
"tanh") [ tanh_s ] | chseq_p(
"tan") [ tan_s ];
172 chseq_p(
"atan2") [ atan2_s ] | chseq_p(
"chi2prob") [ chi2prob_s ] | chseq_p(
"pow") [ pow_s ] |
173 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] ;
175 chseq_p(
"deltaR") [deltaR_s];
180 term >> (* ((
'+' >> expect(
term)) [ plus_s ] |
181 (
'-' >> expect(
term)) [ minus_s ]));
185 power >> * ((
'*' >> expect(
power)) [ multiplies_s ] |
186 (
'/' >> expect(
power)) [ divides_s ]);
191 (
function1 >> ch_p(
'(') [funOk_s ] >> expect(
expression) >> expectParenthesis(ch_p(
')'))) [ fun_s ] |
193 expect(ch_p(
',')) >> expect(
expression) >> expectParenthesis(ch_p(
')'))) [ fun_s ] |
195 expect(ch_p(
',')) >> expect(
expression) >> expectParenthesis(ch_p(
')'))) [ fun_s ] |
206 (ch_p(
'-') >>
factor) [ negate_s ] |
209 (ch_p(
'<') >> ch_p(
'=') [ less_equal_s ]) |
210 (ch_p(
'<') [ less_s ]) |
211 (ch_p(
'=') >> ch_p(
'=') [ equal_to_s ]) |
212 (ch_p(
'=') [ equal_to_s ]) |
213 (ch_p(
'>') >> ch_p(
'=') [ greater_equal_s ]) |
214 (ch_p(
'>') [ greater_s ]) |
215 (ch_p(
'!') >> ch_p(
'=') [ not_equal_to_s ]);
220 or_op = ch_p(
'|') >> ch_p(
'|') | ch_p(
'|');
221 and_op = ch_p(
'&') >> ch_p(
'&') | ch_p(
'&');
235 this->start_parsers(
cut,
fun);
Grammar(ExpressionPtr &expr, const Reflex::Type &iType, bool lazy=false)
LazyMethodStack lazyMethStack
FunctionStack finalFunStack
boost::shared_ptr< ExpressionBase > ExpressionPtr
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
Grammar(SelectorPtr &sel, const Reflex::Type &iType, bool lazy=false)
std::vector< boost::shared_ptr< ComparisonBase > > ComparisonStack
std::vector< Function > FunctionStack
std::vector< Reflex::Type > TypeStack