Skip to content

Commit

Permalink
[Python] Drop inadequate escape scopes
Browse files Browse the repository at this point in the history
This commit drops scoping `\\`, `\"` or `\'` with `constant.character.escape`
in raw strings as those tokens are treated literal - printed as is.

They remain scoped escapes in regexp strings though as scoping of embedded
syntax applies.
  • Loading branch information
deathaxe committed Apr 7, 2024
1 parent 83ea918 commit e44faa4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Python/Python.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -4051,8 +4051,8 @@ contexts:

escaped-raw-quotes:
# consume escaped quotes in raw-strings to preven them terminating strings
# but don't scope them as escapes as they are treated literal
- match: \\[\\'"]
scope: constant.character.escape.python

escaped-string-braces:
- match: \{\{|\}\}
Expand Down
4 changes: 2 additions & 2 deletions Python/tests/syntax_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# <- storage.type.string.python - comment
# ^^^ comment.block.documentation.python punctuation.definition.comment.begin.python
# ^^^^^^^^^^^^^^^^ comment.block.documentation.summary.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ comment.block.documentation.python punctuation.definition.comment.end.python

R"""
Expand Down Expand Up @@ -92,7 +92,7 @@
# <- storage.type.string.python - comment
# ^^^ comment.block.documentation.python punctuation.definition.comment.begin.python
# ^^^^^^^^^^^^^^^^ comment.block.documentation.summary.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ comment.block.documentation.python punctuation.definition.comment.end.python

R'''
Expand Down
88 changes: 44 additions & 44 deletions Python/tests/syntax_test_python_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,35 +278,35 @@

r'''\''''
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

r"""\""""
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

R'''\''''
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

R"""\""""
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

r'''\\'''
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

r"""\\"""
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

R'''\\'''
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

R"""\\"""
#^^^^^^^^ comment.block.documentation
# ^^ constant.character.escape.python
# ^^ - constant.character.escape

raw = r'foo\'' + r'foo\"' + r'foo\\'
# ^^^^^^^ meta.string.python string.quoted.single.python
Expand Down Expand Up @@ -391,85 +391,85 @@
raw = R'foo\'' + R'foo\"' + R'foo\\'
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python

raw = R"foo\"" + R"foo\'" + R"foo\\"
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python

raw = RB'foo\'' + RB'foo\"' + RB'foo\\'
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python

raw = RB"foo\"" + RB"foo\'" + RB"foo\\"
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python

raw = RF'foo\'' + RF'foo\"' + RF'foo\\'
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.single.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python

raw = RF"foo\"" + RF"foo\'" + RF"foo\\"
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python
# ^^^^^^^ meta.string.python string.quoted.double.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^ punctuation.definition.string.end.python

raw = r'''foo\'''' + r'''foo\"''' + r'''foo\\'''
Expand Down Expand Up @@ -559,85 +559,85 @@
raw = R'''foo\'''' + R'''foo\"''' + R'''foo\\'''
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python

raw = R"""foo\"""" + R"""foo\'""" + R"""foo\\"""
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python

raw = RB'''foo\'''' + RB'''foo\"''' + RB'''foo\\'''
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python

raw = RB"""foo\"""" + RB"""foo\'""" + RB"""foo\\"""
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python

raw = RF'''foo\'''' + RF'''foo\"''' + RF'''foo\\'''
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.single.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python

raw = RF"""foo\"""" + RF"""foo\'""" + RF"""foo\\"""
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python
# ^^^^^^^^^^^ meta.string.python string.quoted.double.block.python
# ^^^ punctuation.definition.string.begin.python
# ^^ constant.character.escape.python
# ^^ - constant.character.escape
# ^^^ punctuation.definition.string.end.python

###################################################
Expand Down

0 comments on commit e44faa4

Please sign in to comment.