From e06d7110ab21d6d52b04d35e38faaded8ceae4c4 Mon Sep 17 00:00:00 2001 From: Shubham Ugare Date: Mon, 5 May 2025 16:42:59 -0500 Subject: [PATCH] Fix IterGen issue --- syncode/parsers/__init__.py | 2 +- syncode/parsers/incremental_parser.py | 4 ++-- syncode/parsers/itergen_parser.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/syncode/parsers/__init__.py b/syncode/parsers/__init__.py index 741f8878..f0c36cca 100644 --- a/syncode/parsers/__init__.py +++ b/syncode/parsers/__init__.py @@ -22,7 +22,7 @@ def create_parser( cache_filename = parser_cache_dir + f'{grammar}_{parser}_{grammar.hash()}_parser.pkl' os.makedirs(os.path.dirname(parser_cache_dir), exist_ok=True) - if grammar.name == 'python': + if grammar.name == 'python' and not use_symbol_pos_map: indenter = PythonIndenter() base_parser = create_base_parser(grammar, parser, indenter, cache_filename) diff --git a/syncode/parsers/incremental_parser.py b/syncode/parsers/incremental_parser.py index 224d064c..57d238a0 100644 --- a/syncode/parsers/incremental_parser.py +++ b/syncode/parsers/incremental_parser.py @@ -136,12 +136,12 @@ def get_acceptable_next_terminals(self, partial_code) -> ParseResult: Returns the set of acceptable terminals at the current partial code position. """ # Stores the sequence of tokens that the parser has seen in the order - interactive = self.interactive lexer_tokens, lexing_incomplete = self._lex_code(partial_code) - self.next_ac_terminals = self._accepts(interactive) + self.next_ac_terminals = self._accepts(self.interactive) # Restore the previous state of the parser self._restore_recent_parser_state(lexer_tokens) + interactive = self.interactive # Parse the tokens self.time_accepts = 0 diff --git a/syncode/parsers/itergen_parser.py b/syncode/parsers/itergen_parser.py index 3350c524..3b8ee2b0 100644 --- a/syncode/parsers/itergen_parser.py +++ b/syncode/parsers/itergen_parser.py @@ -230,7 +230,7 @@ def _store_parser_state( # Store parsed tokens, parser state, terminal sets, indent levels, dedent queue, and symbol pos map self.cur_pos_to_parser_state[key] = ( copy.deepcopy(self.parsed_lexer_tokens), - parser_state, + parser_state.copy(), cur_ac_terminals, next_ac_terminals, indent_levels, @@ -336,12 +336,12 @@ def get_acceptable_next_terminals( Now handles updating the symbol position map during parsing. """ # Get lexer tokens and initialize state - interactive = self.interactive lexer_tokens, lexing_incomplete = self._lex_code(partial_code) - self.next_ac_terminals = self._accepts(interactive) + self.next_ac_terminals = self._accepts(self.interactive) # Restore the previous state of the parser self._restore_recent_parser_state(lexer_tokens, symbol_pos_map=symbol_pos_map) + interactive = self.interactive # Update symbol position map for terminals if provided if symbol_pos_map is not None: