You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keep escapes in verbose (x flag) regexp terminals - #1702
In a regexp terminal with the x (verbose) flag, escapes such as \t, \n, \xHH and \uHHHH are evaluated by eval_escaping before the pattern reaches re. They become literal whitespace, which verbose mode then ignores:
Lark(r"""start: NLNL: /\t|a/x""")
# LexError: Lexer does not allow zero-width terminals. (NL: (?x: |a))
/\x20/x similarly compiles to (?x: ) and can never match a space, and /\x23a/x turns into (?x:#a), where the # now starts a comment.
_literal_to_pattern now asks eval_escaping to keep the backslash of these escapes for regexp terminals that use the x flag, so re interprets them itself (it supports all of them). String literals and regexps without x are unchanged.
Added test_token_flags_verbose_escapes next to the existing verbose tests; it fails without the change for every parser/lexer combination. tests/test_grammar.py, tests/test_lexer.py, tests/test_tools.py and the regexp/flag-related tests in tests/test_parser.py pass.
The failing build (3.8, ubuntu-latest) check isn't caused by this change. The job stops at the actions/setup-python step with The version '3.8' with architecture 'x64' was not found for Ubuntu 26.04. ubuntu-latest now resolves to Ubuntu 26.04, which has no Python 3.8 build, so the tests never ran for that entry.
Since the cause is the python-version: ["3.8", ...] x ubuntu-latest entry in .github/workflows/tests.yml, I've left the workflow alone. It's a separate matter from this PR, for the maintainers to decide (for example dropping 3.8 or pinning that entry to an older runner).
On my side, test_token_flags_verbose_escapes and the other token_flags tests pass locally on Python 3.14 for every parser/lexer combination. The other matrix entries can be used to confirm the change on CI.
yes, it's an out of date version, that needs to be fixed separately.
This branch has not been deployed
No deployments
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
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.
In a regexp terminal with the
x(verbose) flag, escapes such as\t,\n,\xHHand\uHHHHare evaluated byeval_escapingbefore the pattern reachesre. They become literal whitespace, which verbose mode then ignores:/\x20/xsimilarly compiles to(?x: )and can never match a space, and/\x23a/xturns into(?x:#a), where the#now starts a comment._literal_to_patternnow askseval_escapingto keep the backslash of these escapes for regexp terminals that use thexflag, soreinterprets them itself (it supports all of them). String literals and regexps withoutxare unchanged.Added
test_token_flags_verbose_escapesnext to the existing verbose tests; it fails without the change for every parser/lexer combination.tests/test_grammar.py,tests/test_lexer.py,tests/test_tools.pyand the regexp/flag-related tests intests/test_parser.pypass.