Class: Temple::Mixins::GrammarDSL::Element 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

#copy_to, #match?, #|

Constructor Details

#initialize(grammar, rule) ⇒ Element

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 Element.



86
87
88
89
# File 'lib/temple/mixins/grammar_dsl.rb', line 86

def initialize(grammar, rule)
  super(grammar)
  @rule = grammar.Rule(rule)
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.



97
98
99
100
101
102
# File 'lib/temple/mixins/grammar_dsl.rb', line 97

def after_copy(source)
  @children = @children.map do |child|
    child == source ? self : child.copy_to(@grammar)
  end
  @rule = @rule.copy_to(@grammar)
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.



91
92
93
94
95
# File 'lib/temple/mixins/grammar_dsl.rb', line 91

def match(exp, unmatched)
  return false unless Array === exp && !exp.empty?
  head, *tail = exp
  @rule.match(head, unmatched) && super(tail, unmatched)
end