mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ripper/core.rb: share handlers
* ext/ripper/lib/ripper/sexp.rb (SexpBuilderPP): share scanner event handlers and most of parser event handlers with SexpBuilder. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f8ecb823a0
commit
cf2b422fc5
1 changed files with 21 additions and 35 deletions
|
@ -59,41 +59,6 @@ class Ripper
|
||||||
sexp unless builder.error?
|
sexp unless builder.error?
|
||||||
end
|
end
|
||||||
|
|
||||||
class SexpBuilderPP < ::Ripper #:nodoc:
|
|
||||||
private
|
|
||||||
|
|
||||||
PARSER_EVENT_TABLE.each do |event, arity|
|
|
||||||
if /_new\z/ =~ event.to_s and arity == 0
|
|
||||||
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
|
||||||
def on_#{event}
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
End
|
|
||||||
elsif /_add\z/ =~ event.to_s
|
|
||||||
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:
|
class SexpBuilder < ::Ripper #:nodoc:
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -115,4 +80,25 @@ class Ripper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SexpBuilderPP < SexpBuilder #:nodoc:
|
||||||
|
private
|
||||||
|
|
||||||
|
def _dispatch_event_new
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
def _dispatch_event_push(list, item)
|
||||||
|
list.push item
|
||||||
|
list
|
||||||
|
end
|
||||||
|
|
||||||
|
PARSER_EVENT_TABLE.each do |event, arity|
|
||||||
|
if /_new\z/ =~ event and arity == 0
|
||||||
|
alias_method "on_#{event}", :_dispatch_event_new
|
||||||
|
elsif /_add\z/ =~ event
|
||||||
|
alias_method "on_#{event}", :_dispatch_event_push
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue