Bug 386685

Summary: Python syntax highlighter thinks escaped quote at end of triple quote comment string is part of string delimiter
Product: [Frameworks and Libraries] frameworks-syntax-highlighting Reporter: Linus Kardell <linus.kardell>
Component: syntaxAssignee: KWrite Developers <kwrite-bugs-null>
Severity: normal CC: nate, nibgonz
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Example of incorrect highlighting

Description Linus Kardell 2017-11-09 18:00:07 UTC
Created attachment 108764 [details]
Example of incorrect highlighting

If you type a triple quote string in a Python document, and put an escaped quote character at the end of the string, Kate will think the quote character is part of the end delimiter of the string. This only happens for ineffectual strings, which are treated as comments. I you do something with the string, e.g. assign it to a variable.
For example, if you type the below code, "print('test')" will be treated as part of the string:

print """test\""""

And if you type the below, the string will be treated as terminated, even though it's not:


Both programs in the screenshot are valid programs printing test, though though the highlighter would have you think they're not.
Comment 1 Nibaldo G. 2018-07-12 06:51:50 UTC
Proposed patch: https://phabricator.kde.org/D14062
Comment 2 Dominik Haumann 2018-07-14 11:11:56 UTC
Git commit 2627d3e421f6e5973258688c50a1391988500cac by Dominik Haumann, on behalf of Nibaldo González.
Committed on 14/07/2018 at 11:11.
Pushed by dhaumann into branch 'master'.

Python: fix escapes in quoted-comments


Escape characters are not detected in triple-quote comments.
Comments in quotes are literal strings that do not have assignment or operations, so the interpreter ignores them. These are also used to associate documentation with objects, using the `__doc__` attribute (Docstrings [1][2]).

Comments in quotes support the same escapes as normal string. Also, since these can be used as documentation strings, I believe that the correct way is to use the same string escape highlight.

* [1] Python. PEP 257 -- Docstring Conventions: https://www.python.org/dev/peps/pep-0257/
* [2] Python docstrings: http://www.pythonforbeginners.com/basics/python-docstrings

Reviewers: #framework_syntax_highlighting, #kate, dhaumann, cullmann

Reviewed By: #framework_syntax_highlighting, #kate, dhaumann

Subscribers: ngraham, kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

Differential Revision: https://phabricator.kde.org/D14062

M  +5    -0    autotests/folding/test.py.fold
M  +5    -0    autotests/html/test.py.html
M  +5    -0    autotests/input/test.py
M  +5    -0    autotests/reference/test.py.ref
M  +5    -4    data/syntax/python.xml