2

In my parser, sometimes the grammar accommodates a match on just the first section of an input string. This seems to be normal behavior for phrase_parse(), but is not what I'm looking for in my application.

How can I require that the whole input string match the grammar for a successful parse, rather than returning success on shorter matches that don't consume all of the input string?

leecbaker
  • 3,611
  • 2
  • 35
  • 51

1 Answers1

3

Just require qi::eoi at the end:

bool ok = qi::phrase_parse(f, l, grammar >> eoi, skipper);

This also works to discard branches that didn't match all input:

myrule = (legA >> eoi) | (legB >> eoi) | (legC >> eoi);

See also

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633