Skip to content

feat: add support for 'a' (ASCII) and 'L' (LOCALE) regex flags - #1655

Closed
amansri-30 wants to merge 1 commit into
lark-parser:masterfrom
amansri-30:add-regex-flags-a-L
Closed

amansri-30 wants to merge 1 commit into
lark-parser:masterfrom
amansri-30:add-regex-flags-a-L

Conversation

@amansri-30

Copy link
Copy Markdown

Summary

Adds support for the a (ASCII) and L (LOCALE) regex flags in Lark grammars, as requested in issue #1527.

Changes

  • Updated _RE_FLAGS in load_grammar.py to include a and L
  • Added test_flag_order_with_new_flags to verify the a flag works and is sorted deterministically
  • Added test_token_flags_ascii to verify the a flag parses correctly

Details

  • a flag (ASCII): Makes \w, \W, \b, \B, \d, \D, \s, \S perform ASCII-only matching instead of full Unicode matching. Works with both string and bytes patterns.
  • L flag (LOCALE): Makes \w, \W, \b, \B locale dependent. Note: In Python 3, this flag can only be used with bytes patterns (when use_bytes=True).

Testing

All existing tests pass, and new tests verify the flags work correctly:

pytest tests/test_lexer.py tests/test_parser.py

Closes #1527

Adds support for the 'a' and 'L' regex flags in Lark grammars, as requested
in issue lark-parser#1527.

- 'a' flag: Makes \w, \W, \b, \B, \d, \D, \s, \S perform ASCII-only
  matching instead of full Unicode matching
- 'L' flag: Makes \w, \W, \b, \B locale dependent (only works with
  bytes patterns in Python 3)

Changes:
- Updated _RE_FLAGS in load_grammar.py to include 'a' and 'L'
- Added test_flag_order_with_new_flags to verify 'a' flag works
- Added test_token_flags_ascii to verify 'a' flag parses correctly
@erezsh

erezsh commented Sep 18, 2026

Copy link
Copy Markdown
Member

low effort

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.

Add support for the a and L regex flags

2 participants