From 26a3fd108d9a74e19f1b68cab42c4d38484e2718 Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Thu, 27 Oct 2022 20:33:48 +0200
Subject: [PATCH] (WIP) Further progress on Unexpected node path length error

---
 gdb-port/top-level-parse.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py
index 790fc58..4e1332e 100644
--- a/gdb-port/top-level-parse.py
+++ b/gdb-port/top-level-parse.py
@@ -93,13 +93,14 @@ class TopLevelParse:
 		if old_stack.depth() > 0:
 			print("Warning: parser stack not empty but parse is successful?")
 
-		top_of_parserstack = self.peek_parserstack()
-		if not top_of_parserstack:
-			self.current_parse_depth = -1 # Parser stack is now empty (i.e. this was the 'topmost' h_parse() invocation
+		print("parser stacks:", self.parser_stacks)
+		print("popping index tree stack")
+		self.input_stream_indices = self.index_tree_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
 		else:
 			self.current_parse_depth = len(self.peek_parserstack().p_stack)-1 # This happens when a h_parse called from a semantic action or HContinuation returns (e. g. filters in pdf)
-			print("popping index tree stack")
-			self.input_stream_indices = self.index_tree_stack.pop()
 
 	# Memoize the parser object for this particular address, then push it on the stack
 	# Returns the parser object we just initalized (or the one already existing)
-- 
GitLab