Repository navigation
Conversation
Update the allowed regex flags in the grammar parser and documentation to include the ASCII (a) and locale (L) flags supported by Python's re module since 3.7. Fixes lark-parser#1527
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for the ASCII (
a) and locale (L) regular expression flags in Lark grammars.Problem
Lark previously allowed only the flags
imslux. Python'sremodule has supported local(?a:...)and(?L:...)flags since 3.7 (see #1527).Implementation
_RE_FLAGSinlark/load_grammar.pyfromimsluxtoaLimsux.docs/grammar.mdto document the new flags.Flags continue to be applied via inline groups (
(?f:...)) inPattern._get_flags(), which is the correct mechanism for local flags.Note on the
LflagPython only allows the
L(LOCALE) flag on bytes patterns. Lark currently validates regexps asstrfirst, so/.../Lraises a clear error at grammar construction time for normal (str) grammars. Full bytes-mode support forLwould need additional validation changes and is left for a follow-up if desired. Prefer Unicode matching (the default) or theaflag for ASCII-only matching.Tests
Verified locally:
aflag restricts\wto ASCII (rejects non-ASCII word characters such asé).test_token_flags,test_token_flags_verbose,test_join_regex_flags, etc.) continue to pass on LALR and Earley./.../Lraises as expected on str grammars.Related
Fixes #1527.