Class: Dendroid::Parsing::OrNode
- Inherits:
-
CompositeParseNode
- Object
- ParseNode
- CompositeParseNode
- Dendroid::Parsing::OrNode
- Defined in:
- lib/dendroid/parsing/or_node.rb
Overview
A composite parse node that embodies multiple syntactical derivations of a right-hand side of a rule to a range of input tokens. Each child node corresponds to a distinct derivation.
Instance Attribute Summary collapse
-
#symbol ⇒ Dendroid::Syntax::NonTerminal
readonly
The non-terminal symbol at LHS of rule.
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
Add a child node as root of one derivation.
-
#initialize(sym, lower, upper, arity) ⇒ OrNode
constructor
A new instance of OrNode.
-
#match(anEItem) ⇒ Boolean
Is the given chart entry matching this node? The chart entry matches this node if: - its origin equals to the start of the range; and, - both rules are the same; and, - each child matches this chart entry.
- #partial? ⇒ FalseClass
-
#to_s ⇒ String
Return a String representation of itself.
Constructor Details
#initialize(sym, lower, upper, arity) ⇒ OrNode
Returns a new instance of OrNode.
17 18 19 20 |
# File 'lib/dendroid/parsing/or_node.rb', line 17 def initialize(sym, lower, upper, arity) @symbol = sym super(lower, upper, arity) end |
Instance Attribute Details
#symbol ⇒ Dendroid::Syntax::NonTerminal (readonly)
Returns The non-terminal symbol at LHS of rule.
11 12 13 |
# File 'lib/dendroid/parsing/or_node.rb', line 11 def symbol @symbol end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
61 62 63 |
# File 'lib/dendroid/parsing/or_node.rb', line 61 def accept(aVisitor) aVisitor.visit_or_node(self) end |
#add_child(child_node, _index) ⇒ Object
Add a child node as root of one derivation. Place it in an available child slot.
26 27 28 29 30 31 32 |
# File 'lib/dendroid/parsing/or_node.rb', line 26 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) ⇒ Boolean
Is the given chart entry matching this node? The chart entry matches this node if:
- its origin equals to the start of the range; and,
- both rules are the same; and,
- each child matches this chart entry
40 41 42 43 44 45 |
# File 'lib/dendroid/parsing/or_node.rb', line 40 def match(anEItem) return false if range.begin != anEItem.origin dotted = anEItem.dotted_item (symbol == dotted.rule.lhs) && children.any? { |ch| ch.match(anEItem) } end |
#partial? ⇒ FalseClass
48 49 50 51 |
# File 'lib/dendroid/parsing/or_node.rb', line 48 def partial? # children.any?(&:nil?) false end |
#to_s ⇒ String
Return a String representation of itself
55 56 57 |
# File 'lib/dendroid/parsing/or_node.rb', line 55 def to_s "OR: #{symbol.name} #{range_to_s}" end |