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

Returns a new instance of TerminalNode.

Parameters:

  • aToken (Lexical::Token)

    Input Token object

  • aPos (Integer)

    position of the token in the input stream.



11
12
13
14
15
16
17
18
# File 'lib/rley/ptree/terminal_node.rb', line 11

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

#tokenLexical::Token (readonly)

Returns the input token.

Returns:



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:



34
35
36
# File 'lib/rley/ptree/terminal_node.rb', line 34

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

#to_sObject

Emit a short string representation of the node. Mainly used for diagnosis/debugging purposes.



28
29
30
# File 'lib/rley/ptree/terminal_node.rb', line 28

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.



22
23
24
# File 'lib/rley/ptree/terminal_node.rb', line 22

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