From: "Florian Groß" Date: 2005-05-11T04:53:28+09:00 Subject: Re: Does any Ruby parser exist ? 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 > => # > 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...