J
John Micheal
Hi!
I want AST for the following code as it is given below. I have install
ruby_parser 1.0 on my system. We are able to parse string using
"RubyParser.new.parse("1+1 = 2")" and the result is " sstr, "1+1=2")".
But how I can parse the full source file(given below)?
Further, whenever I try to parse the string containing class or def in
it, it gives error (it means, it is parsing C code not ruby) I have also
attached the screenshot for this problem. Please also guide us in this
mater.
Ruby Code:
....................readfile.rb
class TestClass
def method1(a,b)
sum = a + b
puts sum
end
def method2(*c)
l = c.length
puts l
end
end
Desired AST Tree:
....................
sclass, :TestClass, sconst, :Object), sdefn, :method1, sscope,
sblock, sargs, :a, :b), slasgn, :sum, scall, slvar, :a), :+,
sarray, slvar, :b)))), sfcall, uts, sarray, slvar,
:sum)))))), sdefn, :method2, sscope, sblock, sargs, :"*c"),
slasgn, :l, scall, slvar, :c), :length)), sfcall, uts,
sarray, slvar, :l)))))))
Attachments:
http://www.ruby-forum.com/attachment/2131/error.GIF
I want AST for the following code as it is given below. I have install
ruby_parser 1.0 on my system. We are able to parse string using
"RubyParser.new.parse("1+1 = 2")" and the result is " sstr, "1+1=2")".
But how I can parse the full source file(given below)?
Further, whenever I try to parse the string containing class or def in
it, it gives error (it means, it is parsing C code not ruby) I have also
attached the screenshot for this problem. Please also guide us in this
mater.
Ruby Code:
....................readfile.rb
class TestClass
def method1(a,b)
sum = a + b
puts sum
end
def method2(*c)
l = c.length
puts l
end
end
Desired AST Tree:
....................
sclass, :TestClass, sconst, :Object), sdefn, :method1, sscope,
sblock, sargs, :a, :b), slasgn, :sum, scall, slvar, :a), :+,
sarray, slvar, :b)))), sfcall, uts, sarray, slvar,
:sum)))))), sdefn, :method2, sscope, sblock, sargs, :"*c"),
slasgn, :l, scall, slvar, :c), :length)), sfcall, uts,
sarray, slvar, :l)))))))
Attachments:
http://www.ruby-forum.com/attachment/2131/error.GIF