From 83da0eeeeff274763515b85c403bd5d1a7205ad8 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 11 Jan 2025 12:10:41 +0100 Subject: [PATCH] [Python] no stray parentheses in regexp patterns (#4133) * [Python] no stray parentheses in regexp patterns This commit scopes stray brackets normally as those may appear in partial patterns. Correct parentheses matching is not always possible and causes valid closing brackets to be scoped illegal. * [Python] Prepend patterns --- Python/Embeddings/RegExp (for Python).sublime-syntax | 8 ++++++++ Python/tests/syntax_test_python_strings.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/Python/Embeddings/RegExp (for Python).sublime-syntax b/Python/Embeddings/RegExp (for Python).sublime-syntax index 52d092f11d..1c03f63a97 100644 --- a/Python/Embeddings/RegExp (for Python).sublime-syntax +++ b/Python/Embeddings/RegExp (for Python).sublime-syntax @@ -56,3 +56,11 @@ contexts: 1: punctuation.definition.capture-group-name.begin.regexp 2: variable.other.backref-and-recursion.regexp 3: punctuation.definition.capture-group-name.end.regexp + + literals: + - meta_prepend: true + # no illegal parentheses in concatenated patterns + - match: \] + scope: punctuation.definition.set.end.regexp + - match: \) + scope: punctuation.section.group.end.regexp diff --git a/Python/tests/syntax_test_python_strings.py b/Python/tests/syntax_test_python_strings.py index eb378885e2..1e37c06eb9 100644 --- a/Python/tests/syntax_test_python_strings.py +++ b/Python/tests/syntax_test_python_strings.py @@ -1300,6 +1300,11 @@ # ^^^^ meta.modifier # ^ storage.modifier.mode +match = re.match(r"([^" + charset + r"]*)", line) +# ^ punctuation.section.group.begin.regexp +# ^ punctuation.definition.set.begin.regexp +# ^ punctuation.definition.set.end.regexp +# ^ punctuation.section.group.end.regexp ############################### # f-strings