Skip to content

Commit d26a1c5

Browse files
committed
BUGFIX: Regression in lexer-only mode (parser=None)
1 parent 20f57b9 commit d26a1c5

File tree

3 files changed

+10
-88
lines changed

3 files changed

+10
-88
lines changed

examples/advanced/python_bytecode.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

lark/lark.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ def __init__(self, grammar, **options):
340340
if self.options.ambiguity not in _VALID_AMBIGUITY_OPTIONS:
341341
raise ConfigurationError("invalid ambiguity option: %r. Must be one of %r" % (self.options.ambiguity, _VALID_AMBIGUITY_OPTIONS))
342342

343-
if self.options.postlex is not None:
343+
if self.options.parser is None:
344+
terminals_to_keep = '*'
345+
elif self.options.postlex is not None:
344346
terminals_to_keep = set(self.options.postlex.always_accept)
345347
else:
346348
terminals_to_keep = set()

lark/load_grammar.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,12 +782,13 @@ def compile(self, start, terminals_to_keep):
782782
break
783783

784784
# Filter out unused terminals
785-
used_terms = {t.name for r in compiled_rules
786-
for t in r.expansion
787-
if isinstance(t, Terminal)}
788-
terminals, unused = classify_bool(terminals, lambda t: t.name in used_terms or t.name in self.ignore or t.name in terminals_to_keep)
789-
if unused:
790-
logger.debug("Unused terminals: %s", [t.name for t in unused])
785+
if terminals_to_keep != '*':
786+
used_terms = {t.name for r in compiled_rules
787+
for t in r.expansion
788+
if isinstance(t, Terminal)}
789+
terminals, unused = classify_bool(terminals, lambda t: t.name in used_terms or t.name in self.ignore or t.name in terminals_to_keep)
790+
if unused:
791+
logger.debug("Unused terminals: %s", [t.name for t in unused])
791792

792793
return terminals, compiled_rules, self.ignore
793794

0 commit comments

Comments
 (0)