Class: Rley::PTree::TerminalNode

Inherits:
ParseTreeNode show all
Defined in:
lib/rley/ptree/terminal_node.rb

Instance Attribute Summary collapse

Attributes inherited from ParseTreeNode

#range, #symbol

Instance Method Summary collapse

Constructor Details

#initialize(aToken, aPos) ⇒ TerminalNode

aPosition is the position of the token in the input stream.



10
11
12
13
14
# File 'lib/rley/ptree/terminal_node.rb', line 10

def initialize(aToken, aPos)
  range = aPos.kind_of?(Fixnum) ? { low: aPos, high: aPos + 1 } : aPos
  super(aToken.terminal, range)
  @token = aToken
end

Instance Attribute Details

#tokenObject (readonly)

Link to the input token



7
8
9
# File 'lib/rley/ptree/terminal_node.rb', line 7

def token
  @token
end

Instance Method Details

#accept(aVisitor) ⇒ Object

Part of the 'visitee' role in Visitor design pattern.

Parameters:



30
31
32
# File 'lib/rley/ptree/terminal_node.rb', line 30

def accept(aVisitor)
  aVisitor.visit_terminal(self)
end

#to_sObject

Emit a short 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_s()
  return super + ": '#{token.lexeme}'"
end

#to_string(indentation) ⇒ Object

Emit a (formatted) string representation of the node. Mainly used for diagnosis/debugging purposes.



18
19
20
# File 'lib/rley/ptree/terminal_node.rb', line 18

def to_string(indentation)
  return super + ": '#{token.lexeme}'"
end