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



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.



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

def token
  @token
end

Instance Method Details

#accept(aVisitor) ⇒ Object

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



31
32
33
# File 'lib/rley/sppf/token_node.rb', line 31

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.



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