Ruby 有类似于 Perl 6 语法的插件吗?
多年来,Perl 一直是我首选的编程语言工具之一。 Perl 6 语法看起来是一个很棒的语言功能。我想知道是否有人为 Ruby 开始了类似的事情。
Perl has been one of my go-to programming language tools for years and years. Perl 6 grammars looks like a great language feature. I'd like to know if someone has started something like this for Ruby.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不知道 Ruby 是否有类似的情况。
然而 Perl5 也有类似的东西,请参阅
Regexp::Grammars
< /a>Don't know of anything similar for Ruby.
However there is something similar for Perl5, see
Regexp::Grammars
不。而且,由于 Perl6 语法是一种语言功能,而 Ruby 不允许扩展该语言,因此实际上不可能在“插件”中实现此功能。
然而,Ruby 有许多库可以实现不同类型的解析或语法系统。标准库已经包含
racc
,它是一个 LALR(1) 解析器生成器(与古老的yacc
相当并在某种程度上兼容)。然后是 ANTLR 解析器生成器,它有一个 Ruby 后端(尽管我不确定它是否真的有效)。Ruby 中最接近 Perl6 语法的是 Ruby-OMeta 项目(请确保也看看 Ryan Davis 的分支),不幸的是它仍在开发中。 (或者更确切地说,不再处于积极开发中。)
因此,保留实际存在的内容,我建议您查看 语法项目 和 Treetop。
No. And, since Perl6 grammars are a language feature, and Ruby doesn't allow the language to be extended, it is actually impossible to implement this in an "addon".
However, there are numerous libraries for Ruby which implement different kinds of Parsing or Grammar Systems. The standard library already contains
racc
, which is an LALR(1) parser generator (comparable to and somewhat compatible with the venerableyacc
). Then there is the ANTLR parser generator, which has a Ruby backend (although I am not sure whether that actually works).The closest thing to Perl6 grammars in Ruby would be the Ruby-OMeta project (make sure to also take a look at Ryan Davis's fork), which unfortunately ist still under development. (Or rather, no longer under active development.)
So, keeping to stuff that actually exists, I recommend you take a look at the Grammar project and Treetop.
如果你想在 Ruby 中使用实际的 Perl 6 语法,你最好的选择是 Cardinal,Parrot 上的 ruby 编译器。它目前尚未完成并且非常缓慢,但我非常希望它最终成为一个可行的 ruby 实现。它目前大部分处于不活动状态,等待 Parrot 中的一些基础设施更改以支持改进的解析速度和其他功能。
If you want to use actual Perl 6 grammars in Ruby, your best bet is going to be Cardinal, a ruby compiler on Parrot. It's currently unfinished and VERY SLOW, but I'm quite hopeful about it being a viable ruby implementation eventually. It's currently mostly-inactive, pending some infrastructure changes in Parrot to support improved parsing speed and additional features.