Class: Rley::PTree::ParseTreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/ptree/parse_tree_node.rb

Direct Known Subclasses

NonTerminalNode, TerminalNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aSymbol, aRange) ⇒ ParseTreeNode

Returns a new instance of ParseTreeNode.



12
13
14
15
# File 'lib/rley/ptree/parse_tree_node.rb', line 12

def initialize(aSymbol, aRange)
  @symbol = aSymbol
  @range = Lexical::TokenRange.new(aRange)
end

Instance Attribute Details

#rangeObject

A range of indices for tokens corresponding to the node.



10
11
12
# File 'lib/rley/ptree/parse_tree_node.rb', line 10

def range
  @range
end

#symbolObject (readonly)

Link to the grammar symbol



7
8
9
# File 'lib/rley/ptree/parse_tree_node.rb', line 7

def symbol
  @symbol
end

Instance Method Details

#to_sObject

Emit a short string representation of the node. Mainly used for diagnosis/debugging purposes.



30
31
32
# File 'lib/rley/ptree/parse_tree_node.rb', line 30

def to_s()
  return "#{symbol.name}#{range.to_string(0)}"
end

#to_string(indentation) ⇒ Object

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



24
25
26
# File 'lib/rley/ptree/parse_tree_node.rb', line 24

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