Skip to content

Commit 3b23b29

Browse files
committed
Highlight XXX, FIXME etc anywhere in comments and docstrings
1 parent 2625c16 commit 3b23b29

File tree

7 files changed

+185
-45
lines changed

7 files changed

+185
-45
lines changed

grammars/MagicPython.YAML-tmLanguage

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ repository:
6868

6969
comments:
7070
name: comment.line.number-sign.python
71-
match: (\#)\s*(BUG|FIXME|TODO|XXX|NB)?.*$
72-
captures:
71+
begin: (\#)
72+
beginCaptures:
7373
'1': {name: punctuation.definition.comment.python}
74-
'2': {name: comment.line.note.notation.python}
74+
end: ($)
75+
patterns:
76+
- match: (?:\b(BUG|FIXME|TODO|XXX|NB)\b)
77+
captures:
78+
'1': {name: comment.line.note.notation.python}
7579

7680
statement:
7781
patterns:
@@ -155,14 +159,20 @@ repository:
155159
- include: '#string-line-continuation'
156160

157161
docstring-guts-common:
158-
match: |
159-
(?x)
160-
(?:
161-
(?:^|\G) \s* (?# '\G' is necessary for ST)
162-
((?:>>>|\.\.\.) \s)
163-
)
164-
captures:
165-
'1': {name: keyword.control.flow.python}
162+
patterns:
163+
- match: |
164+
(?x)
165+
(?:
166+
(?:^|\G) \s* (?# '\G' is necessary for ST)
167+
((?:>>>|\.\.\.) \s)
168+
)
169+
captures:
170+
'1': {name: keyword.control.flow.python}
171+
172+
- match: (?:\b(BUG|FIXME|TODO|XXX|NB)\b)
173+
captures:
174+
'1': {name: string.quoted.docstring.note.python}
175+
166176

167177
statement-keyword:
168178
patterns:

grammars/MagicPython.cson

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@ patterns: [
2525
repository:
2626
comments:
2727
name: "comment.line.number-sign.python"
28-
match: "(\\#)\\s*(BUG|FIXME|TODO|XXX|NB)?.*$"
29-
captures:
28+
begin: "(\\#)"
29+
beginCaptures:
3030
"1":
3131
name: "punctuation.definition.comment.python"
32-
"2":
33-
name: "comment.line.note.notation.python"
32+
end: "($)"
33+
patterns: [
34+
{
35+
match: "(?:\\b(BUG|FIXME|TODO|XXX|NB)\\b)"
36+
captures:
37+
"1":
38+
name: "comment.line.note.notation.python"
39+
}
40+
]
3441
statement:
3542
patterns: [
3643
{
@@ -173,17 +180,27 @@ repository:
173180
}
174181
]
175182
"docstring-guts-common":
176-
match: '''
177-
(?x)
178-
(?:
179-
(?:^|\\G) \\s* (?# '\\G' is necessary for ST)
180-
((?:>>>|\\.\\.\\.) \\s)
181-
)
182-
183-
'''
184-
captures:
185-
"1":
186-
name: "keyword.control.flow.python"
183+
patterns: [
184+
{
185+
match: '''
186+
(?x)
187+
(?:
188+
(?:^|\\G) \\s* (?# '\\G' is necessary for ST)
189+
((?:>>>|\\.\\.\\.) \\s)
190+
)
191+
192+
'''
193+
captures:
194+
"1":
195+
name: "keyword.control.flow.python"
196+
}
197+
{
198+
match: "(?:\\b(BUG|FIXME|TODO|XXX|NB)\\b)"
199+
captures:
200+
"1":
201+
name: "string.quoted.docstring.note.python"
202+
}
203+
]
187204
"statement-keyword":
188205
patterns: [
189206
{

grammars/MagicPython.tmLanguage

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,33 @@
4040
<dict>
4141
<key>name</key>
4242
<string>comment.line.number-sign.python</string>
43-
<key>match</key>
44-
<string>(\#)\s*(BUG|FIXME|TODO|XXX|NB)?.*$</string>
45-
<key>captures</key>
43+
<key>begin</key>
44+
<string>(\#)</string>
45+
<key>beginCaptures</key>
4646
<dict>
4747
<key>1</key>
4848
<dict>
4949
<key>name</key>
5050
<string>punctuation.definition.comment.python</string>
5151
</dict>
52-
<key>2</key>
52+
</dict>
53+
<key>end</key>
54+
<string>($)</string>
55+
<key>patterns</key>
56+
<array>
5357
<dict>
54-
<key>name</key>
55-
<string>comment.line.note.notation.python</string>
58+
<key>match</key>
59+
<string>(?:\b(BUG|FIXME|TODO|XXX|NB)\b)</string>
60+
<key>captures</key>
61+
<dict>
62+
<key>1</key>
63+
<dict>
64+
<key>name</key>
65+
<string>comment.line.note.notation.python</string>
66+
</dict>
67+
</dict>
5668
</dict>
57-
</dict>
69+
</array>
5870
</dict>
5971
<key>statement</key>
6072
<dict>
@@ -302,21 +314,38 @@
302314
</dict>
303315
<key>docstring-guts-common</key>
304316
<dict>
305-
<key>match</key>
306-
<string>(?x)
317+
<key>patterns</key>
318+
<array>
319+
<dict>
320+
<key>match</key>
321+
<string>(?x)
307322
(?:
308323
(?:^|\G) \s* (?# &apos;\G&apos; is necessary for ST)
309324
((?:&gt;&gt;&gt;|\.\.\.) \s)
310325
)
311326
</string>
312-
<key>captures</key>
313-
<dict>
314-
<key>1</key>
327+
<key>captures</key>
328+
<dict>
329+
<key>1</key>
330+
<dict>
331+
<key>name</key>
332+
<string>keyword.control.flow.python</string>
333+
</dict>
334+
</dict>
335+
</dict>
315336
<dict>
316-
<key>name</key>
317-
<string>keyword.control.flow.python</string>
337+
<key>match</key>
338+
<string>(?:\b(BUG|FIXME|TODO|XXX|NB)\b)</string>
339+
<key>captures</key>
340+
<dict>
341+
<key>1</key>
342+
<dict>
343+
<key>name</key>
344+
<string>string.quoted.docstring.note.python</string>
345+
</dict>
346+
</dict>
318347
</dict>
319-
</dict>
348+
</array>
320349
</dict>
321350
<key>statement-keyword</key>
322351
<dict>

grammars/docstring.inc.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
repository:
3+
docstring-${name}:
4+
patterns:
5+
- name: string.quoted.docstring.python
6+
begin: (${marker})
7+
end: (${marker})
8+
beginCaptures:
9+
'1': {name: punctuation.definition.string.begin.python}
10+
endCaptures:
11+
'1': {name: punctuation.definition.string.end.python}
12+
patterns:
13+
- include: '#docstring-guts-common'
14+
- include: '#docstring-guts-unicode'
15+
16+
- name: string.quoted.docstring.raw.python
17+
begin: ([rR])(${marker})
18+
end: (${marker})
19+
beginCaptures:
20+
'1': {name: storage.type.string.python}
21+
'2': {name: punctuation.definition.string.begin.python}
22+
endCaptures:
23+
'1': {name: punctuation.definition.string.end.python}
24+
patterns:
25+
- include: '#docstring-guts-common'
26+
...

test/comments/comment1.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# XXX foo
22
# FIXME: bug
3-
# NB: !
4-
# don't highlight XXX
3+
# NB: XXXx xXXX but XXX!
4+
# also NB highlight XXX and FIXME.
55

66

77

@@ -16,6 +16,14 @@
1616
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
1717
: comment.line.number-sign.python, source.python
1818
NB : comment.line.note.notation.python, comment.line.number-sign.python, source.python
19-
: ! : comment.line.number-sign.python, source.python
19+
: XXXx xXXX but : comment.line.number-sign.python, source.python
20+
XXX : comment.line.note.notation.python, comment.line.number-sign.python, source.python
21+
! : comment.line.number-sign.python, source.python
2022
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
21-
don't highlight XXX : comment.line.number-sign.python, source.python
23+
also : comment.line.number-sign.python, source.python
24+
NB : comment.line.note.notation.python, comment.line.number-sign.python, source.python
25+
highlight : comment.line.number-sign.python, source.python
26+
XXX : comment.line.note.notation.python, comment.line.number-sign.python, source.python
27+
and : comment.line.number-sign.python, source.python
28+
FIXME : comment.line.note.notation.python, comment.line.number-sign.python, source.python
29+
. : comment.line.number-sign.python, source.python

test/docstrings/note1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
''' foo bar XXX baz '''
2+
3+
def foo():
4+
''' foo FIXME baz '''
5+
6+
7+
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
8+
foo bar : source.python, string.quoted.docstring.python
9+
XXX : source.python, string.quoted.docstring.note.python, string.quoted.docstring.python
10+
baz : source.python, string.quoted.docstring.python
11+
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python
12+
: source.python
13+
def : meta.function.python, source.python, storage.type.function.python
14+
: meta.function.python, source.python
15+
foo : entity.name.function.python, meta.function.python, source.python
16+
( : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.begin.python, source.python
17+
) : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.end.python, source.python
18+
: : meta.function.python, punctuation.section.function.begin.python, source.python
19+
: source.python
20+
''' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.python
21+
foo : source.python, string.quoted.docstring.python
22+
FIXME : source.python, string.quoted.docstring.note.python, string.quoted.docstring.python
23+
baz : source.python, string.quoted.docstring.python
24+
''' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.python

test/strings/note1.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
a = 'XXX FIXME NB TODO'
2+
a = r'XXX FIXME NB TODO'
3+
a = b'XXX FIXME NB TODO'
4+
5+
6+
7+
a : source.python
8+
= : keyword.operator.assignment.python, source.python
9+
: source.python
10+
' : punctuation.definition.string.begin.python, source.python, string.quoted.single.single.python
11+
XXX FIXME NB TODO : source.python, string.quoted.single.single.python
12+
' : punctuation.definition.string.end.python, source.python, string.quoted.single.single.python
13+
a : source.python
14+
= : keyword.operator.assignment.python, source.python
15+
: source.python
16+
r : source.python, storage.type.string.python, string.regexp.quoted.single.python
17+
' : punctuation.definition.string.begin.python, source.python, string.regexp.quoted.single.python
18+
XXX FIXME NB TODO : source.python, string.regexp.quoted.single.python
19+
' : punctuation.definition.string.end.python, source.python, string.regexp.quoted.single.python
20+
a : source.python
21+
= : keyword.operator.assignment.python, source.python
22+
: source.python
23+
b : source.python, storage.type.string.python, string.quoted.single.single.binary.python
24+
' : punctuation.definition.string.begin.python, source.python, string.quoted.single.single.binary.python
25+
XXX FIXME NB TODO : source.python, string.quoted.single.single.binary.python
26+
' : punctuation.definition.string.end.python, source.python, string.quoted.single.single.binary.python

0 commit comments

Comments
 (0)