Skip to content

Commit abb3cd7

Browse files
committed
Add an extra scope for f-strings: string.interpolated.python
This way f-strings may be highlighted differently from regular Python strings.
1 parent f5c72f9 commit abb3cd7

37 files changed

+435
-423
lines changed

grammars/MagicPython.cson

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,7 @@ repository:
39553955
}
39563956
]
39573957
"fregexp-single-one-line":
3958-
name: "string.regexp.quoted.single.python"
3958+
name: "string.regexp.quoted.single.python string.interpolated.python"
39593959
begin: "\\b(([uU]r)|([fF]r)|(r[fF]?))(\\')"
39603960
end: "(\\')|(?<!\\\\)(\\n)"
39613961
beginCaptures:
@@ -3978,7 +3978,7 @@ repository:
39783978
}
39793979
]
39803980
"fregexp-single-three-line":
3981-
name: "string.regexp.quoted.multi.python"
3981+
name: "string.regexp.quoted.multi.python string.interpolated.python"
39823982
begin: "\\b(([uU]r)|([fF]r)|(r[fF]?))(\\'\\'\\')"
39833983
end: "(\\'\\'\\')"
39843984
beginCaptures:
@@ -4001,7 +4001,7 @@ repository:
40014001
}
40024002
]
40034003
"fregexp-double-one-line":
4004-
name: "string.regexp.quoted.single.python"
4004+
name: "string.regexp.quoted.single.python string.interpolated.python"
40054005
begin: "\\b(([uU]r)|([fF]r)|(r[fF]?))(\")"
40064006
end: "(\")|(?<!\\\\)(\\n)"
40074007
beginCaptures:
@@ -4024,7 +4024,7 @@ repository:
40244024
}
40254025
]
40264026
"fregexp-double-three-line":
4027-
name: "string.regexp.quoted.multi.python"
4027+
name: "string.regexp.quoted.multi.python string.interpolated.python"
40284028
begin: "\\b(([uU]r)|([fF]r)|(r[fF]?))(\"\"\")"
40294029
end: "(\"\"\")"
40304030
beginCaptures:
@@ -4400,14 +4400,14 @@ repository:
44004400
end: "(\\3)|((?<!\\\\)\\n)"
44014401
beginCaptures:
44024402
"1":
4403-
name: "string.quoted.single.python storage.type.string.python"
4403+
name: "string.quoted.single.python string.interpolated.python storage.type.string.python"
44044404
"2":
44054405
name: "invalid.illegal.prefix.python"
44064406
"3":
4407-
name: "string.quoted.single.python punctuation.definition.string.begin.python"
4407+
name: "string.quoted.single.python string.interpolated.python punctuation.definition.string.begin.python"
44084408
endCaptures:
44094409
"1":
4410-
name: "string.quoted.single.python punctuation.definition.string.end.python"
4410+
name: "string.quoted.single.python string.interpolated.python punctuation.definition.string.end.python"
44114411
"2":
44124412
name: "invalid.illegal.newline.python"
44134413
patterns: [
@@ -4432,12 +4432,12 @@ repository:
44324432
"1":
44334433
name: "invalid.illegal.prefix.python"
44344434
"2":
4435-
name: "string.quoted.single.python storage.type.string.python"
4435+
name: "string.quoted.single.python string.interpolated.python storage.type.string.python"
44364436
"3":
44374437
name: "string.quoted.single.python punctuation.definition.string.begin.python"
44384438
endCaptures:
44394439
"1":
4440-
name: "string.quoted.single.python punctuation.definition.string.end.python"
4440+
name: "string.quoted.single.python string.interpolated.python punctuation.definition.string.end.python"
44414441
"2":
44424442
name: "invalid.illegal.newline.python"
44434443
patterns: [
@@ -4460,12 +4460,12 @@ repository:
44604460
end: "(\\2)|((?<!\\\\)\\n)"
44614461
beginCaptures:
44624462
"1":
4463-
name: "string.quoted.raw.single.python storage.type.string.python"
4463+
name: "string.quoted.raw.single.python string.interpolated.python storage.type.string.python"
44644464
"2":
44654465
name: "string.quoted.raw.single.python punctuation.definition.string.begin.python"
44664466
endCaptures:
44674467
"1":
4468-
name: "string.quoted.raw.single.python punctuation.definition.string.end.python"
4468+
name: "string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python"
44694469
"2":
44704470
name: "invalid.illegal.newline.python"
44714471
patterns: [
@@ -4483,7 +4483,7 @@ repository:
44834483
}
44844484
]
44854485
"fstring-single-core":
4486-
name: "string.quoted.single.python"
4486+
name: "string.quoted.single.python string.interpolated.python"
44874487
match: '''
44884488
(?x)
44894489
(.+?)
@@ -4504,7 +4504,7 @@ repository:
45044504
45054505
'''
45064506
"fstring-raw-single-core":
4507-
name: "string.quoted.raw.single.python"
4507+
name: "string.quoted.raw.single.python string.interpolated.python"
45084508
match: '''
45094509
(?x)
45104510
(.+?)
@@ -4624,14 +4624,14 @@ repository:
46244624
end: "(\\3)"
46254625
beginCaptures:
46264626
"1":
4627-
name: "string.quoted.multi.python storage.type.string.python"
4627+
name: "string.quoted.multi.python string.interpolated.python storage.type.string.python"
46284628
"2":
46294629
name: "invalid.illegal.prefix.python"
46304630
"3":
4631-
name: "string.quoted.multi.python punctuation.definition.string.begin.python"
4631+
name: "string.quoted.multi.python string.interpolated.python punctuation.definition.string.begin.python"
46324632
endCaptures:
46334633
"1":
4634-
name: "string.quoted.multi.python punctuation.definition.string.end.python"
4634+
name: "string.quoted.multi.python string.interpolated.python punctuation.definition.string.end.python"
46354635
"2":
46364636
name: "invalid.illegal.newline.python"
46374637
patterns: [
@@ -4656,12 +4656,12 @@ repository:
46564656
"1":
46574657
name: "invalid.illegal.prefix.python"
46584658
"2":
4659-
name: "string.quoted.multi.python storage.type.string.python"
4659+
name: "string.quoted.multi.python string.interpolated.python storage.type.string.python"
46604660
"3":
46614661
name: "string.quoted.multi.python punctuation.definition.string.begin.python"
46624662
endCaptures:
46634663
"1":
4664-
name: "string.quoted.multi.python punctuation.definition.string.end.python"
4664+
name: "string.quoted.multi.python string.interpolated.python punctuation.definition.string.end.python"
46654665
"2":
46664666
name: "invalid.illegal.newline.python"
46674667
patterns: [
@@ -4684,12 +4684,12 @@ repository:
46844684
end: "(\\2)"
46854685
beginCaptures:
46864686
"1":
4687-
name: "string.quoted.raw.multi.python storage.type.string.python"
4687+
name: "string.quoted.raw.multi.python string.interpolated.python storage.type.string.python"
46884688
"2":
46894689
name: "string.quoted.raw.multi.python punctuation.definition.string.begin.python"
46904690
endCaptures:
46914691
"1":
4692-
name: "string.quoted.raw.multi.python punctuation.definition.string.end.python"
4692+
name: "string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python"
46934693
"2":
46944694
name: "invalid.illegal.newline.python"
46954695
patterns: [
@@ -4707,7 +4707,7 @@ repository:
47074707
}
47084708
]
47094709
"fstring-multi-core":
4710-
name: "string.quoted.multi.python"
4710+
name: "string.quoted.multi.python string.interpolated.python"
47114711
match: '''
47124712
(?x)
47134713
(.+?)
@@ -4728,7 +4728,7 @@ repository:
47284728
47294729
'''
47304730
"fstring-raw-multi-core":
4731-
name: "string.quoted.raw.multi.python"
4731+
name: "string.quoted.raw.multi.python string.interpolated.python"
47324732
match: '''
47334733
(?x)
47344734
(.+?)

grammars/MagicPython.tmLanguage

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6908,7 +6908,7 @@ indirectly through syntactic constructs
69086908
<key>fregexp-single-one-line</key>
69096909
<dict>
69106910
<key>name</key>
6911-
<string>string.regexp.quoted.single.python</string>
6911+
<string>string.regexp.quoted.single.python string.interpolated.python</string>
69126912
<key>begin</key>
69136913
<string>\b(([uU]r)|([fF]r)|(r[fF]?))(\')</string>
69146914
<key>end</key>
@@ -6960,7 +6960,7 @@ indirectly through syntactic constructs
69606960
<key>fregexp-single-three-line</key>
69616961
<dict>
69626962
<key>name</key>
6963-
<string>string.regexp.quoted.multi.python</string>
6963+
<string>string.regexp.quoted.multi.python string.interpolated.python</string>
69646964
<key>begin</key>
69656965
<string>\b(([uU]r)|([fF]r)|(r[fF]?))(\'\'\')</string>
69666966
<key>end</key>
@@ -7012,7 +7012,7 @@ indirectly through syntactic constructs
70127012
<key>fregexp-double-one-line</key>
70137013
<dict>
70147014
<key>name</key>
7015-
<string>string.regexp.quoted.single.python</string>
7015+
<string>string.regexp.quoted.single.python string.interpolated.python</string>
70167016
<key>begin</key>
70177017
<string>\b(([uU]r)|([fF]r)|(r[fF]?))(")</string>
70187018
<key>end</key>
@@ -7064,7 +7064,7 @@ indirectly through syntactic constructs
70647064
<key>fregexp-double-three-line</key>
70657065
<dict>
70667066
<key>name</key>
7067-
<string>string.regexp.quoted.multi.python</string>
7067+
<string>string.regexp.quoted.multi.python string.interpolated.python</string>
70687068
<key>begin</key>
70697069
<string>\b(([uU]r)|([fF]r)|(r[fF]?))(""")</string>
70707070
<key>end</key>
@@ -7726,7 +7726,7 @@ indirectly through syntactic constructs
77267726
<key>1</key>
77277727
<dict>
77287728
<key>name</key>
7729-
<string>string.quoted.single.python storage.type.string.python</string>
7729+
<string>string.quoted.single.python string.interpolated.python storage.type.string.python</string>
77307730
</dict>
77317731
<key>2</key>
77327732
<dict>
@@ -7736,15 +7736,15 @@ indirectly through syntactic constructs
77367736
<key>3</key>
77377737
<dict>
77387738
<key>name</key>
7739-
<string>string.quoted.single.python punctuation.definition.string.begin.python</string>
7739+
<string>string.quoted.single.python string.interpolated.python punctuation.definition.string.begin.python</string>
77407740
</dict>
77417741
</dict>
77427742
<key>endCaptures</key>
77437743
<dict>
77447744
<key>1</key>
77457745
<dict>
77467746
<key>name</key>
7747-
<string>string.quoted.single.python punctuation.definition.string.end.python</string>
7747+
<string>string.quoted.single.python string.interpolated.python punctuation.definition.string.end.python</string>
77487748
</dict>
77497749
<key>2</key>
77507750
<dict>
@@ -7790,7 +7790,7 @@ indirectly through syntactic constructs
77907790
<key>2</key>
77917791
<dict>
77927792
<key>name</key>
7793-
<string>string.quoted.single.python storage.type.string.python</string>
7793+
<string>string.quoted.single.python string.interpolated.python storage.type.string.python</string>
77947794
</dict>
77957795
<key>3</key>
77967796
<dict>
@@ -7803,7 +7803,7 @@ indirectly through syntactic constructs
78037803
<key>1</key>
78047804
<dict>
78057805
<key>name</key>
7806-
<string>string.quoted.single.python punctuation.definition.string.end.python</string>
7806+
<string>string.quoted.single.python string.interpolated.python punctuation.definition.string.end.python</string>
78077807
</dict>
78087808
<key>2</key>
78097809
<dict>
@@ -7844,7 +7844,7 @@ indirectly through syntactic constructs
78447844
<key>1</key>
78457845
<dict>
78467846
<key>name</key>
7847-
<string>string.quoted.raw.single.python storage.type.string.python</string>
7847+
<string>string.quoted.raw.single.python string.interpolated.python storage.type.string.python</string>
78487848
</dict>
78497849
<key>2</key>
78507850
<dict>
@@ -7857,7 +7857,7 @@ indirectly through syntactic constructs
78577857
<key>1</key>
78587858
<dict>
78597859
<key>name</key>
7860-
<string>string.quoted.raw.single.python punctuation.definition.string.end.python</string>
7860+
<string>string.quoted.raw.single.python string.interpolated.python punctuation.definition.string.end.python</string>
78617861
</dict>
78627862
<key>2</key>
78637863
<dict>
@@ -7888,7 +7888,7 @@ indirectly through syntactic constructs
78887888
<key>fstring-single-core</key>
78897889
<dict>
78907890
<key>name</key>
7891-
<string>string.quoted.single.python</string>
7891+
<string>string.quoted.single.python string.interpolated.python</string>
78927892
<key>match</key>
78937893
<string>(?x)
78947894
(.+?)
@@ -7911,7 +7911,7 @@ indirectly through syntactic constructs
79117911
<key>fstring-raw-single-core</key>
79127912
<dict>
79137913
<key>name</key>
7914-
<string>string.quoted.raw.single.python</string>
7914+
<string>string.quoted.raw.single.python string.interpolated.python</string>
79157915
<key>match</key>
79167916
<string>(?x)
79177917
(.+?)
@@ -8098,7 +8098,7 @@ indirectly through syntactic constructs
80988098
<key>1</key>
80998099
<dict>
81008100
<key>name</key>
8101-
<string>string.quoted.multi.python storage.type.string.python</string>
8101+
<string>string.quoted.multi.python string.interpolated.python storage.type.string.python</string>
81028102
</dict>
81038103
<key>2</key>
81048104
<dict>
@@ -8108,15 +8108,15 @@ indirectly through syntactic constructs
81088108
<key>3</key>
81098109
<dict>
81108110
<key>name</key>
8111-
<string>string.quoted.multi.python punctuation.definition.string.begin.python</string>
8111+
<string>string.quoted.multi.python string.interpolated.python punctuation.definition.string.begin.python</string>
81128112
</dict>
81138113
</dict>
81148114
<key>endCaptures</key>
81158115
<dict>
81168116
<key>1</key>
81178117
<dict>
81188118
<key>name</key>
8119-
<string>string.quoted.multi.python punctuation.definition.string.end.python</string>
8119+
<string>string.quoted.multi.python string.interpolated.python punctuation.definition.string.end.python</string>
81208120
</dict>
81218121
<key>2</key>
81228122
<dict>
@@ -8162,7 +8162,7 @@ indirectly through syntactic constructs
81628162
<key>2</key>
81638163
<dict>
81648164
<key>name</key>
8165-
<string>string.quoted.multi.python storage.type.string.python</string>
8165+
<string>string.quoted.multi.python string.interpolated.python storage.type.string.python</string>
81668166
</dict>
81678167
<key>3</key>
81688168
<dict>
@@ -8175,7 +8175,7 @@ indirectly through syntactic constructs
81758175
<key>1</key>
81768176
<dict>
81778177
<key>name</key>
8178-
<string>string.quoted.multi.python punctuation.definition.string.end.python</string>
8178+
<string>string.quoted.multi.python string.interpolated.python punctuation.definition.string.end.python</string>
81798179
</dict>
81808180
<key>2</key>
81818181
<dict>
@@ -8216,7 +8216,7 @@ indirectly through syntactic constructs
82168216
<key>1</key>
82178217
<dict>
82188218
<key>name</key>
8219-
<string>string.quoted.raw.multi.python storage.type.string.python</string>
8219+
<string>string.quoted.raw.multi.python string.interpolated.python storage.type.string.python</string>
82208220
</dict>
82218221
<key>2</key>
82228222
<dict>
@@ -8229,7 +8229,7 @@ indirectly through syntactic constructs
82298229
<key>1</key>
82308230
<dict>
82318231
<key>name</key>
8232-
<string>string.quoted.raw.multi.python punctuation.definition.string.end.python</string>
8232+
<string>string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python</string>
82338233
</dict>
82348234
<key>2</key>
82358235
<dict>
@@ -8260,7 +8260,7 @@ indirectly through syntactic constructs
82608260
<key>fstring-multi-core</key>
82618261
<dict>
82628262
<key>name</key>
8263-
<string>string.quoted.multi.python</string>
8263+
<string>string.quoted.multi.python string.interpolated.python</string>
82648264
<key>match</key>
82658265
<string>(?x)
82668266
(.+?)
@@ -8283,7 +8283,7 @@ indirectly through syntactic constructs
82838283
<key>fstring-raw-multi-core</key>
82848284
<dict>
82858285
<key>name</key>
8286-
<string>string.quoted.raw.multi.python</string>
8286+
<string>string.quoted.raw.multi.python string.interpolated.python</string>
82878287
<key>match</key>
82888288
<string>(?x)
82898289
(.+?)

grammars/src/MagicPython.syntax.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ repository:
139139
- file: 'regexp.wrapper.syntax.yaml'
140140
vars:
141141
scopename: string.regexp.quoted.single.python
142+
string.interpolated.python
142143
prefix: 'single-one-'
143144
basename: 'fregexp'
144145
nested: ''
@@ -149,6 +150,7 @@ repository:
149150
- file: 'regexp.wrapper.syntax.yaml'
150151
vars:
151152
scopename: string.regexp.quoted.multi.python
153+
string.interpolated.python
152154
prefix: 'single-three-'
153155
basename: 'fregexp'
154156
nested: "- include: '#comments-string-single-three'"
@@ -159,6 +161,7 @@ repository:
159161
- file: 'regexp.wrapper.syntax.yaml'
160162
vars:
161163
scopename: string.regexp.quoted.single.python
164+
string.interpolated.python
162165
prefix: 'double-one-'
163166
basename: 'fregexp'
164167
nested: ''
@@ -169,6 +172,7 @@ repository:
169172
- file: 'regexp.wrapper.syntax.yaml'
170173
vars:
171174
scopename: string.regexp.quoted.multi.python
175+
string.interpolated.python
172176
prefix: 'double-three-'
173177
basename: 'fregexp'
174178
nested: "- include: '#comments-string-double-three'"

0 commit comments

Comments
 (0)