Skip to content

Commit

Permalink
SequenceParser optimization - not creating a SequenceParser with only…
Browse files Browse the repository at this point in the history
… one element
  • Loading branch information
noamgat committed Jul 16, 2024
1 parent 390f993 commit 20e0b6d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lmformatenforcer/characterlevelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ def add_character(self, new_character: str) -> CharacterLevelParser:
if new_character in parser.get_allowed_characters():
updated_parser = parser.add_character(new_character)
next_parsers = [updated_parser] + self.parsers[idx+1:]
legal_parsers.append(SequenceParser(next_parsers))
if len(next_parsers) == 1:
legal_parsers.append(next_parsers[0])
else:
legal_parsers.append(SequenceParser(next_parsers))
if not parser.can_end():
break
if len(legal_parsers) == 1:
Expand Down

0 comments on commit 20e0b6d

Please sign in to comment.