class Temple::Mixins::GrammarDSL::Root

Public Class Methods

new(grammar, name) click to toggle source
Calls superclass method Temple::Mixins::GrammarDSL::Or::new
# File lib/temple/mixins/grammar_dsl.rb, line 52
def initialize(grammar, name)
  super(grammar)
  @name = name.to_sym
end

Public Instance Methods

after_copy(source) click to toggle source
# File lib/temple/mixins/grammar_dsl.rb, line 79
def after_copy(source)
  @grammar.const_set(@name, self)
  super
end
copy_to(grammar) click to toggle source
# File lib/temple/mixins/grammar_dsl.rb, line 75
def copy_to(grammar)
  grammar.const_defined?(@name) ? grammar.const_get(@name) : super
end
match(exp, unmatched) click to toggle source
Calls superclass method Temple::Mixins::GrammarDSL::Or#match
# File lib/temple/mixins/grammar_dsl.rb, line 57
def match(exp, unmatched)
  success = super
  unmatched << [@name, exp] unless success
  success
end
validate!(exp) click to toggle source
# File lib/temple/mixins/grammar_dsl.rb, line 63
def validate!(exp)
  unmatched = []
  unless match(exp, unmatched)
    require 'pp'
    entry = unmatched.first
    unmatched.reverse_each do |u|
      entry = u if u.flatten.size < entry.flatten.size
    end
    raise(InvalidExpression, PP.pp(entry.last, "#{@grammar}::#{entry.first} did not match\n".dup))
  end
end