Skip to content

Commit

Permalink
[Python] no stray parentheses in regexp patterns
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deathaxe committed Jan 8, 2025
1 parent f615fed commit 4811601
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 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,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
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 4811601

Please sign in to comment.