From 684205ba2bb172999df35c9d02b4f320709c624c Mon Sep 17 00:00:00 2001 From: pompolic <pompolic@special-circumstanc.es> Date: Thu, 27 Oct 2022 17:15:14 +0200 Subject: [PATCH] (WIP) fix for one cause of "Unexpected node path length" --- gdb-port/top-level-parse.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py index 47d9ecd..790fc58 100644 --- a/gdb-port/top-level-parse.py +++ b/gdb-port/top-level-parse.py @@ -4,6 +4,7 @@ class TopLevelParse: self.parser_objs = {} self.input_stream_indices = IndexTree() # TODO: turn this into a tree self.input_index_tree_path = [0] + self.index_tree_stack = [] self.current_parse_depth = 0 # Used by the AST handling code. self.starting_input_index = [] self.input_token_map = {} @@ -42,6 +43,8 @@ class TopLevelParse: parser_stack = ParserStack(None, None) self.parser_stacks.append(parser_stack) 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) return 0 # TODO: arena parameter is useless @@ -95,6 +98,8 @@ class TopLevelParse: self.current_parse_depth = -1 # Parser stack is now empty (i.e. this was the 'topmost' h_parse() invocation 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) @@ -173,6 +178,10 @@ class TopLevelParse: self.input_index_tree_path.append(0) else: #print("len(self.input_index_tree_path):", len(self.input_index_tree_path), "self.current_parse_depth:", self.current_parse_depth) + #gdb.execute("tbreak") + print("parse depth + 1:", self.current_parse_depth+1, "tree path length:", len(self.input_index_tree_path)) + print("Unexpected node path length at parser:", str(self.peek_parser())) + print("index tree stack", self.index_tree_stack) raise RuntimeError("Unexpected node path length") diff = (self.current_parse_depth+1) - len(self.starting_input_index) -- GitLab