Need confirmation about PEG's semantic predicates in pyparsing
The PEG paper describes two semantic predicate parsing expressions:
- And predicate
&e
- Not predicate
!e
Does pyparsing support the And predicate ? Or is that just a synonym for the sequencing pars开发者_Python百科ing 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.
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".
精彩评论