Class: Rley::RGN::SymbolNode

Inherits:
ASTNode
  • Object
show all
Defined in:
lib/rley/rgn/symbol_node.rb

Overview

A syntax node for a grammar symbol occurring in rhs of a rule. symbol nodes are leaf nodes of RRN parse trees.

Instance Attribute Summary collapse

Attributes inherited from ASTNode

#annotation

Instance Method Summary collapse

Methods inherited from ASTNode

#annotation_to_text, #done!

Constructor Details

#initialize(aPosition, aName) ⇒ SymbolNode

Returns a new instance of SymbolNode.

Parameters:

  • aPosition (Rley::Lexical::Position)

    Position of the entry in the input stream.

  • aName (String)

    name of grammar symbol



18
19
20
21
22
# File 'lib/rley/rgn/symbol_node.rb', line 18

def initialize(aPosition, aName)
  super()
  @position = aPosition
  @name = aName
end

Instance Attribute Details

#nameString (readonly)

Returns name of grammar symbol.

Returns:

  • (String)

    name of grammar symbol



14
15
16
# File 'lib/rley/rgn/symbol_node.rb', line 14

def name
  @name
end

#positionRley::Lexical::Position (readonly)

Returns Position of the entry in the input stream.

Returns:



11
12
13
# File 'lib/rley/rgn/symbol_node.rb', line 11

def position
  @position
end

Instance Method Details

#accept(visitor) ⇒ Object

Abstract method (must be overriden in subclasses). Part of the 'visitee' role in Visitor design pattern.

Parameters:



32
33
34
# File 'lib/rley/rgn/symbol_node.rb', line 32

def accept(visitor)
  visitor.visit_symbol_node(self)
end

#to_textString

Returns name of grammar symbol.

Returns:

  • (String)

    name of grammar symbol



25
26
27
# File 'lib/rley/rgn/symbol_node.rb', line 25

def to_text
  annotation.empty? ? name : "#{name} #{annotation_to_text}"
end