Skip to content

Commit

Permalink
[Python] no stray parentheses in regexp patterns (#4133)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
deathaxe authored Jan 11, 2025
1 parent 553c203 commit 83da0ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Python/Embeddings/RegExp (for Python).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions Python/tests/syntax_test_python_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83da0ee

Please sign in to comment.