Skip to content

Commit 5f8eef9

Browse files
committed
Add meta.fstring.python scope.
1 parent 0939372 commit 5f8eef9

31 files changed

+682
-623
lines changed

grammars/MagicPython.cson

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ repository:
828828
"1":
829829
name: "constant.character.format.placeholder.other.python"
830830
endCaptures:
831-
"2":
831+
"1":
832832
name: "constant.character.format.placeholder.other.python"
833833
patterns: [
834834
{
@@ -956,8 +956,14 @@ repository:
956956
patterns: [
957957
{
958958
comment: "empty braces are illegal"
959-
name: "invalid.illegal.brace.python"
960-
match: "({\\s*?})"
959+
match: "({)(\\s*?)(})"
960+
captures:
961+
"1":
962+
name: "constant.character.format.placeholder.other.python"
963+
"2":
964+
name: "invalid.illegal.brace.python"
965+
"3":
966+
name: "constant.character.format.placeholder.other.python"
961967
}
962968
{
963969
name: "constant.character.escape.python"
@@ -4387,6 +4393,7 @@ repository:
43874393
}
43884394
]
43894395
"fstring-fnorm-quoted-single-line":
4396+
name: "meta.fstring.python"
43904397
begin: "(\\b[fF])([bBuU])?((['\"]))"
43914398
end: "(\\3)|((?<!\\\\)\\n)"
43924399
beginCaptures:
@@ -4416,6 +4423,7 @@ repository:
44164423
}
44174424
]
44184425
"fstring-normf-quoted-single-line":
4426+
name: "meta.fstring.python"
44194427
begin: "(\\b[bBuU])([fF])((['\"]))"
44204428
end: "(\\3)|((?<!\\\\)\\n)"
44214429
beginCaptures:
@@ -4445,6 +4453,7 @@ repository:
44454453
}
44464454
]
44474455
"fstring-raw-quoted-single-line":
4456+
name: "meta.fstring.python"
44484457
begin: "(\\b(?:[R][fF]|[fF][R]))((['\"]))"
44494458
end: "(\\2)|((?<!\\\\)\\n)"
44504459
beginCaptures:
@@ -4608,6 +4617,7 @@ repository:
46084617
}
46094618
]
46104619
"fstring-fnorm-quoted-multi-line":
4620+
name: "meta.fstring.python"
46114621
begin: "(\\b[fF])([bBuU])?('''|\"\"\")"
46124622
end: "(\\3)"
46134623
beginCaptures:
@@ -4637,6 +4647,7 @@ repository:
46374647
}
46384648
]
46394649
"fstring-normf-quoted-multi-line":
4650+
name: "meta.fstring.python"
46404651
begin: "(\\b[bBuU])([fF])('''|\"\"\")"
46414652
end: "(\\3)"
46424653
beginCaptures:
@@ -4666,6 +4677,7 @@ repository:
46664677
}
46674678
]
46684679
"fstring-raw-quoted-multi-line":
4680+
name: "meta.fstring.python"
46694681
begin: "(\\b(?:[R][fF]|[fF][R]))('''|\"\"\")"
46704682
end: "(\\2)"
46714683
beginCaptures:

