Skip to content

Commit feeecc5

Browse files
committed
Add support for single quoted doctrings (apparently they are popular)
1 parent 2c645de commit feeecc5

14 files changed

+766
-83
lines changed

Diff for: grammars/MagicPython.YAML-tmLanguage

+47-20
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ repository:
8080
begin: (?<=:)
8181
end: |
8282
(?x)
83-
(?! \s | \# | [rR]?(\'\'\'|\"\"\") | $)
83+
(?! \s | \# | [rR]?(\'\'\'|\"\"\"|\'|\") | $)
8484
|
85-
(?<=\'\'\'|\"\"\")
85+
(?<=\'\'\'|\"\"\"|\'|\")
8686
endCaptures:
8787
'1': {name: punctuation.definition.string.end.python}
8888
patterns:
8989
- include: '#comments'
9090
- include: '#docstring'
9191

9292
docstring-module:
93-
begin: ^(?=[rR]?(\'\'\'|\"\"\"))
94-
end: (?<=\'\'\'|\"\"\")
93+
begin: ^(?=[rR]?(\'\'\'|\"\"\"|\'|\"))
94+
end: (?<=\'\'\'|\"\"\"|\'|\")
9595
patterns:
9696
- include: '#docstring'
9797

@@ -105,7 +105,8 @@ repository:
105105
endCaptures:
106106
'1': {name: punctuation.definition.string.end.python}
107107
patterns:
108-
- include: '#docstring-guts-common'
108+
- include: '#docstring-prompt'
109+
- include: '#docstring-codetags'
109110
- include: '#docstring-guts-unicode'
110111

111112
- name: string.quoted.docstring.raw.multi.python
@@ -118,28 +119,54 @@ repository:
118119
'1': {name: punctuation.definition.string.end.python}
119120
patterns:
120121
- include: '#string-consume-escape'
121-
- include: '#docstring-guts-common'
122+
- include: '#docstring-prompt'
123+
- include: '#docstring-codetags'
124+
125+
- name: string.quoted.docstring.python
126+
begin: (\'|\")
127+
end: (\1)|((?<!\\)\n)
128+
beginCaptures:
129+
'1': {name: punctuation.definition.string.begin.python}
130+
endCaptures:
131+
'1': {name: punctuation.definition.string.end.python}
132+
'2': {name: invalid.illegal.newline.python}
133+
patterns:
134+
- include: '#docstring-codetags'
135+
- include: '#docstring-guts-unicode'
136+
137+
- name: string.quoted.docstring.raw.python
138+
begin: ([rR])(\'|\")
139+
end: (\2)|((?<!\\)\n)
140+
beginCaptures:
141+
'1': {name: storage.type.string.python}
142+
'2': {name: punctuation.definition.string.begin.python}
143+
endCaptures:
144+
'1': {name: punctuation.definition.string.end.python}
145+
'2': {name: invalid.illegal.newline.python}
146+
patterns:
147+
- include: '#string-consume-escape'
148+
- include: '#docstring-codetags'
122149

123150
docstring-guts-unicode:
124151
patterns:
125152
- include: '#escape-sequence-unicode'
126153
- include: '#escape-sequence'
127154
- include: '#string-line-continuation'
128155

129-
docstring-guts-common:
130-
patterns:
131-
- match: |
132-
(?x)
133-
(?:
134-
(?:^|\G) \s* (?# '\G' is necessary for ST)
135-
((?:>>>|\.\.\.) \s)
136-
)
137-
captures:
138-
'1': {name: keyword.control.flow.python}
156+
docstring-prompt:
157+
match: |
158+
(?x)
159+
(?:
160+
(?:^|\G) \s* (?# '\G' is necessary for ST)
161+
((?:>>>|\.\.\.) \s)
162+
)
163+
captures:
164+
'1': {name: keyword.control.flow.python}
139165

140-
- match: (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b)
141-
captures:
142-
'1': {name: keyword.string.quoted.docstring.note.python}
166+
docstring-codetags:
167+
match: (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b)
168+
captures:
169+
'1': {name: keyword.string.quoted.docstring.note.python}
143170

144171
statement-keyword:
145172
patterns:
@@ -245,7 +272,7 @@ repository:
245272
(?x)
246273
(?=^\s*$)
247274
|
248-
(?! ([rR]? (\'\'\'|\"\"\"))
275+
(?! ([rR]? (\'\'\'|\"\"\"|\'|\"))
249276
|
250277
(\G $) (?# '\G' is necessary for ST)
251278
)

Diff for: grammars/MagicPython.cson

+74-29
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ repository:
5151
begin: "(?<=:)"
5252
end: '''
5353
(?x)
54-
(?! \\s | \\# | [rR]?(\\'\\'\\'|\\"\\"\\") | $)
54+
(?! \\s | \\# | [rR]?(\\'\\'\\'|\\"\\"\\"|\\'|\\") | $)
5555
|
56-
(?<=\\'\\'\\'|\\"\\"\\")
56+
(?<=\\'\\'\\'|\\"\\"\\"|\\'|\\")
5757
5858
'''
5959
endCaptures:
@@ -68,8 +68,8 @@ repository:
6868
}
6969
]
7070
"docstring-module":
71-
begin: "^(?=[rR]?(\\'\\'\\'|\\\"\\\"\\\"))"
72-
end: "(?<=\\'\\'\\'|\\\"\\\"\\\")"
71+
begin: "^(?=[rR]?(\\'\\'\\'|\\\"\\\"\\\"|\\'|\\\"))"
72+
end: "(?<=\\'\\'\\'|\\\"\\\"\\\"|\\'|\\\")"
7373
patterns: [
7474
{
7575
include: "#docstring"
@@ -89,7 +89,10 @@ repository:
8989
name: "punctuation.definition.string.end.python"
9090
patterns: [
9191
{
92-
include: "#docstring-guts-common"
92+
include: "#docstring-prompt"
93+
}
94+
{
95+
include: "#docstring-codetags"
9396
}
9497
{
9598
include: "#docstring-guts-unicode"
@@ -113,7 +116,54 @@ repository:
113116
include: "#string-consume-escape"
114117
}
115118
{
116-
include: "#docstring-guts-common"
119+
include: "#docstring-prompt"
120+
}
121+
{
122+
include: "#docstring-codetags"
123+
}
124+
]
125+
}
126+
{
127+
name: "string.quoted.docstring.python"
128+
begin: "(\\'|\\\")"
129+
end: "(\\1)|((?<!\\\\)\\n)"
130+
beginCaptures:
131+
"1":
132+
name: "punctuation.definition.string.begin.python"
133+
endCaptures:
134+
"1":
135+
name: "punctuation.definition.string.end.python"
136+
"2":
137+
name: "invalid.illegal.newline.python"
138+
patterns: [
139+
{
140+
include: "#docstring-codetags"
141+
}
142+
{
143+
include: "#docstring-guts-unicode"
144+
}
145+
]
146+
}
147+
{
148+
name: "string.quoted.docstring.raw.python"
149+
begin: "([rR])(\\'|\\\")"
150+
end: "(\\2)|((?<!\\\\)\\n)"
151+
beginCaptures:
152+
"1":
153+
name: "storage.type.string.python"
154+
"2":
155+
name: "punctuation.definition.string.begin.python"
156+
endCaptures:
157+
"1":
158+
name: "punctuation.definition.string.end.python"
159+
"2":
160+
name: "invalid.illegal.newline.python"
161+
patterns: [
162+
{
163+
include: "#string-consume-escape"
164+
}
165+
{
166+
include: "#docstring-codetags"
117167
}
118168
]
119169
}
@@ -130,28 +180,23 @@ repository:
130180
include: "#string-line-continuation"
131181
}
132182
]
133-
"docstring-guts-common":
134-
patterns: [
135-
{
136-
match: '''
137-
(?x)
138-
(?:
139-
(?:^|\\G) \\s* (?# '\\G' is necessary for ST)
140-
((?:>>>|\\.\\.\\.) \\s)
141-
)
142-
143-
'''
144-
captures:
145-
"1":
146-
name: "keyword.control.flow.python"
147-
}
148-
{
149-
match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)"
150-
captures:
151-
"1":
152-
name: "keyword.string.quoted.docstring.note.python"
153-
}
154-
]
183+
"docstring-prompt":
184+
match: '''
185+
(?x)
186+
(?:
187+
(?:^|\\G) \\s* (?# '\\G' is necessary for ST)
188+
((?:>>>|\\.\\.\\.) \\s)
189+
)
190+
191+
'''
192+
captures:
193+
"1":
194+
name: "keyword.control.flow.python"
195+
"docstring-codetags":
196+
match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)"
197+
captures:
198+
"1":
199+
name: "keyword.string.quoted.docstring.note.python"
155200
"statement-keyword":
156201
patterns: [
157202
{
@@ -329,7 +374,7 @@ repository:
329374
(?x)
330375
(?=^\\s*$)
331376
|
332-
(?! ([rR]? (\\'\\'\\'|\\"\\"\\"))
377+
(?! ([rR]? (\\'\\'\\'|\\"\\"\\"|\\'|\\"))
333378
|
334379
(\\G $) (?# '\\G' is necessary for ST)
335380
)

0 commit comments

Comments
 (0)