Does any Ruby parser exist ?

L

Lothar Scholz

Hello ruby-talk,

Does any Ruby parser existother then the internal one inside the ruby
interpreter. I found a few projects but most of them seems to be dead.

bRuby (not really a parser) and Ripper are old and not touched since
2003. I need some positional data for the AST and a defined way to
traverse the AST. Even the ParseTree project forgets to traverse some
branches inside the tree.
 
F

Florian Groß

Lothar said:
Does any Ruby parser existother then the internal one inside the ruby
interpreter. I found a few projects but most of them seems to be dead.

bRuby (not really a parser) and Ripper are old and not touched since
2003.

Ripper has been merged into 1.9 and is part of the windows one-click
installer -- its grammar rules will thus always be up-to-date in the future.

It is used like this:
irb(main):001:0> require 'ripper'
=> true
irb(main):002:0> ripper = Ripper.new
=> #<Ripper:0x28e2810>
irb(main):003:0> def ripper.method_missing(*args) p args end
=> nil
irb(main):004:0> ripper.parse "puts 'Hello World!'"
[:eek:n__scan, "puts"]
[:eek:n__IDENTIFIER, "puts"]
[:eek:n__scan, " "]
[:eek:n__space, " "]
[:eek:n__scan, "'"]
[:eek:n__new_string, "'"]
[:eek:n__scan, "Hello World!"]
[:eek:n__add_string, nil, "Hello World!"]
[:eek:n__scan, "'"]
[:eek:n__string_end, nil, "'"]
[:eek:n__argstart, "Hello World!"]
[:eek:n__fcall, :puts, nil]
=> nil
I need some positional data for the AST and a defined way to
traverse the AST. Even the ParseTree project forgets to traverse some
branches inside the tree.

I think that Ripper will do what you want, but I think you will have to
build the tree by yourself.

That aside there is also a few lexers like the IRB one and the one used
by the syntax library that does Ruby code highlighting.

I think there were other projects that generate ASTs as well, but I have
trouble remembering their names right now... Perhaps I am wrong...
 
L

Lothar Scholz

Hello Florian,

FG> Ripper has been merged into 1.9 and is part of the windows one-click
FG> installer -- its grammar rules will thus always be up-to-date in the future.

How compatible are these rules with 1.8 ?

FG> I think that Ripper will do what you want, but I think you will have to
FG> build the tree by yourself.

Okay i will see if i can use Ripper, as i must add it to a running
1.8.2 ruby system.

FG> That aside there is also a few lexers like the IRB one and the one used
FG> by the syntax library that does Ruby code highlighting.

They are all ugly hacks that are just doing a fraction of the ruby
grammer. Good for there special purpose but i need something
different. And none of them can give me line/column positions of an
indentifier.
 
F

Florian Groß

Lothar said:
FG> Ripper has been merged into 1.9 and is part of the windows one-click
FG> installer -- its grammar rules will thus always be up-to-date in the future.

How compatible are these rules with 1.8 ?

It uses the same rules as the platform it is build against. The
one-click installer is on 1.8.2 and comes with Ripper so it works there.
FG> That aside there is also a few lexers like the IRB one and the one used
FG> by the syntax library that does Ruby code highlighting.

They are all ugly hacks that are just doing a fraction of the ruby
grammer. Good for there special purpose but i need something
different. And none of them can give me line/column positions of an
indentifier.

IRB's lexer will give you the column and line numbers. It also ought to
lex quite a lot of Ruby. Of course having a complete parser at all times
is hard without using Ruby's built-in grammar.
 
R

Ryan Davis

Even the ParseTree project forgets to traverse some branches inside
the tree.

Really? Where?

Please respond directly, or better, file a bug at http://
rubyforge.org/projects/parsetree/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,738
Latest member
TiffinyHol

Latest Threads

Top