1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/ripper/lib/ripper/sexp.rb: new method Ripper.sexp_raw.

* ext/ripper/lib/ripper/sexp.rb (Ripper.sexp): returns more readable tree.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2005-07-26 13:42:49 +00:00
parent bf96629711
commit 57c8f59761
2 changed files with 52 additions and 5 deletions

View file

@ -1,3 +1,10 @@
Tue Jul 26 22:41:28 2005 Minero Aoki <aamine@loveruby.net>
* ext/ripper/lib/ripper/sexp.rb: new method Ripper.sexp_raw.
* ext/ripper/lib/ripper/sexp.rb (Ripper.sexp): returns more
readable tree. This is suggested by Kirill A. Shutemov.
Tue Jul 26 22:05:12 2005 Minero Aoki <aamine@loveruby.net>
* lib/net/http.rb: merge a patch contributed by Daniel Berger,

View file

@ -33,23 +33,63 @@ class Ripper
# nil]]]]
#
def Ripper.sexp(src, filename = '-', lineno = 1)
SexpBuilderPP.new(src, filename, lineno).parse
end
def Ripper.sexp_raw(src, filename = '-', lineno = 1)
SexpBuilder.new(src, filename, lineno).parse
end
class SexpBuilderPP < ::Ripper #:nodoc:
private
PARSER_EVENTS.each do |event|
case event.to_s
when /_new\z/
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}(*args)
[]
end
End
when /_add\z/
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}(list, item)
list.push item
list
end
End
else
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}(*args)
[:#{event}, *args]
end
End
end
end
SCANNER_EVENTS.each do |event|
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}(tok)
[:@#{event}, tok, [lineno(), column()]]
end
End
end
end
class SexpBuilder < ::Ripper #:nodoc:
private
PARSER_EVENTS.each do |event|
module_eval(<<-End)
def on_#{event}(*list)
list.unshift :#{event}
list
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}(*args)
args.unshift :#{event}
args
end
End
end
SCANNER_EVENTS.each do |event|
module_eval(<<-End)
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}(tok)
[:@#{event}, tok, [lineno(), column()]]
end