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

#done!Object

Notify the builder that the construction is over



18
19
# File 'lib/rley/ptree/parse_tree_node.rb', line 18

def done!()
end

#to_sObject

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



34
35
36
# File 'lib/rley/ptree/parse_tree_node.rb', line 34

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.



28
29
30
# File 'lib/rley/ptree/parse_tree_node.rb', line 28

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