pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/MagicStack/MagicPython/commit/1f7c61b3e14657bb565c4c65f8461ba5cc7631cb

ss" /> Handle a string after line continuation as not docstring. · MagicStack/MagicPython@1f7c61b · GitHub
Skip to content

Commit 1f7c61b

Browse files
committed
Handle a string after line continuation as not docstring.
1 parent d991894 commit 1f7c61b

File tree

4 files changed

+110
-16
lines changed

4 files changed

+110
-16
lines changed

grammars/MagicPython.YAML-tmLanguage

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,24 @@ repository:
258258

259259
line-continuation:
260260
patterns:
261-
- match: '(\\)\s*$'
262-
captures:
263-
'1': {name: separator.continuation.line.python}
264261
- match: '(\\)\s*(\S.*$\n?)'
265262
captures:
266263
'1': {name: separator.continuation.line.python}
267264
'2': {name: invalid.illegal.line.continuation.python}
265+
- begin: '(\\)\s*$\n?'
266+
# Line continuation matching ends on anything that is not a
267+
# potential docstring. For docstring-like strings we explicitly
268+
# match regexp and string.
269+
end: |
270+
(?x)
271+
(?=^\s*$)
272+
|
273+
(?! [rR]? (\'\'\'|\"\"\") | $)
274+
beginCaptures:
275+
'1': {name: separator.continuation.line.python}
276+
patterns:
277+
- include: '#regexp'
278+
- include: '#string'
268279

269280
assignment-operator:
270281
name: keyword.operator.assignment.python

grammars/MagicPython.cson

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,33 @@ repository:
356356
"line-continuation":
357357
patterns: [
358358
{
359-
match: "(\\\\)\\s*$"
359+
match: "(\\\\)\\s*(\\S.*$\\n?)"
360360
captures:
361361
"1":
362362
name: "separator.continuation.line.python"
363+
"2":
364+
name: "invalid.illegal.line.continuation.python"
363365
}
364366
{
365-
match: "(\\\\)\\s*(\\S.*$\\n?)"
366-
captures:
367+
begin: "(\\\\)\\s*$\\n?"
368+
end: '''
369+
(?x)
370+
(?=^\\s*$)
371+
|
372+
(?! [rR]? (\\'\\'\\'|\\"\\"\\") | $)
373+
374+
'''
375+
beginCaptures:
367376
"1":
368377
name: "separator.continuation.line.python"
369-
"2":
370-
name: "invalid.illegal.line.continuation.python"
378+
patterns: [
379+
{
380+
include: "#regexp"
381+
}
382+
{
383+
include: "#string"
384+
}
385+
]
371386
}
372387
]
373388
"assignment-operator":

grammars/MagicPython.tmLanguage

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,32 +584,49 @@
584584
<array>
585585
<dict>
586586
<key>match</key>
587-
<string>(\\)\s*$</string>
587+
<string>(\\)\s*(\S.*$\n?)</string>
588588
<key>captures</key>
589589
<dict>
590590
<key>1</key>
591591
<dict>
592592
<key>name</key>
593593
<string>separator.continuation.line.python</string>
594594
</dict>
595+
<key>2</key>
596+
<dict>
597+
<key>name</key>
598+
<string>invalid.illegal.line.continuation.python</string>
599+
</dict>
595600
</dict>
596601
</dict>
597602
<dict>
598-
<key>match</key>
599-
<string>(\\)\s*(\S.*$\n?)</string>
600-
<key>captures</key>
603+
<key>begin</key>
604+
<string>(\\)\s*$\n?</string>
605+
<key>end</key>
606+
<string>(?x)
607+
(?=^\s*$)
608+
|
609+
(?! [rR]? (\&apos;\&apos;\&apos;|\&quot;\&quot;\&quot;) | $)
610+
</string>
611+
<key>beginCaptures</key>
601612
<dict>
602613
<key>1</key>
603614
<dict>
604615
<key>name</key>
605616
<string>separator.continuation.line.python</string>
606617
</dict>
607-
<key>2</key>
618+
</dict>
619+
<key>patterns</key>
620+
<array>
608621
<dict>
609-
<key>name</key>
610-
<string>invalid.illegal.line.continuation.python</string>
622+
<key>include</key>
623+
<string>#regexp</string>
611624
</dict>
612-
</dict>
625+
<dict>
626+
<key>include</key>
627+
<string>#string</string>
628+
</dict>
629+
</array>
613630
</dict>
614631
</array>
615632
</dict>

test/docstrings/continuation1.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# not a docstring
2+
a = \
3+
r'''
4+
>>> print(42)
5+
a[wer]
6+
'''
7+
a = \
8+
# docstring
9+
r'''
10+
>>> print()
11+
a[wer]
12+
'''
13+
14+
15+
16+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
17+
not a docstring : comment.line.number-sign.python, source.python
18+
a : source.python
19+
= : keyword.operator.assignment.python, source.python
20+
: source.python
21+
\ : separator.continuation.line.python, source.python
22+
: source.python
23+
r : source.python, storage.type.string.python, string.regexp.quoted.triple.python
24+
''' : punctuation.definition.string.begin.python, source.python, string.regexp.quoted.triple.python
25+
>>> print : source.python, string.regexp.quoted.triple.python
26+
( : punctuation.parenthesis.begin.regexp support.other.parenthesis.regexp, source.python, string.regexp.quoted.triple.python
27+
42 : source.python, string.regexp.quoted.triple.python
28+
) : punctuation.parenthesis.end.regexp support.other.parenthesis.regexp, source.python, string.regexp.quoted.triple.python
29+
a : source.python, string.regexp.quoted.triple.python
30+
[ : constant.other.set.regexp punctuation.character.set.begin.regexp, meta.character.set.regexp, source.python, string.regexp.quoted.triple.python
31+
w : constant.character.set.regexp, meta.character.set.regexp, source.python, string.regexp.quoted.triple.python
32+
e : constant.character.set.regexp, meta.character.set.regexp, source.python, string.regexp.quoted.triple.python
33+
r : constant.character.set.regexp, meta.character.set.regexp, source.python, string.regexp.quoted.triple.python
34+
] : constant.other.set.regexp punctuation.character.set.end.regexp, meta.character.set.regexp, source.python, string.regexp.quoted.triple.python
35+
''' : punctuation.definition.string.end.python, source.python, string.regexp.quoted.triple.python
36+
a : source.python
37+
= : keyword.operator.assignment.python, source.python
38+
: source.python
39+
\ : separator.continuation.line.python, source.python
40+
: source.python
41+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
42+
docstring : comment.line.number-sign.python, source.python
43+
r : source.python, storage.type.string.python, string.quoted.docstring.raw.python
44+
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.raw.python
45+
>>> : source.python, string.quoted.docstring.raw.python
46+
: source.python, string.quoted.docstring.raw.python
47+
print : meta.function-call.python, source.python, string.quoted.docstring.raw.python, support.function.builtin.python
48+
( : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.arguments.begin.python, source.python, string.quoted.docstring.raw.python
49+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python, string.quoted.docstring.raw.python
50+
a[wer] : source.python, string.quoted.docstring.raw.python
51+
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.raw.python

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy