Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Fix escaped quotes in raw strings #3861

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Python/Python.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,7 @@ contexts:
double-quoted-raw-docstring-body:
- meta_content_scope: comment.block.documentation.python
- include: double-quoted-docstring-end
- include: escaped-raw-quotes

single-quoted-docstrings:
- match: ^\s*(?i)(u)?(''')
Expand Down Expand Up @@ -2612,6 +2613,7 @@ contexts:
single-quoted-raw-docstring-body:
- meta_content_scope: comment.block.documentation.python
- include: single-quoted-docstring-end
- include: escaped-raw-quotes

###[ STRINGS ]################################################################

Expand Down Expand Up @@ -2660,6 +2662,7 @@ contexts:

triple-double-quoted-plain-raw-b-string-content:
- include: string-prototype
- include: escaped-raw-quotes

triple-double-quoted-raw-b-strings:
# Triple-quoted raw string, bytes, will use regex
Expand Down Expand Up @@ -2698,6 +2701,7 @@ contexts:

triple-double-quoted-plain-raw-f-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: triple-double-quoted-f-string-replacements

triple-double-quoted-raw-f-strings:
Expand Down Expand Up @@ -2738,6 +2742,7 @@ contexts:

triple-double-quoted-plain-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: escaped-unicode-chars

triple-double-quoted-raw-u-strings:
Expand Down Expand Up @@ -2786,6 +2791,7 @@ contexts:

triple-double-quoted-sql-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: escaped-unicode-chars
- include: string-placeholders
- include: triple-double-quoted-string-replacements
Expand Down Expand Up @@ -3001,6 +3007,7 @@ contexts:

double-quoted-plain-raw-b-string-content:
- include: string-prototype
- include: escaped-raw-quotes

double-quoted-raw-b-strings:
# Single-line raw string, bytes, treated as regex
Expand Down Expand Up @@ -3039,6 +3046,7 @@ contexts:

double-quoted-plain-raw-f-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: double-quoted-f-string-replacements

double-quoted-raw-f-strings:
Expand Down Expand Up @@ -3079,6 +3087,7 @@ contexts:

double-quoted-plain-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes

double-quoted-raw-u-strings:
- match: ([uU]?r)(")
Expand Down Expand Up @@ -3126,6 +3135,7 @@ contexts:

double-quoted-sql-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: string-placeholders
- include: double-quoted-string-replacements

Expand Down Expand Up @@ -3333,6 +3343,7 @@ contexts:

triple-single-quoted-plain-raw-b-string-content:
- include: string-prototype
- include: escaped-raw-quotes

triple-single-quoted-raw-b-strings:
# Triple-quoted raw string, bytes, will use regex
Expand Down Expand Up @@ -3371,6 +3382,7 @@ contexts:

triple-single-quoted-plain-raw-f-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: triple-single-quoted-f-string-replacements

triple-single-quoted-raw-f-strings:
Expand Down Expand Up @@ -3411,6 +3423,7 @@ contexts:

triple-single-quoted-plain-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes

triple-single-quoted-raw-u-strings:
# Triple-quoted raw string, unicode or not, will detect SQL, otherwise regex
Expand Down Expand Up @@ -3458,6 +3471,7 @@ contexts:

triple-single-quoted-sql-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: escaped-unicode-chars
- include: string-placeholders
- include: triple-single-quoted-string-replacements
Expand Down Expand Up @@ -3673,6 +3687,7 @@ contexts:

single-quoted-plain-raw-b-string-content:
- include: string-prototype
- include: escaped-raw-quotes

single-quoted-raw-b-strings:
# Single-line raw string, bytes, treated as regex
Expand Down Expand Up @@ -3711,6 +3726,7 @@ contexts:

single-quoted-plain-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes

single-quoted-raw-u-strings:
- match: ([uU]?r)(')
Expand Down Expand Up @@ -3758,6 +3774,7 @@ contexts:

single-quoted-sql-raw-u-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: string-placeholders
- include: single-quoted-string-replacements

Expand All @@ -3777,6 +3794,7 @@ contexts:

single-quoted-plain-raw-f-string-content:
- include: string-prototype
- include: escaped-raw-quotes
- include: single-quoted-f-string-replacements

single-quoted-raw-f-strings:
Expand Down Expand Up @@ -3995,6 +4013,11 @@ contexts:
- match: \\N\{[-a-zA-Z ]+\}
scope: constant.character.escape.unicode.name.python

escaped-raw-quotes:
# consume escaped quotes in raw-strings to preven them terminating strings
- match: \\['"]
scope: constant.character.escape.python

escaped-string-braces:
- match: \{\{|\}\}
scope: constant.character.escape.python
Expand Down
14 changes: 8 additions & 6 deletions Python/tests/syntax_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"""
# <- comment.block.documentation.python punctuation.definition.comment.end.python

ur"""Raw docstring \"""
ur"""Raw docstring \""""
# <- storage.type.string.python - comment
# ^^^ comment.block.documentation.python punctuation.definition.comment.begin.python
# ^^^^^^^^^^^^^^^ comment.block.documentation.summary.python
# ^^^ comment.block.documentation.python punctuation.definition.comment.end.python
# ^^^^^^^^^^^^^^^^ comment.block.documentation.summary.python
# ^^ constant.character.escape.python
# ^^^ comment.block.documentation.python punctuation.definition.comment.end.python

R"""
C:\Users
Expand Down Expand Up @@ -87,11 +88,12 @@
'''
# <- comment.block.documentation.python punctuation.definition.comment.end.python

ur'''Raw docstring \'''
ur'''Raw docstring \''''
# <- storage.type.string.python - comment
# ^^^ comment.block.documentation.python punctuation.definition.comment.begin.python
# ^^^^^^^^^^^^^^^ comment.block.documentation.summary.python
# ^^^ comment.block.documentation.python punctuation.definition.comment.end.python
# ^^^^^^^^^^^^^^^^ comment.block.documentation.summary.python
# ^^ constant.character.escape.python
# ^^^ comment.block.documentation.python punctuation.definition.comment.end.python

R'''
C:\Users
Expand Down
Loading