Skip to content

Commit d3f7a83

Browse files
committed
Handle trailing whitespace after decorators.
1 parent 7906532 commit d3f7a83

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

Diff for: grammars/MagicPython.cson

+3-1
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,9 @@ repository:
14391439
'''
14401440
end: '''
14411441
(?x)
1442-
( \\) ) (?: (?=\\s*\\#|$) | (.*$) )
1442+
( \\) )
1443+
# trailing whitespace and comments are legal
1444+
(?: (.*?) (?=\\s*(?:\\#|$)) )
14431445
| (?=\\n|\\#)
14441446
14451447
'''

Diff for: grammars/MagicPython.tmLanguage

+3-1
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,9 @@
22612261
</string>
22622262
<key>end</key>
22632263
<string>(?x)
2264-
( \) ) (?: (?=\s*\#|$) | (.*$) )
2264+
( \) )
2265+
# trailing whitespace and comments are legal
2266+
(?: (.*?) (?=\s*(?:\#|$)) )
22652267
| (?=\n|\#)
22662268
</string>
22672269
<key>beginCaptures</key>

Diff for: grammars/src/MagicPython.syntax.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,9 @@ repository:
10811081
(@) \s* (?=[[:alpha:]_]\w*)
10821082
end: |
10831083
(?x)
1084-
( \) ) (?: (?=\s*\#|$) | (.*$) )
1084+
( \) )
1085+
# trailing whitespace and comments are legal
1086+
(?: (.*?) (?=\s*(?:\#|$)) )
10851087
| (?=\n|\#)
10861088
beginCaptures:
10871089
'1': {name: entity.name.function.decorator.python}

Diff for: test/functions/decorators7.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# this is testing trailing whitespace after the decorator
2+
# DO NOT DELETE TRAILING WHITESTAPCE IN THIS FILE
3+
@foo
4+
@foo()
5+
@bar
6+
@bar()
7+
@bar() illegal # legal
8+
@bar():
9+
def baz(): pass
10+
11+
12+
13+
14+
15+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
16+
this is testing trailing whitespace after the decorator : comment.line.number-sign.python, source.python
17+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
18+
DO NOT DELETE TRAILING WHITESTAPCE IN THIS FILE : comment.line.number-sign.python, source.python
19+
@ : entity.name.function.decorator.python, meta.function.decorator.python, source.python
20+
foo : entity.name.function.decorator.python, meta.function.decorator.python, source.python
21+
: meta.function.decorator.python, source.python
22+
@ : entity.name.function.decorator.python, meta.function.decorator.python, source.python
23+
foo : entity.name.function.decorator.python, meta.function.decorator.python, source.python
24+
( : meta.function.decorator.python, punctuation.definition.arguments.begin.python, source.python
25+
) : meta.function.decorator.python, punctuation.definition.arguments.end.python, source.python
26+
: source.python
27+
@ : entity.name.function.decorator.python, meta.function.decorator.python, source.python
28+
bar : entity.name.function.decorator.python, meta.function.decorator.python, source.python
29+
: meta.function.decorator.python, source.python
30+
@ : entity.name.function.decorator.python, meta.function.decorator.python, source.python
31+
bar : entity.name.function.decorator.python, meta.function.decorator.python, source.python
32+
( : meta.function.decorator.python, punctuation.definition.arguments.begin.python, source.python
33+
) : meta.function.decorator.python, punctuation.definition.arguments.end.python, source.python
34+
: source.python
35+
@ : entity.name.function.decorator.python, meta.function.decorator.python, source.python
36+
bar : entity.name.function.decorator.python, meta.function.decorator.python, source.python
37+
( : meta.function.decorator.python, punctuation.definition.arguments.begin.python, source.python
38+
) : meta.function.decorator.python, punctuation.definition.arguments.end.python, source.python
39+
illegal : invalid.illegal.decorator.python, meta.function.decorator.python, source.python
40+
: source.python
41+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
42+
legal : comment.line.number-sign.python, source.python
43+
@ : entity.name.function.decorator.python, meta.function.decorator.python, source.python
44+
bar : entity.name.function.decorator.python, meta.function.decorator.python, source.python
45+
( : meta.function.decorator.python, punctuation.definition.arguments.begin.python, source.python
46+
) : meta.function.decorator.python, punctuation.definition.arguments.end.python, source.python
47+
: : invalid.illegal.decorator.python, meta.function.decorator.python, source.python
48+
: source.python
49+
def : meta.function.python, source.python, storage.type.function.python
50+
: meta.function.python, source.python
51+
baz : entity.name.function.python, meta.function.python, source.python
52+
( : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.begin.python, source.python
53+
) : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.end.python, source.python
54+
: : meta.function.python, punctuation.section.function.begin.python, source.python
55+
: source.python
56+
pass : keyword.control.flow.python, source.python
57+

0 commit comments

Comments
 (0)