X Tutup
Skip to content

Commit a71b792

Browse files
committed
Handle one-line docstrings.
1 parent 1f7c61b commit a71b792

File tree

5 files changed

+137
-17
lines changed

5 files changed

+137
-17
lines changed

grammars/MagicPython.YAML-tmLanguage

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ repository:
113113
'1': {name: punctuation.definition.string.end.python}
114114
patterns:
115115
- include: '#docstring-guts-unicode'
116+
- include: '#docstring-guts-common-single'
116117

117118
- name: string.quoted.docstring.raw.python
118119
begin: ([rR])(\'\'\')
@@ -124,6 +125,7 @@ repository:
124125
'1': {name: punctuation.definition.string.end.python}
125126
patterns:
126127
- include: '#docstring-guts-raw'
128+
- include: '#docstring-guts-common-single'
127129

128130
- name: string.quoted.docstring.python
129131
begin: (\"\"\")
@@ -134,6 +136,7 @@ repository:
134136
'1': {name: punctuation.definition.string.end.python}
135137
patterns:
136138
- include: '#docstring-guts-unicode'
139+
- include: '#docstring-guts-common-double'
137140

138141
- name: string.quoted.docstring.raw.python
139142
begin: ([rR])(\"\"\")
@@ -145,23 +148,29 @@ repository:
145148
'1': {name: punctuation.definition.string.end.python}
146149
patterns:
147150
- include: '#docstring-guts-raw'
151+
- include: '#docstring-guts-common-double'
148152

149153
docstring-guts-unicode:
150154
patterns:
151155
- include: '#escape-sequence-unicode'
152156
- include: '#escape-sequence'
153157
- include: '#string-line-continuation'
154-
- include: '#docstring-guts-common'
155158

156159
docstring-guts-raw:
157160
patterns:
158161
- include: '#escape-sequence'
159162
- include: '#string-line-continuation'
160-
- include: '#docstring-guts-common'
161163

162-
docstring-guts-common:
164+
docstring-guts-common-single:
163165
begin: (>>>|\.\.\.)
164-
end: $
166+
end: ($|(?=\'\'\'))
167+
patterns:
168+
- include: '#statement'
169+
- include: '#expression'
170+
171+
docstring-guts-common-double:
172+
begin: (>>>|\.\.\.)
173+
end: ($|(?=\"\"\"))
165174
patterns:
166175
- include: '#statement'
167176
- include: '#expression'

grammars/MagicPython.cson

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ repository:
9999
{
100100
include: "#docstring-guts-unicode"
101101
}
102+
{
103+
include: "#docstring-guts-common-single"
104+
}
102105
]
103106
}
104107
{
@@ -117,6 +120,9 @@ repository:
117120
{
118121
include: "#docstring-guts-raw"
119122
}
123+
{
124+
include: "#docstring-guts-common-single"
125+
}
120126
]
121127
}
122128
{
@@ -133,6 +139,9 @@ repository:
133139
{
134140
include: "#docstring-guts-unicode"
135141
}
142+
{
143+
include: "#docstring-guts-common-double"
144+
}
136145
]
137146
}
138147
{
@@ -151,6 +160,9 @@ repository:
151160
{
152161
include: "#docstring-guts-raw"
153162
}
163+
{
164+
include: "#docstring-guts-common-double"
165+
}
154166
]
155167
}
156168
]
@@ -165,9 +177,6 @@ repository:
165177
{
166178
include: "#string-line-continuation"
167179
}
168-
{
169-
include: "#docstring-guts-common"
170-
}
171180
]
172181
"docstring-guts-raw":
173182
patterns: [
@@ -177,13 +186,21 @@ repository:
177186
{
178187
include: "#string-line-continuation"
179188
}
189+
]
190+
"docstring-guts-common-single":
191+
begin: "(>>>|\\.\\.\\.)"
192+
end: "($|(?=\\'\\'\\'))"
193+
patterns: [
194+
{
195+
include: "#statement"
196+
}
180197
{
181-
include: "#docstring-guts-common"
198+
include: "#expression"
182199
}
183200
]
184-
"docstring-guts-common":
201+
"docstring-guts-common-double":
185202
begin: "(>>>|\\.\\.\\.)"
186-
end: "$"
203+
end: "($|(?=\\\"\\\"\\\"))"
187204
patterns: [
188205
{
189206
include: "#statement"

grammars/MagicPython.tmLanguage

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
<key>include</key>
168168
<string>#docstring-guts-unicode</string>
169169
</dict>
170+
<dict>
171+
<key>include</key>
172+
<string>#docstring-guts-common-single</string>
173+
</dict>
170174
</array>
171175
</dict>
172176
<dict>
@@ -203,6 +207,10 @@
203207
<key>include</key>
204208
<string>#docstring-guts-raw</string>
205209
</dict>
210+
<dict>
211+
<key>include</key>
212+
<string>#docstring-guts-common-single</string>
213+
</dict>
206214
</array>
207215
</dict>
208216
<dict>
@@ -234,6 +242,10 @@
234242
<key>include</key>
235243
<string>#docstring-guts-unicode</string>
236244
</dict>
245+
<dict>
246+
<key>include</key>
247+
<string>#docstring-guts-common-double</string>
248+
</dict>
237249
</array>
238250
</dict>
239251
<dict>
@@ -270,6 +282,10 @@
270282
<key>include</key>
271283
<string>#docstring-guts-raw</string>
272284
</dict>
285+
<dict>
286+
<key>include</key>
287+
<string>#docstring-guts-common-double</string>
288+
</dict>
273289
</array>
274290
</dict>
275291
</array>
@@ -290,10 +306,6 @@
290306
<key>include</key>
291307
<string>#string-line-continuation</string>
292308
</dict>
293-
<dict>
294-
<key>include</key>
295-
<string>#docstring-guts-common</string>
296-
</dict>
297309
</array>
298310
</dict>
299311
<key>docstring-guts-raw</key>
@@ -308,18 +320,32 @@
308320
<key>include</key>
309321
<string>#string-line-continuation</string>
310322
</dict>
323+
</array>
324+
</dict>
325+
<key>docstring-guts-common-single</key>
326+
<dict>
327+
<key>begin</key>
328+
<string>(&gt;&gt;&gt;|\.\.\.)</string>
329+
<key>end</key>
330+
<string>($|(?=\&apos;\&apos;\&apos;))</string>
331+
<key>patterns</key>
332+
<array>
333+
<dict>
334+
<key>include</key>
335+
<string>#statement</string>
336+
</dict>
311337
<dict>
312338
<key>include</key>
313-
<string>#docstring-guts-common</string>
339+
<string>#expression</string>
314340
</dict>
315341
</array>
316342
</dict>
317-
<key>docstring-guts-common</key>
343+
<key>docstring-guts-common-double</key>
318344
<dict>
319345
<key>begin</key>
320346
<string>(&gt;&gt;&gt;|\.\.\.)</string>
321347
<key>end</key>
322-
<string>$</string>
348+
<string>($|(?=\&quot;\&quot;\&quot;))</string>
323349
<key>patterns</key>
324350
<array>
325351
<dict>

test/docstrings/oneline1.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''>>> print("""docstring""")'''
2+
""">>> print('''docstring''')"""
3+
4+
5+
6+
7+
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
8+
>>> : source.python, string.quoted.docstring.python
9+
: source.python, string.quoted.docstring.python
10+
print : meta.function-call.python, source.python, string.quoted.docstring.python, support.function.builtin.python
11+
( : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.arguments.begin.python, source.python, string.quoted.docstring.python
12+
""" : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python, string.quoted.double.multi.python
13+
docstring : meta.function-call.arguments.python, meta.function-call.python, source.python, string.quoted.docstring.python, string.quoted.double.multi.python
14+
""" : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.end.python, source.python, string.quoted.docstring.python, string.quoted.double.multi.python
15+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python, string.quoted.docstring.python
16+
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python
17+
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
18+
>>> : source.python, string.quoted.docstring.python
19+
: source.python, string.quoted.docstring.python
20+
print : meta.function-call.python, source.python, string.quoted.docstring.python, support.function.builtin.python
21+
( : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.arguments.begin.python, source.python, string.quoted.docstring.python
22+
''' : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python, string.quoted.single.multi.python
23+
docstring : meta.function-call.arguments.python, meta.function-call.python, source.python, string.quoted.docstring.python, string.quoted.single.multi.python
24+
''' : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.end.python, source.python, string.quoted.docstring.python, string.quoted.single.multi.python
25+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python, string.quoted.docstring.python
26+
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python

test/docstrings/oneline2.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
def foo():
2+
'''>>> print("""docstring""")'''
3+
def foo():
4+
""">>> print('''docstring''')"""
5+
6+
7+
8+
9+
def : meta.function.python, source.python, storage.type.function.python
10+
: meta.function.python, source.python
11+
foo : entity.name.function.python, meta.function.python, source.python
12+
( : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.begin.python, source.python
13+
) : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.end.python, source.python
14+
: : meta.function.python, punctuation.section.function.begin.python, source.python
15+
: source.python
16+
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
17+
>>> : source.python, string.quoted.docstring.python
18+
: source.python, string.quoted.docstring.python
19+
print : meta.function-call.python, source.python, string.quoted.docstring.python, support.function.builtin.python
20+
( : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.arguments.begin.python, source.python, string.quoted.docstring.python
21+
""" : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python, string.quoted.double.multi.python
22+
docstring : meta.function-call.arguments.python, meta.function-call.python, source.python, string.quoted.docstring.python, string.quoted.double.multi.python
23+
""" : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.end.python, source.python, string.quoted.docstring.python, string.quoted.double.multi.python
24+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python, string.quoted.docstring.python
25+
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python
26+
def : meta.function.python, source.python, storage.type.function.python
27+
: meta.function.python, source.python
28+
foo : entity.name.function.python, meta.function.python, source.python
29+
( : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.begin.python, source.python
30+
) : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.end.python, source.python
31+
: : meta.function.python, punctuation.section.function.begin.python, source.python
32+
: source.python
33+
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
34+
>>> : source.python, string.quoted.docstring.python
35+
: source.python, string.quoted.docstring.python
36+
print : meta.function-call.python, source.python, string.quoted.docstring.python, support.function.builtin.python
37+
( : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.arguments.begin.python, source.python, string.quoted.docstring.python
38+
''' : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python, string.quoted.single.multi.python
39+
docstring : meta.function-call.arguments.python, meta.function-call.python, source.python, string.quoted.docstring.python, string.quoted.single.multi.python
40+
''' : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.string.end.python, source.python, string.quoted.docstring.python, string.quoted.single.multi.python
41+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python, string.quoted.docstring.python
42+
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python

0 commit comments

Comments
 (0)
X Tutup