# Parsing a ruby code

**URL:** <https://www.ruby-forum.com/t/parsing-a-ruby-code/139879>\
**Category:** Ruby\
**Created:** [June 8, 2008, 5:01pm UTC](https://www.ruby-forum.com/t/parsing-a-ruby-code/139879 "2008-06-08T17:01:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeeshanbth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce73a5/32.png) [@zeeshanbth](https://www.ruby-forum.com/u/zeeshanbth)\
**Post date:** [June 8, 2008, 5:01pm UTC](https://www.ruby-forum.com/t/parsing-a-ruby-code/139879/1 "2008-06-08T17:01:05Z")

</div>

Hello,  
I am using the below given code to parse ruby code line by line and  
generate its s-expression (AST). The help i need from you is that i want  
to parse the whole ruby file at a time instead of parsing line by line.

require “ruby\_parser”

# puts RubyParser.new.parse(“My name is defecto”)

counter = 1  
file = File.new(“readfile.rb”, “r”)

while (line = file.gets)  
puts “#{counter}: #{RubyParser.new.parse(line)}”  
counter = counter + 1  
end
