本文介绍了Treetop/PEG中的非贪婪匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何在Treetop中做类似的事情?
How would I do something like this in Treetop?
/.+?;/
似乎唯一的方法是这样做:
It seems like the only way is to do:
[^;]+ ';'
还有什么丑陋的..其他方式吗? .+?
似乎不起作用.
Which is kind of ugly.. any other way? .+?
doesn't seem to work..
推荐答案
默认情况下,PEG是贪婪和盲目的,这意味着它们会尽可能多地吃掉它们的输入,并且他们不考虑随后发生的事情:
PEGs are greedy and blind by default, that means they eat as much input as they can and they do not consider what comes afterwards:
S <- P1* P2
(贪婪,盲目)
尽管可以通过使用有序选择(并且无需使用先行提示)来解决该问题,但相当容易:
That can be considerably easy fixed though by making use of the ordered choice (and without using lookaheads):
S <- P1 S / P2
(贪婪,非盲目)
S <- P2 / P1 S
(懒惰,非盲)
这篇关于Treetop/PEG中的非贪婪匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!