Last active
December 10, 2015 13:28
Revisions
-
JoshCheek revised this gist
Jan 3, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ require 'ripper' Ripper::SexpBuilder.instance_methods.grep(/error/i) # => [:on_alias_error, :on_assign_error, :on_class_name_error, :on_param_error, :on_parse_error] class DemoBuilder < Ripper::SexpBuilder instance_methods.each do |meth_name| next unless meth_name =~ /^on_/ -
JoshCheek created this gist
Jan 3, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ require 'ripper' class DemoBuilder < Ripper::SexpBuilder instance_methods.each do |meth_name| next unless meth_name =~ /^on_/ super_meth = instance_method meth_name define_method meth_name do |*args| super_meth.bind(self).call(*args).tap do |result| puts "#{meth_name}(#{args.map(&:inspect).join(', ')})".ljust(50) << " #> #{result.inspect}" end end end end src = %(+) DemoBuilder.new(src).parse # >> on_op("+") #> [:@op, "+", [1, 0]] # >> on_parse_error("syntax error, unexpected $end") #> [:parse_error, "syntax error, unexpected $end"]