From e698b23628dccdb5c80a312a908c5c4adba9f56c Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Fri, 28 Oct 2022 16:34:23 +0200
Subject: [PATCH] (WIP) Further fixes on Unexpected node path length error

This version runs very slow
---
 gdb-port/top-level-parse.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py
index 4e1332e..17a0bce 100644
--- a/gdb-port/top-level-parse.py
+++ b/gdb-port/top-level-parse.py
@@ -2,8 +2,9 @@ class TopLevelParse:
 	def __init__(self):
 		self.parser_stacks = []
 		self.parser_objs = {}
-		self.input_stream_indices = IndexTree() # TODO: turn this into a tree
+		self.input_stream_indices = IndexTree()
 		self.input_index_tree_path = [0]
+		self.input_index_tree_path_stack = [] # TODO: put index_tree_path code in IndexTree()
 		self.index_tree_stack = []
 		self.current_parse_depth = 0 # Used by the AST handling code.
 		self.starting_input_index = []
@@ -45,6 +46,9 @@ class TopLevelParse:
 		self.current_parse_depth = -1 # entering h_do_parse increments this by 1. To have it 0-indexed, it needs to be initialized to -1
 		if self.input_stream_indices:
 			self.index_tree_stack.append(self.input_stream_indices)
+			self.input_stream_indices = IndexTree()
+			self.input_index_tree_path_stack.append(self.input_index_tree_path)
+			self.input_index_tree_path = [0]
 		return 0
 
 	# TODO: arena parameter is useless
@@ -96,6 +100,7 @@ class TopLevelParse:
 		print("parser stacks:", self.parser_stacks)
 		print("popping index tree stack")
 		self.input_stream_indices = self.index_tree_stack.pop()
+		self.input_index_tree_path = self.input_index_tree_path_stack.pop()
 
 		if not self.parser_stacks: # if self.parser_stacks is now empty, we've returned from h_packrat_parse() called by the "outermost" h_parse()
 			self.current_parse_depth = -1 # Restore parse depth
-- 
GitLab