diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py index 4e1332e03de34f359bf995bcc4c1582da565785b..17a0bce342f75a0d5ea2e511a88fe5ab8278d854 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