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/c58247de8ab20ae1794a09d5263d16416cd32c95

/> Properly handle backslashes in raw docstrings · MagicStack/MagicPython@c58247d · GitHub
Skip to content

Commit c58247d

Browse files
committed
Properly handle backslashes in raw docstrings
1 parent 70cf5d3 commit c58247d

File tree

6 files changed

+139
-30
lines changed

6 files changed

+139
-30
lines changed

grammars/MagicPython.YAML-tmLanguage

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ repository:
132132
endCaptures:
133133
'1': {name: punctuation.definition.string.end.python}
134134
patterns:
135+
- include: '#string-consume-escape'
135136
- include: '#docstring-guts-common'
136137

137138
docstring-guts-unicode:
@@ -471,15 +472,18 @@ repository:
471472
- include: '#string-entity'
472473
- include: '#string-brace-formatting'
473474

475+
string-consume-escape:
476+
match: \\.
477+
474478
string-raw-guts:
475479
patterns:
476-
- match: \\.
480+
- include: '#string-consume-escape'
477481
- include: '#string-formatting'
478482
- include: '#string-brace-formatting'
479483

480484
string-raw-bin-guts:
481485
patterns:
482-
- match: \\.
486+
- include: '#string-consume-escape'
483487
- include: '#string-formatting'
484488

485489
string-entity:

grammars/MagicPython.cson

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ repository:
109109
"1":
110110
name: "punctuation.definition.string.end.python"
111111
patterns: [
112+
{
113+
include: "#string-consume-escape"
114+
}
112115
{
113116
include: "#docstring-guts-common"
114117
}
@@ -656,10 +659,12 @@ repository:
656659
include: "#string-brace-formatting"
657660
}
658661
]
662+
"string-consume-escape":
663+
match: "\\\\."
659664
"string-raw-guts":
660665
patterns: [
661666
{
662-
match: "\\\\."
667+
include: "#string-consume-escape"
663668
}
664669
{
665670
include: "#string-formatting"
@@ -671,7 +676,7 @@ repository:
671676
"string-raw-bin-guts":
672677
patterns: [
673678
{
674-
match: "\\\\."
679+
include: "#string-consume-escape"
675680
}
676681
{
677682
include: "#string-formatting"

grammars/MagicPython.tmLanguage

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@
183183
</dict>
184184
<key>patterns</key>
185185
<array>
186+
<dict>
187+
<key>include</key>
188+
<string>#string-consume-escape</string>
189+
</dict>
186190
<dict>
187191
<key>include</key>
188192
<string>#docstring-guts-common</string>
@@ -1069,13 +1073,18 @@
10691073
</dict>
10701074
</array>
10711075
</dict>
1076+
<key>string-consume-escape</key>
1077+
<dict>
1078+
<key>match</key>
1079+
<string>\\.</string>
1080+
</dict>
10721081
<key>string-raw-guts</key>
10731082
<dict>
10741083
<key>patterns</key>
10751084
<array>
10761085
<dict>
1077-
<key>match</key>
1078-
<string>\\.</string>
1086+
<key>include</key>
1087+
<string>#string-consume-escape</string>
10791088
</dict>
10801089
<dict>
10811090
<key>include</key>
@@ -1092,8 +1101,8 @@
10921101
<key>patterns</key>
10931102
<array>
10941103
<dict>
1095-
<key>match</key>
1096-
<string>\\.</string>
1104+
<key>include</key>
1105+
<string>#string-consume-escape</string>
10971106
</dict>
10981107
<dict>
10991108
<key>include</key>

test/docstrings/def1.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
def foo():
2-
'''TEST'''
2+
'''TE\'''ST'''
33

44
def foo():
5-
r'''TEST'''
5+
r'''TE\'''ST'''
66

77
def foo():
8-
R'''TEST'''
8+
R'''TE\'''ST'''
99

1010
def foo():
1111
u'''TEST'''
@@ -21,7 +21,6 @@ def foo():
2121

2222

2323

24-
2524
def : meta.function.python, source.python, storage.type.function.python
2625
: meta.function.python, source.python
2726
foo : entity.name.function.python, meta.function.python, source.python
@@ -30,7 +29,9 @@ def : meta.function.python, source.python, storage.type.function.pytho
3029
: : meta.function.python, punctuation.section.function.begin.python, source.python
3130
: source.python
3231
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
33-
TEST : source.python, string.quoted.docstring.python
32+
TE : source.python, string.quoted.docstring.python
33+
\' : constant.character.python, source.python, string.quoted.docstring.python
34+
''ST : source.python, string.quoted.docstring.python
3435
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python
3536
: source.python
3637
def : meta.function.python, source.python, storage.type.function.python
@@ -42,7 +43,9 @@ def : meta.function.python, source.python, storage.type.function.pytho
4243
: source.python
4344
r : source.python, storage.type.string.python, string.quoted.docstring.raw.python
4445
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.raw.python
45-
TEST : source.python, string.quoted.docstring.raw.python
46+
TE : source.python, string.quoted.docstring.raw.python
47+
\' : source.python, string.quoted.docstring.raw.python
48+
''ST : source.python, string.quoted.docstring.raw.python
4649
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.raw.python
4750
: source.python
4851
def : meta.function.python, source.python, storage.type.function.python
@@ -54,7 +57,9 @@ def : meta.function.python, source.python, storage.type.function.pytho
5457
: source.python
5558
R : source.python, storage.type.string.python, string.quoted.docstring.raw.python
5659
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.raw.python
57-
TEST : source.python, string.quoted.docstring.raw.python
60+
TE : source.python, string.quoted.docstring.raw.python
61+
\' : source.python, string.quoted.docstring.raw.python
62+
''ST : source.python, string.quoted.docstring.raw.python
5863
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.raw.python
5964
: source.python
6065
def : meta.function.python, source.python, storage.type.function.python

test/docstrings/def2.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
def foo():
2-
"""TEST"""
2+
"""TE\"""ST"""
33

44
def foo():
5-
r"""TEST"""
5+
r"""TE\"""ST"""
66

77
def foo():
8-
R"""TEST"""
8+
R"""TE\"""ST"""
99

1010
def foo():
1111
u"""TEST"""
@@ -21,7 +21,6 @@ def foo():
2121

2222

2323

24-
2524
def : meta.function.python, source.python, storage.type.function.python
2625
: meta.function.python, source.python
2726
foo : entity.name.function.python, meta.function.python, source.python
@@ -30,7 +29,9 @@ def : meta.function.python, source.python, storage.type.function.pytho
3029
: : meta.function.python, punctuation.section.function.begin.python, source.python
3130
: source.python
3231
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
33-
TEST : source.python, string.quoted.docstring.python
32+
TE : source.python, string.quoted.docstring.python
33+
\" : constant.character.python, source.python, string.quoted.docstring.python
34+
""ST : source.python, string.quoted.docstring.python
3435
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python
3536
: source.python
3637
def : meta.function.python, source.python, storage.type.function.python
@@ -42,7 +43,9 @@ def : meta.function.python, source.python, storage.type.function.pytho
4243
: source.python
4344
r : source.python, storage.type.string.python, string.quoted.docstring.raw.python
4445
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.raw.python
45-
TEST : source.python, string.quoted.docstring.raw.python
46+
TE : source.python, string.quoted.docstring.raw.python
47+
\" : source.python, string.quoted.docstring.raw.python
48+
""ST : source.python, string.quoted.docstring.raw.python
4649
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.raw.python
4750
: source.python
4851
def : meta.function.python, source.python, storage.type.function.python
@@ -54,7 +57,9 @@ def : meta.function.python, source.python, storage.type.function.pytho
5457
: source.python
5558
R : source.python, storage.type.string.python, string.quoted.docstring.raw.python
5659
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.raw.python
57-
TEST : source.python, string.quoted.docstring.raw.python
60+
TE : source.python, string.quoted.docstring.raw.python
61+
\" : source.python, string.quoted.docstring.raw.python
62+
""ST : source.python, string.quoted.docstring.raw.python
5863
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.raw.python
5964
: source.python
6065
def : meta.function.python, source.python, storage.type.function.python

test/docstrings/escaping2.py

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,57 @@
2121
'''
2222

2323

24+
2425
r : source.python, storage.type.string.python, string.quoted.docstring.raw.python
2526
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.raw.python
2627
Module docstring : source.python, string.quoted.docstring.raw.python
2728
: source.python, string.quoted.docstring.raw.python
28-
simple \\ string \ : source.python, string.quoted.docstring.raw.python
29-
foo \' \" \a \b \c \f \n \r \t \v \5 \55 \555 \05 \005 : source.python, string.quoted.docstring.raw.python
29+
simple : source.python, string.quoted.docstring.raw.python
30+
\\ : source.python, string.quoted.docstring.raw.python
31+
string \ : source.python, string.quoted.docstring.raw.python
32+
foo : source.python, string.quoted.docstring.raw.python
33+
\' : source.python, string.quoted.docstring.raw.python
34+
: source.python, string.quoted.docstring.raw.python
35+
\" : source.python, string.quoted.docstring.raw.python
36+
: source.python, string.quoted.docstring.raw.python
37+
\a : source.python, string.quoted.docstring.raw.python
38+
: source.python, string.quoted.docstring.raw.python
39+
\b : source.python, string.quoted.docstring.raw.python
40+
: source.python, string.quoted.docstring.raw.python
41+
\c : source.python, string.quoted.docstring.raw.python
42+
: source.python, string.quoted.docstring.raw.python
43+
\f : source.python, string.quoted.docstring.raw.python
44+
: source.python, string.quoted.docstring.raw.python
45+
\n : source.python, string.quoted.docstring.raw.python
46+
: source.python, string.quoted.docstring.raw.python
47+
\r : source.python, string.quoted.docstring.raw.python
48+
: source.python, string.quoted.docstring.raw.python
49+
\t : source.python, string.quoted.docstring.raw.python
50+
: source.python, string.quoted.docstring.raw.python
51+
\v : source.python, string.quoted.docstring.raw.python
52+
: source.python, string.quoted.docstring.raw.python
53+
\5 : source.python, string.quoted.docstring.raw.python
54+
: source.python, string.quoted.docstring.raw.python
55+
\5 : source.python, string.quoted.docstring.raw.python
56+
5 : source.python, string.quoted.docstring.raw.python
57+
\5 : source.python, string.quoted.docstring.raw.python
58+
55 : source.python, string.quoted.docstring.raw.python
59+
\0 : source.python, string.quoted.docstring.raw.python
60+
5 : source.python, string.quoted.docstring.raw.python
61+
\0 : source.python, string.quoted.docstring.raw.python
62+
05 : source.python, string.quoted.docstring.raw.python
3063
: source.python, string.quoted.docstring.raw.python
3164
multiline "unicode" string \ : source.python, string.quoted.docstring.raw.python
32-
\xf1 \u1234aaaa \U1234aaaa : source.python, string.quoted.docstring.raw.python
33-
\N{BLACK SPADE SUIT} : source.python, string.quoted.docstring.raw.python
65+
: source.python, string.quoted.docstring.raw.python
66+
\x : source.python, string.quoted.docstring.raw.python
67+
f1 : source.python, string.quoted.docstring.raw.python
68+
\u : source.python, string.quoted.docstring.raw.python
69+
1234aaaa : source.python, string.quoted.docstring.raw.python
70+
\U : source.python, string.quoted.docstring.raw.python
71+
1234aaaa : source.python, string.quoted.docstring.raw.python
72+
: source.python, string.quoted.docstring.raw.python
73+
\N : source.python, string.quoted.docstring.raw.python
74+
{BLACK SPADE SUIT} : source.python, string.quoted.docstring.raw.python
3475
: source.python, string.quoted.docstring.raw.python
3576
>>> : keyword.control.flow.python, source.python, string.quoted.docstring.raw.python
3677
aaa : source.python, string.quoted.docstring.raw.python
@@ -40,12 +81,52 @@
4081
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.raw.python
4182
Module docstring : source.python, string.quoted.docstring.raw.python
4283
: source.python, string.quoted.docstring.raw.python
43-
simple \\ string \ : source.python, string.quoted.docstring.raw.python
44-
foo \' \" \a \b \c \f \n \r \t \v \5 \55 \555 \05 \005 : source.python, string.quoted.docstring.raw.python
84+
simple : source.python, string.quoted.docstring.raw.python
85+
\\ : source.python, string.quoted.docstring.raw.python
86+
string \ : source.python, string.quoted.docstring.raw.python
87+
foo : source.python, string.quoted.docstring.raw.python
88+
\' : source.python, string.quoted.docstring.raw.python
89+
: source.python, string.quoted.docstring.raw.python
90+
\" : source.python, string.quoted.docstring.raw.python
91+
: source.python, string.quoted.docstring.raw.python
92+
\a : source.python, string.quoted.docstring.raw.python
93+
: source.python, string.quoted.docstring.raw.python
94+
\b : source.python, string.quoted.docstring.raw.python
95+
: source.python, string.quoted.docstring.raw.python
96+
\c : source.python, string.quoted.docstring.raw.python
97+
: source.python, string.quoted.docstring.raw.python
98+
\f : source.python, string.quoted.docstring.raw.python
99+
: source.python, string.quoted.docstring.raw.python
100+
\n : source.python, string.quoted.docstring.raw.python
101+
: source.python, string.quoted.docstring.raw.python
102+
\r : source.python, string.quoted.docstring.raw.python
103+
: source.python, string.quoted.docstring.raw.python
104+
\t : source.python, string.quoted.docstring.raw.python
105+
: source.python, string.quoted.docstring.raw.python
106+
\v : source.python, string.quoted.docstring.raw.python
107+
: source.python, string.quoted.docstring.raw.python
108+
\5 : source.python, string.quoted.docstring.raw.python
109+
: source.python, string.quoted.docstring.raw.python
110+
\5 : source.python, string.quoted.docstring.raw.python
111+
5 : source.python, string.quoted.docstring.raw.python
112+
\5 : source.python, string.quoted.docstring.raw.python
113+
55 : source.python, string.quoted.docstring.raw.python
114+
\0 : source.python, string.quoted.docstring.raw.python
115+
5 : source.python, string.quoted.docstring.raw.python
116+
\0 : source.python, string.quoted.docstring.raw.python
117+
05 : source.python, string.quoted.docstring.raw.python
45118
: source.python, string.quoted.docstring.raw.python
46119
multiline "unicode" string \ : source.python, string.quoted.docstring.raw.python
47-
\xf1 \u1234aaaa \U1234aaaa : source.python, string.quoted.docstring.raw.python
48-
\N{BLACK SPADE SUIT} : source.python, string.quoted.docstring.raw.python
120+
: source.python, string.quoted.docstring.raw.python
121+
\x : source.python, string.quoted.docstring.raw.python
122+
f1 : source.python, string.quoted.docstring.raw.python
123+
\u : source.python, string.quoted.docstring.raw.python
124+
1234aaaa : source.python, string.quoted.docstring.raw.python
125+
\U : source.python, string.quoted.docstring.raw.python
126+
1234aaaa : source.python, string.quoted.docstring.raw.python
127+
: source.python, string.quoted.docstring.raw.python
128+
\N : source.python, string.quoted.docstring.raw.python
129+
{BLACK SPADE SUIT} : source.python, string.quoted.docstring.raw.python
49130
: source.python, string.quoted.docstring.raw.python
50131
>>> : keyword.control.flow.python, source.python, string.quoted.docstring.raw.python
51132
aaa : 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