Class: Rley::SPPF::TokenNode

Inherits:
LeafNode show all
Defined in:
lib/rley/sppf/token_node.rb

Overview

A SPPF node that matches exactly one token from the input.

Instance Attribute Summary collapse

Attributes inherited from SPPFNode

#range

Instance Method Summary collapse

Methods inherited from LeafNode

#inspect, #key

Methods inherited from SPPFNode

#origin

Constructor Details

#initialize(aToken, aPosition) ⇒ TokenNode

Constructor

Parameters:

  • aToken (Lexical::Token)

    input token represented by this node.

  • aPosition (Integer)

    index of the token in the input stream.



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

#tokenLexical::Token (readonly)

The input token that is represented by this parse node.

Returns:



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.

Parameters:



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.

Parameters:

  • indentation (Integer)

Returns:

  • (String)


27
28
29
# File 'lib/rley/sppf/token_node.rb', line 27

def to_string(indentation)
  return "#{token.terminal.name}#{range.to_string(indentation)}"
end