grammars/MagicPython.tmLanguage

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@
12791279
</dict>
12801280
<key>endCaptures</key>
12811281
<dict>
1282-
<key>2</key>
1282+
<key>1</key>
12831283
<dict>
12841284
<key>name</key>
12851285
<string>constant.character.format.placeholder.other.python</string>
@@ -1462,10 +1462,26 @@
14621462
<dict>
14631463
<key>comment</key>
14641464
<string>empty braces are illegal</string>
1465-
<key>name</key>
1466-
<string>invalid.illegal.brace.python</string>
14671465
<key>match</key>
1468-
<string>({\s*?})</string>
1466+
<string>({)(\s*?)(})</string>
1467+
<key>captures</key>
1468+
<dict>
1469+
<key>1</key>
1470+
<dict>
1471+
<key>name</key>
1472+
<string>constant.character.format.placeholder.other.python</string>
1473+
</dict>
1474+
<key>2</key>
1475+
<dict>
1476+
<key>name</key>
1477+
<string>invalid.illegal.brace.python</string>
1478+
</dict>
1479+
<key>3</key>
1480+
<dict>
1481+
<key>name</key>
1482+
<string>constant.character.format.placeholder.other.python</string>
1483+
</dict>
1484+
</dict>
14691485
</dict>
14701486
<dict>
14711487
<key>name</key>
@@ -7697,6 +7713,8 @@ indirectly through syntactic constructs
76977713
</dict>
76987714
<key>fstring-fnorm-quoted-single-line</key>
76997715
<dict>
7716+
<key>name</key>
7717+
<string>meta.fstring.python</string>
77007718
<key>begin</key>
77017719
<string>(\b[fF])([bBuU])?((['"]))</string>
77027720
<key>end</key>
@@ -7754,6 +7772,8 @@ indirectly through syntactic constructs
77547772
</dict>
77557773
<key>fstring-normf-quoted-single-line</key>
77567774
<dict>
7775+
<key>name</key>
7776+
<string>meta.fstring.python</string>
77577777
<key>begin</key>
77587778
<string>(\b[bBuU])([fF])((['"]))</string>
77597779
<key>end</key>
@@ -7811,6 +7831,8 @@ indirectly through syntactic constructs
78117831
</dict>
78127832
<key>fstring-raw-quoted-single-line</key>
78137833
<dict>
7834+
<key>name</key>
7835+
<string>meta.fstring.python</string>
78147836
<key>begin</key>
78157837
<string>(\b(?:[R][fF]|[fF][R]))((['"]))</string>
78167838
<key>end</key>
@@ -8063,6 +8085,8 @@ indirectly through syntactic constructs
80638085
</dict>
80648086
<key>fstring-fnorm-quoted-multi-line</key>
80658087
<dict>
8088+
<key>name</key>
8089+
<string>meta.fstring.python</string>
80668090
<key>begin</key>
80678091
<string>(\b[fF])([bBuU])?('''|""")</string>
80688092
<key>end</key>
@@ -8120,6 +8144,8 @@ indirectly through syntactic constructs
81208144
</dict>
81218145
<key>fstring-normf-quoted-multi-line</key>
81228146
<dict>
8147+
<key>name</key>
8148+
<string>meta.fstring.python</string>
81238149
<key>begin</key>
81248150
<string>(\b[bBuU])([fF])('''|""")</string>
81258151
<key>end</key>
@@ -8177,6 +8203,8 @@ indirectly through syntactic constructs
81778203
</dict>
81788204
<key>fstring-raw-quoted-multi-line</key>
81798205
<dict>
8206+
<key>name</key>
8207+
<string>meta.fstring.python</string>
81808208
<key>begin</key>
81818209
<string>(\b(?:[R][fF]|[fF][R]))('''|""")</string>
81828210
<key>end</key>

grammars/src/MagicPython.syntax.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ repository:
697697
beginCaptures:
698698
'1': {name: constant.character.format.placeholder.other.python}
699699
endCaptures:
700-
'2': {name: constant.character.format.placeholder.other.python}
700+
'1': {name: constant.character.format.placeholder.other.python}
701701
patterns:
702702
- include: '#fstring-terminator-single'
703703
- include: '#f-expression'
@@ -787,8 +787,11 @@ repository:
787787
fstring-formatting-braces:
788788
patterns:
789789
- comment: empty braces are illegal
790-
name: invalid.illegal.brace.python
791-
match: ({\s*?})
790+
match: ({)(\s*?)(})
791+
captures:
792+
'1': {name: constant.character.format.placeholder.other.python}
793+
'2': {name: invalid.illegal.brace.python}
794+
'3': {name: constant.character.format.placeholder.other.python}
792795
- name: constant.character.escape.python
793796
match: ({{|}})
794797

grammars/src/pyfstring.inc.syntax.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
repository:
33
fstring-fnorm-quoted-${line}-line:
4+
name: meta.fstring.python
45
begin: (\b[fF])([bBuU])?(${marker})
56
end: (\3)${guard}
67
beginCaptures:
@@ -20,6 +21,7 @@ repository:
2021
- include: '#fstring-${line}-core'
2122

2223
fstring-normf-quoted-${line}-line:
24+
name: meta.fstring.python
2325
begin: (\b[bBuU])([fF])(${marker})
2426
end: (\3)${guard}
2527
beginCaptures:
@@ -39,6 +41,7 @@ repository:
3941
- include: '#fstring-${line}-core'
4042

4143
fstring-raw-quoted-${line}-line:
44+
name: meta.fstring.python
4245
begin: (\b(?:[R][fF]|[fF][R]))(${marker})
4346
end: (\2)${guard}
4447
beginCaptures:

misc/scopes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ meta.backreference.regexp
6565
meta.character.set.regexp
6666
meta.class.inheritance.python
6767
meta.class.python
68+
meta.fstring.python
6869
meta.function-call.generic.python
6970
meta.function-call.python
7071
meta.function.decorator.python

test/fstrings/comment1.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ def foo(): pass
44

55

66

7-
f : source.python, storage.type.string.python, string.quoted.single.python
8-
' : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
9-
prefix : source.python, string.quoted.single.python
10-
{ : constant.character.format.placeholder.other.python, source.python
11-
10 : constant.numeric.dec.python, source.python
12-
# : source.python
13-
comment : source.python
14-
, : source.python
15-
making : source.python
16-
: source.python
17-
the : source.python
18-
: source.python
19-
string : source.python
20-
: source.python
21-
technically : source.python
22-
: source.python
23-
illegal : source.python
24-
: invalid.illegal.newline.python, source.python
7+
f : meta.fstring.python, source.python, storage.type.string.python, string.quoted.single.python
8+
' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.single.python
9+
prefix : meta.fstring.python, source.python, string.quoted.single.python
10+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
11+
10 : constant.numeric.dec.python, meta.fstring.python, source.python
12+
# : meta.fstring.python, source.python
13+
comment : meta.fstring.python, source.python
14+
, : meta.fstring.python, source.python
15+
making : meta.fstring.python, source.python
16+
: meta.fstring.python, source.python
17+
the : meta.fstring.python, source.python
18+
: meta.fstring.python, source.python
19+
string : meta.fstring.python, source.python
20+
: meta.fstring.python, source.python
21+
technically : meta.fstring.python, source.python
22+
: meta.fstring.python, source.python
23+
illegal : meta.fstring.python, source.python
24+
: invalid.illegal.newline.python, meta.fstring.python, source.python
2525
def : meta.function.python, source.python, storage.type.function.python
2626
: meta.function.python, source.python
2727
foo : entity.name.function.python, meta.function.python, source.python

test/fstrings/comment2.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66

77

8-
f : source.python, storage.type.string.python, string.quoted.multi.python
9-
''' : punctuation.definition.string.begin.python, source.python, string.quoted.multi.python
10-
: source.python, string.quoted.multi.python
11-
prefix : source.python, string.quoted.multi.python
12-
{ : constant.character.format.placeholder.other.python, source.python
13-
10 : constant.numeric.dec.python, source.python
14-
: source.python
15-
+ : keyword.operator.arithmetic.python, source.python
16-
: source.python
17-
32 : constant.numeric.dec.python, source.python
18-
} : constant.character.format.placeholder.other.python, source.python
19-
suffix : source.python, string.quoted.multi.python
20-
''' : punctuation.definition.string.end.python, source.python, string.quoted.multi.python
8+
f : meta.fstring.python, source.python, storage.type.string.python, string.quoted.multi.python
9+
''' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.multi.python
10+
: meta.fstring.python, source.python, string.quoted.multi.python
11+
prefix : meta.fstring.python, source.python, string.quoted.multi.python
12+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
13+
10 : constant.numeric.dec.python, meta.fstring.python, source.python
14+
: meta.fstring.python, source.python
15+
+ : keyword.operator.arithmetic.python, meta.fstring.python, source.python
16+
: meta.fstring.python, source.python
17+
32 : constant.numeric.dec.python, meta.fstring.python, source.python
18+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
19+
suffix : meta.fstring.python, source.python, string.quoted.multi.python
20+
''' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.quoted.multi.python

test/fstrings/comment3.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66

77

8-
f : source.python, storage.type.string.python, string.quoted.multi.python
9-
''' : punctuation.definition.string.begin.python, source.python, string.quoted.multi.python
10-
: source.python, string.quoted.multi.python
11-
prefix : source.python, string.quoted.multi.python
12-
{ : constant.character.format.placeholder.other.python, source.python
13-
10 : constant.numeric.dec.python, source.python
14-
# : source.python
15-
comment : source.python
16-
: source.python
17-
is : keyword.operator.logical.python, source.python
18-
: source.python
19-
still : source.python
20-
: source.python
21-
illegal : source.python
22-
: source.python
23-
here : source.python
24-
: source.python
25-
} : constant.character.format.placeholder.other.python, source.python
26-
suffix : source.python, string.quoted.multi.python
27-
''' : punctuation.definition.string.end.python, source.python, string.quoted.multi.python
8+
f : meta.fstring.python, source.python, storage.type.string.python, string.quoted.multi.python
9+
''' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.multi.python
10+
: meta.fstring.python, source.python, string.quoted.multi.python
11+
prefix : meta.fstring.python, source.python, string.quoted.multi.python
12+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
13+
10 : constant.numeric.dec.python, meta.fstring.python, source.python
14+
# : meta.fstring.python, source.python
15+
comment : meta.fstring.python, source.python
16+
: meta.fstring.python, source.python
17+
is : keyword.operator.logical.python, meta.fstring.python, source.python
18+
: meta.fstring.python, source.python
19+
still : meta.fstring.python, source.python
20+
: meta.fstring.python, source.python
21+
illegal : meta.fstring.python, source.python
22+
: meta.fstring.python, source.python
23+
here : meta.fstring.python, source.python
24+
: meta.fstring.python, source.python
25+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
26+
suffix : meta.fstring.python, source.python, string.quoted.multi.python
27+
''' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.quoted.multi.python

0 commit comments

Comments
 (0)