lib/rley/parser/parse_forest_builder.rb in rley-0.4.06 vs lib/rley/parser/parse_forest_builder.rb in rley-0.4.07
- old
+ new
@@ -80,16 +80,11 @@
@forest = create_forest(curr_parent) unless @last_visitee
when :backtrack
# Restore path
@curr_path = entry2path_to_alt[anEntry].dup
- # puts "Restore path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
- antecedent_index = curr_parent.subnodes.size
- # puts "Current parent #{curr_parent.to_string(0)}"
- # puts "Antecedent index #{antecedent_index}"
-
when :revisit
# Retrieve the already existing node corresponding
# to re-visited entry
popular = @entry2node[anEntry]
@@ -100,11 +95,10 @@
else
raise NotImplementedError
end
end
-
def process_item_entry(anEvent, anEntry, anIndex)
case anEvent
when :visit
if anEntry.exit_entry?
# Previous entry was an end entry (X. pattern)
@@ -148,18 +142,13 @@
end
when :backtrack
# Restore path
@curr_path = entry2path_to_alt[anEntry].dup
- # puts "Special restore path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
- antecedent_index = curr_parent.subnodes.size
- # puts "Current parent #{curr_parent.to_string(0)}"
- # puts "Antecedent index #{antecedent_index}"
-
create_alternative_node(anEntry)
- when :revisit
+ when :revisit
# Retrieve the grammar symbol before the dot (if any)
prev_symbol = anEntry.prev_symbol
case prev_symbol
when Syntax::Terminal
# Add node without changing current path
@@ -179,11 +168,10 @@
# Create an empty parse forest
def create_forest(aRootNode)
return Rley::SPPF::ParseForest.new(aRootNode)
end
-
# Factory method. Build and return an SPPF non-terminal node.
def create_non_terminal_node(anEntry, aRange, nonTSymb = nil)
non_terminal = nonTSymb.nil? ? anEntry.vertex.non_terminal : nonTSymb
new_node = Rley::SPPF::NonTerminalNode.new(non_terminal, aRange)
entry2node[anEntry] = new_node
@@ -191,11 +179,10 @@
# puts "FOREST ADD #{curr_parent.key if curr_parent}/#{new_node.key}"
return new_node
end
-
# Add an alternative node to the forest
def create_alternative_node(anEntry)
vertex = anEntry.vertex
range = curr_parent.range
alternative = Rley::SPPF::AlternativeNode.new(vertex, range)
@@ -218,11 +205,10 @@
entry2node[anEntry] = candidate
return candidate
end
-
def create_epsilon_node(anEntry, anIndex)
new_node = SPPF::EpsilonNode.new(anIndex)
candidate = add_node_to_forest(new_node)
entry2node[anEntry] = candidate
@@ -230,21 +216,20 @@
end
# Add the given node if not yet present in parse forest
def add_node_to_forest(aNode)
key_node = aNode.key
- if forest.include?(key_node)
- new_node = forest.key2node[key_node]
- else
- new_node = aNode
- forest.key2node[key_node] = new_node
- # puts "FOREST ADD #{key_node}"
- end
+ if forest.include?(key_node)
+ new_node = forest.key2node[key_node]
+ else
+ new_node = aNode
+ forest.key2node[key_node] = new_node
+ # puts "FOREST ADD #{key_node}"
+ end
add_subnode(new_node, false)
return new_node
end
-
# Add the given node as sub-node of current parent node
# Optionally add the node to the current path
def add_subnode(aNode, addToPath = true)
curr_parent.add_subnode(aNode) unless curr_path.empty?