Skip to content

fix: support zero-width regex terminals in non-empty contexts (#1640) - #1695

Open
vnanduri326 wants to merge 1 commit into
lark-parser:masterfrom
vnanduri326:fix-zero-width-terminals
Open

vnanduri326 wants to merge 1 commit into
lark-parser:masterfrom
vnanduri326:fix-zero-width-terminals

Conversation

@vnanduri326

Copy link
Copy Markdown

This PR fixes issue #1640.

Previously, Lark strictly rejected any terminal whose regular expression could match the empty string at initialization time (LexError or GrammarError), even when safely embedded within a larger rule guaranteed to consume characters.

  • lark/lexer.py: Relaxed the strict min_width == 0 check in BasicLexer to permit nullable/zero-width terminals when part of a valid non-zero-width rule context.
  • lark/parser_frontends.py: Removed the restrictive GrammarError check for zero-width regexps under dynamic Earley.
  • lark/parsers/xearley.py: Updated scan_zero_width and complete lexing behavior to correctly process shorter prefixes and zero-length token alternatives (such as /a*/) under dynamic_complete lexing.
  • tests/test_zero_width.py: Added comprehensive regression tests covering zero-width terminals in non-empty rules and dynamic complete empty-alternative parsing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant