Skip to content

Commit 0580d7e

Browse files
committed
Add a rule for illegal empty braces.
1 parent b93c9a4 commit 0580d7e

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

grammars/MagicPython.cson

+5
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,11 @@ repository:
870870
{
871871
include: "#string-line-continuation"
872872
}
873+
{
874+
comment: "empty braces are illegal"
875+
name: "invalid.illegal.brace.python"
876+
match: "({\\s*?})"
877+
}
873878
{
874879
name: "constant.character.escape.python"
875880
match: "({{|}})"

grammars/MagicPython.tmLanguage

+8
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,14 @@
14061406
<key>include</key>
14071407
<string>#string-line-continuation</string>
14081408
</dict>
1409+
<dict>
1410+
<key>comment</key>
1411+
<string>empty braces are illegal</string>
1412+
<key>name</key>
1413+
<string>invalid.illegal.brace.python</string>
1414+
<key>match</key>
1415+
<string>({\s*?})</string>
1416+
</dict>
14091417
<dict>
14101418
<key>name</key>
14111419
<string>constant.character.escape.python</string>

grammars/src/MagicPython.syntax.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,16 @@ repository:
615615
- include: '#escape-sequence-unicode'
616616
- include: '#escape-sequence'
617617
- include: '#string-line-continuation'
618+
- comment: empty braces are illegal
619+
name: invalid.illegal.brace.python
620+
match: ({\s*?})
618621
- name: constant.character.escape.python
619622
match: ({{|}})
620623
- name: invalid.illegal.brace.python
621624
match: (}(?!}))
622625

626+
627+
623628
fstring-illegal-single-brace:
624629
comment: it is illegal to have a multiline brace inside a single-line
625630
string

test/fstrings/empty1.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
f"{} { }"
2+
f"""{}
3+
{ }
4+
"""
5+
6+
7+
8+
9+
10+
f : source.python, storage.type.string.python, string.quoted.single.python
11+
" : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
12+
{} : invalid.illegal.brace.python, source.python
13+
: source.python, string.quoted.single.python
14+
{ } : invalid.illegal.brace.python, source.python
15+
" : punctuation.definition.string.end.python, source.python, string.quoted.single.python
16+
f : source.python, storage.type.string.python, string.quoted.multi.python
17+
""" : punctuation.definition.string.begin.python, source.python, string.quoted.multi.python
18+
{} : invalid.illegal.brace.python, source.python
19+
: source.python, string.quoted.multi.python
20+
{ } : invalid.illegal.brace.python, source.python
21+
: source.python, string.quoted.multi.python
22+
""" : punctuation.definition.string.end.python, source.python, string.quoted.multi.python

0 commit comments

Comments
 (0)