Which is the best counterpart to ANTLR to create parsers in ruby?
Asked Answered
I

3

8

I've used antlr and javacc/freecc for a while. Now I need to write a bunch of parsers using antlr grammars but such parsers need to be written in ruby lang.

I googled but nothing found. Is there any ruby parser generator that takes antlr grammars and create a parser? If there are many, which is the best one in your opinion?

TIA Paolo

Impatience answered 15/6, 2010 at 7:58 Comment(0)
B
1

You could also generate the parser with ANTLR for Java or C and call it from your Ruby program with JRuby or FFI.

This should also give you a performance boost which might be a big advantage if you have a lot of input to parse.

Balls answered 15/6, 2010 at 8:25 Comment(1)
ahe, that's exactly what I choose to do. I fired up a new project (github.com/thesp0nge/mirage) concerning all stuff about parsing source code. I'll write mirage in C using antlr and then I'll call it from Ruby. For anyone interested, this is for a major rewrite for the Owasp Orizon project, a static source code analyzer I'm writing (github.com/thesp0nge/owasp-orizon)Impatience
E
9
  1. You might get away easy by using JRuby and keeping your ANTLR parsers in java.
  2. If PEGs are enough for your job, treetop and the newer citrus are common tools used by rubyists.
  3. Other parsers I dug while researching for a project are: peggy, Kanocc, Racc.

For my project I chosed treetop (citrus was not born yet).

Entoderm answered 15/6, 2010 at 8:21 Comment(0)
P
3

Why not to use ANTLR Ruby: http://www.antlr.org/wiki/display/ANTLR3/Antlr3RubyTarget (http://split-s.blogspot.com/2005/12/antlr-for-ruby.html)

There is also some beta here: http://rubyforge.org/projects/antlr3/

Pilcomayo answered 15/6, 2010 at 8:15 Comment(2)
Shame on me. I didn't check the proper place first... the gem community. Thank you so much :-)Impatience
Note that the Ruby target shipped with ANTLR 3.4 is quite broken. If there are any issues with the gem, the head revision of the project on GitHub appears to work ok: github.com/ohboyohboyohboy/antlr3Excurrent
B
1

You could also generate the parser with ANTLR for Java or C and call it from your Ruby program with JRuby or FFI.

This should also give you a performance boost which might be a big advantage if you have a lot of input to parse.

Balls answered 15/6, 2010 at 8:25 Comment(1)
ahe, that's exactly what I choose to do. I fired up a new project (github.com/thesp0nge/mirage) concerning all stuff about parsing source code. I'll write mirage in C using antlr and then I'll call it from Ruby. For anyone interested, this is for a major rewrite for the Owasp Orizon project, a static source code analyzer I'm writing (github.com/thesp0nge/owasp-orizon)Impatience

© 2022 - 2024 — McMap. All rights reserved.