lib/raabro.rb in raabro-1.0.3 vs lib/raabro.rb in raabro-1.0.4

- old
+ new

@@ -24,11 +24,11 @@ #++ module Raabro - VERSION = '1.0.3' + VERSION = '1.0.4' class Input attr_accessor :string, :offset attr_reader :options @@ -386,10 +386,21 @@ r end alias jseq eseq + attr_accessor :last + + def method_added(name) + + m = method(name) + return unless m.arity == 1 + return unless m.parameters[0][1] == :i || m.parameters[0][1] == :input + + @last = name.to_sym + end + def parse(input, opts={}) opts[:prune] = true unless opts.has_key?(:prune) root = self.respond_to?(:root) ? :root : @last @@ -403,23 +414,20 @@ return nil if opts[:prune] != false && t.result != 1 t = t.children.first if t.parter == :all - return rewrite(t) if opts[:rewrite] != false && respond_to?(:rewrite) + return rewrite(t) if opts[:rewrite] != false && rewrite(0) == true t end - attr_accessor :last + def rewrite(tree) - def method_added(name) + return !! methods.find { |m| m.to_s.match(/^rewrite_/) } if tree == 0 + # return true when "rewrite_xxx" methods seem to have been provided - m = method(name) - return unless m.arity == 1 - return unless m.parameters[0][1] == :i || m.parameters[0][1] == :input - - @last = name.to_sym + send("rewrite_#{tree.name}", tree) end end extend ModuleMethods def self.included(target)