Class: Rley::SPPF::NonTerminalNode
- Inherits:
-
CompositeNode
- Object
- SPPFNode
- CompositeNode
- Rley::SPPF::NonTerminalNode
- Defined in:
- lib/rley/sppf/non_terminal_node.rb
Overview
A node in a parse forest that matches exactly one non-terminal symbol.
Instance Attribute Summary collapse
-
#refinement ⇒ Object
Indication on how the sub-nodes contribute to the 'success' of parent node.
-
#symbol ⇒ Syntax::NonTerminal
readonly
Link to the non-terminal symbol.
Attributes inherited from CompositeNode
Attributes inherited from SPPFNode
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
-
#add_subnode(aSubnode) ⇒ Object
Add a sub-node (child) to this one.
-
#initialize(aNonTerminal, aRange) ⇒ NonTerminalNode
constructor
Constructor.
-
#to_string(indentation) ⇒ String
Emit a (formatted) string representation of the node.
Methods inherited from CompositeNode
#add_edge_signatures, #inspect, #key, #signature_exist?
Methods inherited from SPPFNode
Constructor Details
#initialize(aNonTerminal, aRange) ⇒ NonTerminalNode
Constructor
20 21 22 23 24 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 20 def initialize(aNonTerminal, aRange) super(aRange) @symbol = aNonTerminal @refinement = :and end |
Instance Attribute Details
#refinement ⇒ Object
Indication on how the sub-nodes contribute to the 'success' of parent node. Possible values: :and, :or
15 16 17 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 15 def refinement @refinement end |
#symbol ⇒ Syntax::NonTerminal (readonly)
Returns Link to the non-terminal symbol.
11 12 13 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 11 def symbol @symbol end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
45 46 47 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 45 def accept(aVisitor) aVisitor.visit_nonterminal(self) end |
#add_subnode(aSubnode) ⇒ Object
Add a sub-node (child) to this one.
28 29 30 31 32 33 34 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 28 def add_subnode(aSubnode) if refinement == :or subnodes << aSubnode else super(aSubnode) end end |
#to_string(indentation) ⇒ String
Emit a (formatted) string representation of the node. Mainly used for diagnosis/debugging purposes.
39 40 41 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 39 def to_string(indentation) return "#{symbol.name}#{range.to_string(indentation)}" end |