Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Ruby have an addon similar to Perl 6 grammars?

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.

like image 956
dreftymac Avatar asked Oct 28 '09 16:10

dreftymac


3 Answers

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.

like image 178
tene Avatar answered Sep 28 '22 08:09

tene


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 venerable yacc). 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.

like image 37
Jörg W Mittag Avatar answered Sep 28 '22 09:09

Jörg W Mittag


Don't know of anything similar for Ruby.

However there is something similar for Perl5, see Regexp::Grammars

like image 25
draegtun Avatar answered Sep 28 '22 07:09

draegtun