Class: Dendroid::Parsing::OrNode
- Inherits:
-
CompositeParseNode
- Object
- ParseNode
- CompositeParseNode
- Dendroid::Parsing::OrNode
- Defined in:
- lib/dendroid/parsing/or_node.rb
Instance Attribute Summary collapse
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Attributes inherited from CompositeParseNode
Attributes inherited from ParseNode
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
- #add_child(child_node, _index) ⇒ Object
-
#initialize(sym, lower, upper, arity) ⇒ OrNode
constructor
A new instance of OrNode.
- #match(anEItem) ⇒ Object
- #partial? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(sym, lower, upper, arity) ⇒ OrNode
Returns a new instance of OrNode.
10 11 12 13 |
# File 'lib/dendroid/parsing/or_node.rb', line 10 def initialize(sym, lower, upper, arity) @symbol = sym super(lower, upper, arity) end |
Instance Attribute Details
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
8 9 10 |
# File 'lib/dendroid/parsing/or_node.rb', line 8 def symbol @symbol end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
41 42 43 |
# File 'lib/dendroid/parsing/or_node.rb', line 41 def accept(aVisitor) aVisitor.visit_or_node(self) end |
#add_child(child_node, _index) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/dendroid/parsing/or_node.rb', line 15 def add_child(child_node, _index) idx = children.find_index(&:nil?) raise StandardError unless idx # Use first found available slot... super(child_node, idx) end |
#match(anEItem) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/dendroid/parsing/or_node.rb', line 23 def match(anEItem) return false if range[0] != anEItem.origin dotted = anEItem.dotted_item (symbol == dotted.rule.lhs) && children.any? { |ch| ch.match(anEItem) } end |
#partial? ⇒ Boolean
30 31 32 33 |
# File 'lib/dendroid/parsing/or_node.rb', line 30 def partial? # children.any?(&:nil?) false end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/dendroid/parsing/or_node.rb', line 35 def to_s "OR: #{symbol.name} #{range}" end |