зеркало из https://github.com/github/ruby.git
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:
Родитель
f8ecb823a0
Коммит
cf2b422fc5
|
@ -59,41 +59,6 @@ class Ripper
|
|||
sexp unless builder.error?
|
||||
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:
|
||||
private
|
||||
|
||||
|
@ -115,4 +80,25 @@ class Ripper
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче