Does any Ruby parser exist?

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.

···

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Lothar Scholz wrote:

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!'" [:on__scan, "puts"] [:on__IDENTIFIER, "puts"] [:on__scan, " "] [:on__space, " "] [:on__scan, "'"] [:on__new_string, "'"] [:on__scan, "Hello World!"] [:on__add_string, nil, "Hello World!"] [:on__scan, "'"] [:on__string_end, nil, "'"] [:on__argstart, "Hello World!"] [:on__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...

Really? Where?

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

···

On May 10, 2005, at 11:23 AM, Lothar Scholz wrote:

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

--
ryand-ruby@zenspider.com - Seattle.rb - Seattle.rb | Home
http://blog.zenspider.com/ - http://rubyforge.org/projects/ruby2c

Hello Florian,

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.

How compatible are these rules with 1.8 ?

I think that Ripper will do what you want, but I think you will have to
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.

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.

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.

···

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Lothar Scholz wrote:

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.

> 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.

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.

> 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.

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.