I am trying to parse a rule
of the form predicate -> action
.
My problem is that predicate
can be any valid mathematical expression, so it may actually include a minus sign or a greater sign (but we have to disallow them in sequence as that's the token we want to separate predicate
from action
).
Essentially, I would like predicate
to consume all non-spaces until it hits the string "->"
.
How do I got about doing this?
Is the right approach to fix the line I have commented below or should I better define what a predicate
is, in terms of a valid expression, and let the parser fall into "->"
when predicate
ends, according to that valid expression?
rule %=
predicate
>> "->"
>> action
;
predicate %= (+~(qi::char_("-"))); // BAD: works only if no minus sign in predicate
action %= (+(qi::char_));
Rephrase predicate
as follows:
predicate = +(qi::char_ - "->");
action = +(qi::char_);
Equivalently,
predicate = +(!qi::lit("->") >> qi::char_);
should do the same.
See the docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With