需要确认 pyparsing 中 PEG 的语义谓词
PEG 论文描述了两种语义谓词解析表达式:
- 和谓词
&e
- 非谓词
!e
pyparsing 是否支持 And 谓词?或者这只是排序解析表达式的同义词?在这种情况下,它应该等同于 And
类。正确的?
NotAny
是否表示 Not 谓词?
具体来说,它们是否符合规范的行为:
解析表达式 foo &(bar) 匹配并使用文本“foo”,但前提是它后面跟着文本“bar”。解析表达式 foo !(bar) 匹配文本“foo”,但前提是它后面没有文本“bar”。表达式 !(a+ b) a 匹配单个“a”,但前提是它不是 a 后跟 b 的任意长序列中的第一个。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PEG&和 !谓词是非消耗性的前瞻,对应于 pyparsing 的 FollowedBy 和 NotAny。 &与序列的不同之处在于“a + b”消耗输入字符串中的 a 和 b 表达式的文本,但“a & b”表示“仅在后面跟着 b 时匹配 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".