开发者

Need confirmation about PEG's semantic predicates in pyparsing

开发者 https://www.devze.com 2023-03-01 14:22 出处:网络
The PEG paper describes two semantic predicate parsing expressions: And predicate &e Not predicate !e

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 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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号