diff --git a/Python/Python.sublime-syntax b/Python/Python.sublime-syntax index d05c8f5901..156ffd0a31 100644 --- a/Python/Python.sublime-syntax +++ b/Python/Python.sublime-syntax @@ -2826,11 +2826,35 @@ contexts: push: triple-double-quoted-f-string-body triple-double-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-f-string-syntax + + triple-double-quoted-f-string-syntax: + # Single-line string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: triple-double-quoted-sql-f-string-body + # Single-line string, unicode or not + - match: (?=\S) + set: triple-double-quoted-plain-f-string-body + + triple-double-quoted-plain-f-string-body: - meta_include_prototype: false - meta_content_scope: meta.string.python string.quoted.double.block.python - include: triple-double-quoted-string-end - include: triple-double-quoted-f-string-content + triple-double-quoted-sql-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: triple-double-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: triple-double-quoted-string-pop + - include: triple-double-quoted-f-string-content + triple-double-quoted-f-string-content: - include: string-prototype - include: string-continuations @@ -3168,11 +3192,35 @@ contexts: push: double-quoted-f-string-body double-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python + - include: double-quoted-string-end + - include: double-quoted-f-string-syntax + + double-quoted-f-string-syntax: + # Single-line string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: double-quoted-sql-f-string-body + # Single-line string, unicode or not + - match: (?=\S) + set: double-quoted-plain-f-string-body + + double-quoted-plain-f-string-body: - meta_include_prototype: false - meta_content_scope: meta.string.python string.quoted.double.python - include: double-quoted-string-end - include: double-quoted-f-string-content + double-quoted-sql-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: double-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: double-quoted-string-pop + - include: double-quoted-f-string-content + double-quoted-f-string-content: - include: string-prototype - include: double-quoted-f-string-replacements @@ -3506,11 +3554,35 @@ contexts: push: triple-single-quoted-f-string-body triple-single-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-f-string-syntax + + triple-single-quoted-f-string-syntax: + # Single-line string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: triple-single-quoted-sql-f-string-body + # Single-line string, unicode or not + - match: (?=\S) + set: triple-single-quoted-plain-f-string-body + + triple-single-quoted-plain-f-string-body: - meta_include_prototype: false - meta_content_scope: meta.string.python string.quoted.single.block.python - include: triple-single-quoted-string-end - include: triple-single-quoted-f-string-content + triple-single-quoted-sql-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: triple-single-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: triple-single-quoted-string-pop + - include: triple-single-quoted-f-string-content + triple-single-quoted-f-string-content: - include: string-prototype - include: string-continuations @@ -3848,11 +3920,35 @@ contexts: push: single-quoted-f-string-body single-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-f-string-syntax + + single-quoted-f-string-syntax: + # Single-line string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: single-quoted-sql-f-string-body + # Single-line string, unicode or not + - match: (?=\S) + set: single-quoted-plain-f-string-body + + single-quoted-plain-f-string-body: - meta_include_prototype: false - meta_content_scope: meta.string.python string.quoted.single.python - include: single-quoted-string-end - include: single-quoted-f-string-content + single-quoted-sql-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: single-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: single-quoted-string-pop + - include: single-quoted-f-string-content + single-quoted-f-string-content: - include: string-prototype - include: single-quoted-f-string-replacements diff --git a/Python/tests/syntax_test_python_strings.py b/Python/tests/syntax_test_python_strings.py index a07d2f2fc6..a2a3408add 100644 --- a/Python/tests/syntax_test_python_strings.py +++ b/Python/tests/syntax_test_python_strings.py @@ -1192,6 +1192,34 @@ # ^^^^^^^^^^^ meta.interpolation.python meta.interpolation.python # ^^^ - meta.interpolation.python meta.interpolation.python +f"""SELECT * FROM {table!s:r}""" +# <- storage.type.string.python +#^^^ meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python +# ^^^^^^^^^^^^^^ meta.string.python source.sql +# ^^^^^^^^^^^ meta.string.python meta.interpolation.python +# ^^^ meta.string.python string.quoted.double.block.python punctuation.definition.string.end.python + +f'''SELECT * FROM {table!s:r}''' +# <- storage.type.string.python +#^^^ meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python +# ^^^^^^^^^^^^^^ meta.string.python source.sql +# ^^^^^^^^^^^ meta.string.python meta.interpolation.python +# ^^^ meta.string.python string.quoted.single.block.python punctuation.definition.string.end.python + +f"SELECT * FROM {table!s:r}" +# <- storage.type.string.python +#^ meta.string.python string.quoted.double.python punctuation.definition.string.begin.python +# ^^^^^^^^^^^^^^ meta.string.python source.sql +# ^^^^^^^^^^^ meta.string.python meta.interpolation.python +# ^ meta.string.python string.quoted.double.python punctuation.definition.string.end.python + +f'SELECT * FROM {table!s:r}' +# <- storage.type.string.python +#^ meta.string.python string.quoted.single.python punctuation.definition.string.begin.python +# ^^^^^^^^^^^^^^ meta.string.python source.sql +# ^^^^^^^^^^^ meta.string.python meta.interpolation.python +# ^ meta.string.python string.quoted.single.python punctuation.definition.string.end.python + rf"{value:{width!s:d}}" # <- storage.type.string - meta.string - string #^ storage.type.string - meta.string - string