Class: Rley::SPPF::TokenNode

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

Overview

A node in a parse forest that matches exactly one token from the input

Instance Attribute Summary collapse

Attributes inherited from SPPFNode

#range

Instance Method Summary collapse

Methods inherited from SPPFNode

#origin

Constructor Details

#initialize(aToken, aPosition) ⇒ TokenNode

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



11
12
13
14
15
# File 'lib/rley/sppf/token_node.rb', line 11

def initialize(aToken, aPosition)
  range = { low: aPosition, high: aPosition + 1 }
  super(range)
  @token = aToken
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/rley/sppf/token_node.rb', line 8

def token
  @token
end

Instance Method Details

#keyObject



23
24
25
# File 'lib/rley/sppf/token_node.rb', line 23

def key()
  @key ||= to_string(0)
end

#to_string(indentation) ⇒ Object

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



19
20
21
# File 'lib/rley/sppf/token_node.rb', line 19

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