2010-04-15 44 views
0

是否可以通过在树梢上使用ruby代码验证它来跳过规则?我可以在树顶以编程方式“不匹配”规则吗?

说有这样的事情:

rule short_words 
    [a-z]+ { 
    def method1 
     text_value 
    end 
    ... 
    } 

end 

而且我想要的话大小为2至5个字母。如果我发现text_value的长度不在2到5之间,我可以退出规则吗?

回答

1

Treetop的语法支持匹配上的{min,max}边界。 (从http://treetop.rubyforge.org/syntactic_recognition.html节选)

重复计数

广义重复计数(最小,最大)也是可用的。

* 'foo' 2.. matches 'foo' two or more times 
* 'foo' 3..5 matches 'foo' from three to five times 
* 'foo' ..4 matches 'foo' from zero to four times 
+0

非常感谢! – dimus 2011-02-03 14:48:49

相关问题