Class: Rley::SPPF::TokenNode
- Defined in:
- lib/rley/sppf/token_node.rb
Overview
A SPPF node that matches exactly one token from the input.
Instance Attribute Summary collapse
-
#token ⇒ Lexical::Token
readonly
The input token that is represented by this parse node.
Attributes inherited from SPPFNode
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
-
#initialize(aToken, aPosition) ⇒ TokenNode
constructor
Constructor.
-
#to_string(indentation) ⇒ String
Emit a (formatted) string representation of the node.
Methods inherited from LeafNode
Methods inherited from SPPFNode
Constructor Details
#initialize(aToken, aPosition) ⇒ TokenNode
Constructor
17 18 19 20 21 |
# File 'lib/rley/sppf/token_node.rb', line 17 def initialize(aToken, aPosition) range = { low: aPosition, high: aPosition + 1 } super(range) @token = aToken end |
Instance Attribute Details
#token ⇒ Lexical::Token (readonly)
The input token that is represented by this parse node.
12 13 14 |
# File 'lib/rley/sppf/token_node.rb', line 12 def token @token end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
33 34 35 |
# File 'lib/rley/sppf/token_node.rb', line 33 def accept(aVisitor) aVisitor.visit_terminal(self) end |
#to_string(indentation) ⇒ String
Emit a (formatted) string representation of the node. Mainly used for diagnosis/debugging purposes.
27 28 29 |
# File 'lib/rley/sppf/token_node.rb', line 27 def to_string(indentation) "#{token.terminal.name}#{range.to_string(indentation)}" end |