Class: Rley::RGN::ASTNode

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

Overview

Abstract class. Instances of its subclasses represent nodes of an abstract syntax tree that is the product of the parse of an input text.

Direct Known Subclasses

CompositeNode, SymbolNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeASTNode

Returns a new instance of ASTNode.



12
13
14
# File 'lib/rley/rgn/ast_node.rb', line 12

def initialize
  @annotation = {}
end

Instance Attribute Details

#annotationHash

Returns:

  • (Hash)


10
11
12
# File 'lib/rley/rgn/ast_node.rb', line 10

def annotation
  @annotation
end

Instance Method Details

#accept(_visitor) ⇒ Object

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

Parameters:

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/rley/rgn/ast_node.rb', line 40

def accept(_visitor)
  raise NotImplementedError
end

#annotation_to_textObject



22
23
24
25
26
27
28
29
30
# File 'lib/rley/rgn/ast_node.rb', line 22

def annotation_to_text
  map_arr = []
  @annotation.each_pair do |key, val|
    literal = val.kind_of?(String) ? "'#{val}'" : val
    map_arr << "#{key}: #{literal}"
  end

  "{ #{map_arr.join(', ')} }"
end

#done!Object

Notification that the parsing has successfully completed



33
34
35
# File 'lib/rley/rgn/ast_node.rb', line 33

def done!
  # Default: do nothing ...
end