Question

The PEG paper describes two semantic predicate parsing expressions:

  1. And predicate &e
  2. Not predicate !e

Does pyparsing support the And predicate ? Or is that just a synonym for the sequencing parsing expression ? In that case it should be equivalent to the And class. Correct?

Does NotAny represent the Not predicate?

Specifically do they conform to the spec's behaviour:

The parsing expression foo &(bar) matches and consumes the text "foo" but only if it is followed by the text "bar". The parsing expression foo !(bar) matches the text "foo" but only if it is not followed by the text "bar". The expression !(a+ b) a matches a single "a" but only if it is not the first in an arbitrarily-long sequence of a's followed by a b.

Was it helpful?

Solution

The PEG & and ! predicates are non-consuming lookaheads, corresponding to pyparsing's FollowedBy and NotAny. & is different from the sequence in that "a + b" consumes both a and b expressions' text from the input string, but "a & b" means "match a only if followed by b, BUT DON'T CONSUME b".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top