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
-
#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
Methods inherited from SPPFNode
Constructor Details
#initialize(aNonTerminal, aRange) ⇒ NonTerminalNode
Constructor
18 19 20 21 22 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 18 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
13 14 15 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 13 def refinement @refinement end |
#symbol ⇒ Syntax::NonTerminal (readonly)
Returns Link to the non-terminal symbol.
9 10 11 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 9 def symbol @symbol end |
Instance Method Details
#add_subnode(aSubnode) ⇒ Object
Add a sub-node (child) to this one.
26 27 28 29 30 31 32 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 26 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.
37 38 39 |
# File 'lib/rley/sppf/non_terminal_node.rb', line 37 def to_string(indentation) return "#{symbol.name}#{range.to_string(indentation)}" end |