3

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_));
4

1 に答える 1