[Spirit/qi] parsing order, exact matches
Dear Boost-User list, I have modified the calc6-example from the Spirit docs, so that it uses double variables rather than integers. I have then added a number of mathematical functions. The rule for the unary functions (reduced to just sin and sinh here for readability) is: unary_function_rule_ = (string_("sin") > '(' > expression_rule_ > ')') | (string_("sinh") > '(' > expression_rule_ > ')') ; I would have expected the "sin" part of the rule to trigger only when there is a "sin" string, which is immediately followed by a '('. This works o.k. when the function in question really contains a sin(). However, when I pass a "sinh()", I get an error message that it failed parsing a "h(", so the "sin" part of the message has triggered. Changing the order of sinh and sin in the rule cures the problem. Still I would like to understand how I can make the sin-part of the rule only trigger for expressions like "sin(3.14)", but not for e.g. "sinh(2)". Thanks and best regards, Beet
On 10/2/2013 2:31 PM, beet wrote:
Dear Boost-User list,
I have modified the calc6-example from the Spirit docs, so that it uses double variables rather than integers. I have then added a number of mathematical functions.
The rule for the unary functions (reduced to just sin and sinh here for readability) is:
unary_function_rule_ = (string_("sin") > '(' > expression_rule_ > ')') | (string_("sinh") > '(' > expression_rule_ > ')') ;
For this specific case you can reverse the order:
(string_("sinh") > '(' > expression_rule_ > ')') | (string_("sin") > '(' > expression_rule_ > ')')
for the more general case see: http://www.boost.org/doc/libs/1_41_0/libs/spirit/repository/doc/html/spirit_... Jeff
participants (2)
-
beet
-
Jeff Flinn