Skip to content

Commit f96a090

Browse files
committed
Fix format string placeholders
This commit... 1. separates double- and single-quoted format string contexts to enable quotation marks in format-strings. 2. scopes format-spec as python 3. restricts format placeholders to brace+digit `{\d+}` to avoid false positives
1 parent 5222ea6 commit f96a090

File tree

2 files changed

+152
-41
lines changed

2 files changed

+152
-41
lines changed

PowerShell.sublime-syntax

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ contexts:
315315
- meta_scope: meta.string.interpolated.powershell string.quoted.double.powershell meta.function-call.powershell variable.function.powershell
316316
- match: '{{double_quote}}{2}'
317317
scope: constant.character.escape.powershell
318-
- include: escape-sequences
319318
- match: '{{double_quote}}'
320319
scope: punctuation.definition.string.end.powershell
321320
pop: 1
321+
- include: escape-sequences
322322
- include: string-interpolations
323323
- include: path-punctuation
324324

@@ -1043,7 +1043,7 @@ contexts:
10431043
- match: '{{single_quote}}'
10441044
scope: punctuation.definition.string.end.powershell
10451045
pop: 1
1046-
- include: string-placeholders
1046+
- include: single-quoted-string-placeholders
10471047

10481048
double-quoted-strings:
10491049
- match: '{{double_quote}}'
@@ -1055,12 +1055,12 @@ contexts:
10551055
- meta_scope: meta.string.interpolated.powershell string.quoted.double.powershell
10561056
- match: '{{double_quote}}{2}'
10571057
scope: constant.character.escape.powershell
1058-
- include: escape-sequences
10591058
- match: '{{double_quote}}'
10601059
scope: punctuation.definition.string.end.powershell
10611060
pop: 1
1061+
- include: escape-sequences
10621062
- include: string-interpolations
1063-
- include: string-placeholders
1063+
- include: double-quoted-string-placeholders
10641064

10651065
single-quoted-heredoc-strings:
10661066
- match: \@{{single_quote}}(?=$)
@@ -1088,7 +1088,7 @@ contexts:
10881088
pop: 1
10891089
- match: '{{single_quote}}{2}'
10901090
scope: constant.character.escape.powershell
1091-
- include: string-placeholders
1091+
- include: single-quoted-string-placeholders
10921092

10931093
double-quoted-heredoc-strings:
10941094
- match: \@{{double_quote}}(?=$)
@@ -1104,8 +1104,8 @@ contexts:
11041104
scope: punctuation.definition.string.end.powershell
11051105
pop: 1
11061106
- include: escape-sequences
1107-
- include: string-placeholders
11081107
- include: string-interpolations
1108+
- include: double-quoted-string-placeholders
11091109

11101110
inside-double-quoted-heredoc-string.syntax:
11111111
- meta_include_prototype: false
@@ -1137,20 +1137,84 @@ contexts:
11371137
- include: variables-without-members
11381138
- include: immediately-pop
11391139

1140-
string-placeholders:
1141-
- match: \{
1142-
scope: punctuation.definition.placeholder.begin.powershell
1143-
push: inside-string-placeholder
1140+
double-quoted-string-placeholders:
1141+
- match: \{\{|\}\}
1142+
scope: constant.character.escape.powershell
1143+
- match: (\{)(\d+)
1144+
captures:
1145+
1: punctuation.definition.placeholder.begin.powershell
1146+
2: meta.number.integer.decimal.powershell constant.numeric.value.powershell
1147+
push: inside-double-quoted-string-placeholder
11441148

1145-
inside-string-placeholder:
1149+
inside-double-quoted-string-placeholder:
11461150
- meta_include_prototype: false
11471151
- meta_scope: constant.other.placeholder.powershell
11481152
- match: \}
11491153
scope: punctuation.definition.placeholder.end.powershell
11501154
pop: 1
1151-
- match: (?={{single_quote}}|{{double_quote}})
1155+
- match: (?={{double_quote}})
11521156
pop: 1
1153-
- match: '[:,;]'
1157+
- match: ':'
1158+
scope: punctuation.separator.format-spec.powershell
1159+
push: inside-double-quoted-string-placeholder-formatspec
1160+
- include: string-placeholder-separators
1161+
- include: string-placeholder-numbers
1162+
1163+
inside-double-quoted-string-placeholder-formatspec:
1164+
- meta_include_prototype: false
1165+
- meta_content_scope: meta.format-spec.powershell constant.other.format-spec.powershell
1166+
- match: \}
1167+
scope: punctuation.definition.placeholder.end.powershell
1168+
pop: 2
1169+
- match: '{{double_quote}}{2}'
1170+
scope: constant.character.escape.powershell
1171+
- match: (?={{double_quote}})
1172+
pop: 2
1173+
- include: escape-sequences
1174+
- include: string-placeholder-separators
1175+
1176+
single-quoted-string-placeholders:
1177+
- match: \{\{|\}\}
1178+
scope: constant.character.escape.powershell
1179+
- match: (\{)(\d+)
1180+
captures:
1181+
1: punctuation.definition.placeholder.begin.powershell
1182+
2: meta.number.integer.decimal.powershell constant.numeric.value.powershell
1183+
push: inside-single-quoted-string-placeholder
1184+
1185+
inside-single-quoted-string-placeholder:
1186+
- meta_include_prototype: false
1187+
- meta_scope: constant.other.placeholder.powershell
1188+
- match: \}
1189+
scope: punctuation.definition.placeholder.end.powershell
1190+
pop: 1
1191+
- match: (?={{single_quote}})
1192+
pop: 1
1193+
- match: ':'
1194+
scope: punctuation.separator.format-spec.powershell
1195+
push: inside-single-quoted-string-placeholder-formatspec
1196+
- include: string-placeholder-separators
1197+
- include: string-placeholder-numbers
1198+
1199+
inside-single-quoted-string-placeholder-formatspec:
1200+
- meta_include_prototype: false
1201+
- meta_content_scope: meta.format-spec.powershell constant.other.format-spec.powershell
1202+
- match: \}
1203+
scope: punctuation.definition.placeholder.end.powershell
1204+
pop: 2
1205+
- match: '{{single_quote}}{2}'
1206+
scope: constant.character.escape.powershell
1207+
- match: (?={{single_quote}})
1208+
pop: 2
1209+
- include: escape-sequences
1210+
- include: string-placeholder-separators
1211+
1212+
string-placeholder-numbers:
1213+
- match: \d+
1214+
scope: meta.number.integer.decimal.powershell constant.numeric.value.powershell
1215+
1216+
string-placeholder-separators:
1217+
- match: '[,;]'
11541218
scope: punctuation.separator.powershell
11551219

11561220
string-wildcards:

0 commit comments

Comments
 (0)