Skip to content

Commit 0dbf67d

Browse files
authored
Merge pull request #199 from structuredllm/fix_iter
Fix IterGen issue
2 parents 657e58a + e06d711 commit 0dbf67d

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

syncode/parsers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def create_parser(
2222
cache_filename = parser_cache_dir + f'{grammar}_{parser}_{grammar.hash()}_parser.pkl'
2323
os.makedirs(os.path.dirname(parser_cache_dir), exist_ok=True)
2424

25-
if grammar.name == 'python':
25+
if grammar.name == 'python' and not use_symbol_pos_map:
2626
indenter = PythonIndenter()
2727

2828
base_parser = create_base_parser(grammar, parser, indenter, cache_filename)

syncode/parsers/incremental_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ def get_acceptable_next_terminals(self, partial_code) -> ParseResult:
136136
Returns the set of acceptable terminals at the current partial code position.
137137
"""
138138
# Stores the sequence of tokens that the parser has seen in the order
139-
interactive = self.interactive
140139
lexer_tokens, lexing_incomplete = self._lex_code(partial_code)
141-
self.next_ac_terminals = self._accepts(interactive)
140+
self.next_ac_terminals = self._accepts(self.interactive)
142141

143142
# Restore the previous state of the parser
144143
self._restore_recent_parser_state(lexer_tokens)
144+
interactive = self.interactive
145145

146146
# Parse the tokens
147147
self.time_accepts = 0

syncode/parsers/itergen_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _store_parser_state(
232232
# Store parsed tokens, parser state, terminal sets, indent levels, dedent queue, and symbol pos map
233233
self.cur_pos_to_parser_state[key] = (
234234
copy.deepcopy(self.parsed_lexer_tokens),
235-
parser_state,
235+
parser_state.copy(),
236236
cur_ac_terminals,
237237
next_ac_terminals,
238238
indent_levels,
@@ -338,12 +338,12 @@ def get_acceptable_next_terminals(
338338
Now handles updating the symbol position map during parsing.
339339
"""
340340
# Get lexer tokens and initialize state
341-
interactive = self.interactive
342341
lexer_tokens, lexing_incomplete = self._lex_code(partial_code)
343-
self.next_ac_terminals = self._accepts(interactive)
342+
self.next_ac_terminals = self._accepts(self.interactive)
344343

345344
# Restore the previous state of the parser
346345
self._restore_recent_parser_state(lexer_tokens, symbol_pos_map=symbol_pos_map)
346+
interactive = self.interactive
347347

348348
# Update symbol position map for terminals if provided
349349
if symbol_pos_map is not None:

0 commit comments

Comments
 (0)