我可以“不匹配”吗?在树顶上以编程方式制定规则?

发布于 2024-08-29 13:00:05 字数 230 浏览 3 评论 0原文

是否可以通过使用树顶中的 ruby​​ 代码验证来跳过规则?

假设有这样的事情:

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

end

我希望单词大小为 2 到 5 个字母。如果我发现text_value的长度不在2到5之间,我可以退出规则吗?

Is it possibe to skip a rule by validating it using ruby code in treetop?

Say there is something like this:

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

end

And I want the words size to be from 2 to 5 letters. Can I exit rule if I find that the length of text_value is not between 2 and 5?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左耳近心 2024-09-05 13:00:05

Treetop 的语法支持匹配的 {min,max} 界限。 (摘自 http://treetop.rubyforge.org/syntropic_recognition.html

重复计数

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

* '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

Treetop's syntax supports {min,max} bounds on matches. (Excerpt from http://treetop.rubyforge.org/syntactic_recognition.html)

Repetition count

A generalised repetition count (minimum, maximum) is also available.

* '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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文