From 48116017b847f2e00c526587dd714a4419fbe0a5 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 8 Jan 2025 21:12:16 +0100 Subject: [PATCH 1/2] [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/Embeddings/RegExp (for Python).sublime-syntax | 11 +++++++++++ Python/tests/syntax_test_python_strings.py | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/Python/Embeddings/RegExp (for Python).sublime-syntax b/Python/Embeddings/RegExp (for Python).sublime-syntax index 52d092f11d..774da9cdfc 100644 --- a/Python/Embeddings/RegExp (for Python).sublime-syntax +++ b/Python/Embeddings/RegExp (for Python).sublime-syntax @@ -56,3 +56,14 @@ 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: + - include: quantifiers + # https://github.com/sublimehq/Packages/issues/314 + - match: \. + scope: keyword.other.any.regexp + # 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 From 0d9a5ece00778f52ffab93b9286f9e1cd75f9cc2 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 9 Jan 2025 19:01:01 +0100 Subject: [PATCH 2/2] [Python] Prepend patterns --- Python/Embeddings/RegExp (for Python).sublime-syntax | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Python/Embeddings/RegExp (for Python).sublime-syntax b/Python/Embeddings/RegExp (for Python).sublime-syntax index 774da9cdfc..1c03f63a97 100644 --- a/Python/Embeddings/RegExp (for Python).sublime-syntax +++ b/Python/Embeddings/RegExp (for Python).sublime-syntax @@ -58,10 +58,7 @@ contexts: 3: punctuation.definition.capture-group-name.end.regexp literals: - - include: quantifiers - # https://github.com/sublimehq/Packages/issues/314 - - match: \. - scope: keyword.other.any.regexp + - meta_prepend: true # no illegal parentheses in concatenated patterns - match: \] scope: punctuation.definition.set.end.regexp