ruby-changes:40696
From: nobu <ko1@a...>
Date: Sat, 28 Nov 2015 14:43:23 +0900 (JST)
Subject: [ruby-changes:40696] nobu:r52775 (trunk): ripper/core.rb: share handlers
nobu 2015-11-28 14:43:17 +0900 (Sat, 28 Nov 2015) New Revision: 52775 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52775 Log: ripper/core.rb: share handlers * ext/ripper/lib/ripper/sexp.rb (SexpBuilderPP): share scanner event handlers and most of parser event handlers with SexpBuilder. Modified files: trunk/ext/ripper/lib/ripper/sexp.rb Index: ext/ripper/lib/ripper/sexp.rb =================================================================== --- ext/ripper/lib/ripper/sexp.rb (revision 52774) +++ ext/ripper/lib/ripper/sexp.rb (revision 52775) @@ -59,41 +59,6 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/sexp.rb#L59 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 https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/sexp.rb#L80 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/