lib/raabro.rb in raabro-1.0.0 vs lib/raabro.rb in raabro-1.0.1

- old
+ new

@@ -24,11 +24,11 @@ #++ module Raabro - VERSION = '1.0.0' + VERSION = '1.0.1' class Input attr_accessor :string, :offset attr_reader :options @@ -396,9 +396,41 @@ r.prune! if input.options[:prune] r end alias jseq eseq + + def parse(input, opts={}) + + root = self.respond_to?(:root) ? :root : @last + + t = + if opts[:all] == false + _parse(root, Raabro::Input.new(input, opts)) + else + all(nil, Raabro::Input.new(input, opts), root) + end + + return nil if t.result != 1 + + t = t.children.first if t.parter == :all + t = opts[:shrink] == false ? t : t.shrink! + + return rewrite(t) if respond_to?(:rewrite) + + t + end + + 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 end extend ModuleMethods def self.included(target)