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.



14
15
16
17
# File 'lib/rley/ptree/parse_tree_node.rb', line 14

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.



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

def range
  @range
end

#symbolObject (readonly)

Link to the grammar symbol



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

def symbol
  @symbol
end

Instance Method Details

#done!Object

Notify the builder that the construction is over



20
21
22
# File 'lib/rley/ptree/parse_tree_node.rb', line 20

def done!
  # Do nothing
end

#to_sObject

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



37
38
39
# File 'lib/rley/ptree/parse_tree_node.rb', line 37

def to_s
  "#{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.



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

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