Class: Rley::Parser::ParseTreeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/parser/parse_tree_builder.rb

Overview

Builder GoF pattern. Builder pattern builds a complex object (say, a parse tree) from simpler objects (terminal and non-terminal nodes) and using a step by step approach.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theTokens) ⇒ ParseTreeBuilder

Returns a new instance of ParseTreeBuilder.



32
33
34
35
36
# File 'lib/rley/parser/parse_tree_builder.rb', line 32

def initialize(theTokens)
  @tokens = theTokens
  @curr_path = []
  @entry2node = {}
end

Instance Attribute Details

#curr_pathObject (readonly)

Link to current path



23
24
25
# File 'lib/rley/parser/parse_tree_builder.rb', line 23

def curr_path
  @curr_path
end

#entry2nodeObject (readonly)

A hash with pairs of the form: visited parse entry => tree node



29
30
31
# File 'lib/rley/parser/parse_tree_builder.rb', line 29

def entry2node
  @entry2node
end

#last_visiteeObject (readonly)

The last parse entry visited



26
27
28
# File 'lib/rley/parser/parse_tree_builder.rb', line 26

def last_visitee
  @last_visitee
end

#tokensObject (readonly)

The sequence of input tokens



17
18
19
# File 'lib/rley/parser/parse_tree_builder.rb', line 17

def tokens
  @tokens
end

#treeObject (readonly)

Link to tree object



20
21
22
# File 'lib/rley/parser/parse_tree_builder.rb', line 20

def tree
  @tree
end

Instance Method Details

#curr_parentObject

Return the current_parent node



54
55
56
# File 'lib/rley/parser/parse_tree_builder.rb', line 54

def curr_parent()
  return curr_path.last
end

#receive_event(anEvent, anEntry, anIndex) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rley/parser/parse_tree_builder.rb', line 38

def receive_event(anEvent, anEntry, anIndex)
  # puts "Event: #{anEvent} #{anEntry} #{anIndex}"
  if anEntry.dotted_entry?
    process_item_entry(anEvent, anEntry, anIndex)
  elsif anEntry.start_entry?
    process_start_entry(anEvent, anEntry, anIndex)
  elsif anEntry.end_entry?
    process_end_entry(anEvent, anEntry, anIndex)
  else
    raise NotImplementedError
  end

  @last_visitee = anEntry
end