# Best lexer/parser for Ruby language itself

**URL:** <https://www.ruby-forum.com/t/best-lexer-parser-for-ruby-language-itself/50813>\
**Category:** Ruby\
**Created:** [December 21, 2005, 12:30pm UTC](https://www.ruby-forum.com/t/best-lexer-parser-for-ruby-language-itself/50813 "2005-12-21T12:30:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anatol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@anatol](https://www.ruby-forum.com/u/anatol)\
**Post date:** [December 21, 2005, 12:30pm UTC](https://www.ruby-forum.com/t/best-lexer-parser-for-ruby-language-itself/50813/1 "2005-12-21T12:30:10Z")

</div>

Hi, all.

I need to do following thing: I have some program on ruby and I would  
like  
parse this program, do some manipulations with code and write back it to  
file.

Manipulations with sourcecode quite simple, like changing from  
puts 2 if a.nil?  
to  
if a.nil?  
puts 2  
end

or %Q{hello world} -\> “hello world”

program is very similar to ruby code beautifier (and probably will be  
somewhere in the future).

I am looking for articles/documents with theory background in this area  
as  
well as example programs (better on ruby)

Could you also help me with choosing what is the best lib for doing  
that. I  
saw bunch of ruby parser/lexer libs among them: grammar, parsetree,  
rubylexer, syntax, ripper. I dont know what is the best for my task. And  
I  
dont know from what to start. Could you give me any advice on that?
