Class: Temple::Mixins::GrammarDSL::Root Private

Inherits:
Or show all
Defined in:
lib/temple/mixins/grammar_dsl.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Or

#<<

Methods inherited from Rule

#match?, #|

Constructor Details

#initialize(grammar, name) ⇒ Root

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Root.



52
53
54
55
# File 'lib/temple/mixins/grammar_dsl.rb', line 52

def initialize(grammar, name)
  super(grammar)
  @name = name.to_sym
end

Instance Method Details

#after_copy(source) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
82
# File 'lib/temple/mixins/grammar_dsl.rb', line 79

def after_copy(source)
  @grammar.const_set(@name, self)
  super
end

#copy_to(grammar) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
# File 'lib/temple/mixins/grammar_dsl.rb', line 57

def match(exp, unmatched)
  success = super
  unmatched << [@name, exp] unless success
  success
end

#validate!(exp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
70
71
72
73
# 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