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.



15
16
17
18
19
# File 'lib/rley/sppf/token_node.rb', line 15

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:



10
11
12
# File 'lib/rley/sppf/token_node.rb', line 10

def token
  @token
end

Instance Method Details

#to_string(indentation) ⇒ String

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

Parameters:

  • indentation (Integer)

Returns:

  • (String)


25
26
27
# File 'lib/rley/sppf/token_node.rb', line 25

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