summaryrefslogtreecommitdiff
path: root/ext/ripper/lib/ripper/sexp.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-28 05:43:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-28 05:43:17 +0000
commitcf2b422fc58bd34332a123896253b12c627d8b21 (patch)
tree2ca5a605866e1789d7543f010ca26d468361407b /ext/ripper/lib/ripper/sexp.rb
parentf8ecb823a0705eda22f845abea38fc065ecc3ab9 (diff)
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
Diffstat (limited to 'ext/ripper/lib/ripper/sexp.rb')
-rw-r--r--ext/ripper/lib/ripper/sexp.rb56
1 files changed, 21 insertions, 35 deletions
diff --git a/ext/ripper/lib/ripper/sexp.rb b/ext/ripper/lib/ripper/sexp.rb
index 150c6f0..55b942a 100644
--- a/ext/ripper/lib/ripper/sexp.rb
+++ b/ext/ripper/lib/ripper/sexp.rb
@@ -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