Class: Dendroid::Parsing::TerminalNode

Inherits:
ParseNode
  • Object
show all
Defined in:
lib/dendroid/parsing/terminal_node.rb

Overview

A parse tree/forest node that is related to one input token.

Instance Attribute Summary collapse

Attributes inherited from ParseNode

#range

Instance Method Summary collapse

Constructor Details

#initialize(sym, tok, rank) ⇒ TerminalNode

Returns a new instance of TerminalNode.



15
16
17
18
19
# File 'lib/dendroid/parsing/terminal_node.rb', line 15

def initialize(sym, tok, rank)
  super(rank, rank + 1)
  @symbol = sym
  @token = tok
end

Instance Attribute Details

#symbolDendroid::Syntax::Terminal (readonly)

Returns Terminal symbol of matching token.

Returns:



10
11
12
# File 'lib/dendroid/parsing/terminal_node.rb', line 10

def symbol
  @symbol
end

#tokenDendroid::Lexical::Token (readonly)

Returns Matching input token object.

Returns:



13
14
15
# File 'lib/dendroid/parsing/terminal_node.rb', line 13

def token
  @token
end

Instance Method Details

#accept(aVisitor) ⇒ Object

Part of the ‘visitee’ role in Visitor design pattern.

Parameters:



23
24
25
# File 'lib/dendroid/parsing/terminal_node.rb', line 23

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

#to_sString

Render a String representation of itself

Returns:

  • (String)


29
30
31
32
# File 'lib/dendroid/parsing/terminal_node.rb', line 29

def to_s
  display_val = token.literal? ? ": #{token.value}" : ''
  "#{symbol.name}#{display_val} #{range_to_s}"
end