Boost logo

Boost Users :

Subject: [Boost-users] [Spirit/qi] parsing order, exact matches
From: beet (r.berlich_at_[hidden])
Date: 2013-10-02 14:31:38


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net