Class: Rley::PTree::TerminalNode
- Inherits:
-
ParseTreeNode
- Object
- ParseTreeNode
- Rley::PTree::TerminalNode
- Defined in:
- lib/rley/ptree/terminal_node.rb
Instance Attribute Summary collapse
-
#token ⇒ Lexical::Token
readonly
The input token.
Attributes inherited from ParseTreeNode
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
-
#initialize(aToken, aPos) ⇒ TerminalNode
constructor
A new instance of TerminalNode.
-
#to_s ⇒ Object
Emit a short string representation of the node.
-
#to_string(indentation) ⇒ Object
Emit a (formatted) string representation of the node.
Methods inherited from ParseTreeNode
Constructor Details
#initialize(aToken, aPos) ⇒ TerminalNode
Returns a new instance of TerminalNode.
13 14 15 16 17 18 19 20 |
# File 'lib/rley/ptree/terminal_node.rb', line 13 def initialize(aToken, aPos) # (major, minor) = # Use '1.class' trick to support both Integer and Fixnum classes range = aPos.kind_of?(1.class) ? { low: aPos, high: aPos + 1 } : aPos super(aToken.terminal, range) @token = aToken end |
Instance Attribute Details
#token ⇒ Lexical::Token (readonly)
Returns the input token.
9 10 11 |
# File 'lib/rley/ptree/terminal_node.rb', line 9 def token @token end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
36 37 38 |
# File 'lib/rley/ptree/terminal_node.rb', line 36 def accept(aVisitor) aVisitor.visit_terminal(self) end |
#to_s ⇒ Object
Emit a short string representation of the node. Mainly used for diagnosis/debugging purposes.
30 31 32 |
# File 'lib/rley/ptree/terminal_node.rb', line 30 def to_s return super + ": '#{token.lexeme}'" end |
#to_string(indentation) ⇒ Object
Emit a (formatted) string representation of the node. Mainly used for diagnosis/debugging purposes.
24 25 26 |
# File 'lib/rley/ptree/terminal_node.rb', line 24 def to_string(indentation) return super + ": '#{token.lexeme}'" end |