Skip to content

Commit 8bcaa62

Browse files
deathaxemichaelblyons
authored andcommitted
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 e80d590 commit 8bcaa62

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

@@ -1051,7 +1051,7 @@ contexts:
10511051
- match: '{{single_quote}}'
10521052
scope: punctuation.definition.string.end.powershell
10531053
pop: 1
1054-
- include: string-placeholders
1054+
- include: single-quoted-string-placeholders
10551055

10561056
double-quoted-strings:
10571057
- match: '{{double_quote}}'
@@ -1063,12 +1063,12 @@ contexts:
10631063
- meta_scope: meta.string.interpolated.powershell string.quoted.double.powershell
10641064
- match: '{{double_quote}}{2}'
10651065
scope: constant.character.escape.powershell
1066-
- include: escape-sequences
10671066
- match: '{{double_quote}}'
10681067
scope: punctuation.definition.string.end.powershell
10691068
pop: 1
1069+
- include: escape-sequences
10701070
- include: string-interpolations
1071-
- include: string-placeholders
1071+
- include: double-quoted-string-placeholders
10721072

10731073
single-quoted-heredoc-strings:
10741074
- match: \@{{single_quote}}(?=$)
@@ -1096,7 +1096,7 @@ contexts:
10961096
pop: 1
10971097
- match: '{{single_quote}}{2}'
10981098
scope: constant.character.escape.powershell
1099-
- include: string-placeholders
1099+
- include: single-quoted-string-placeholders
11001100

11011101
double-quoted-heredoc-strings:
11021102
- match: \@{{double_quote}}(?=$)
@@ -1112,8 +1112,8 @@ contexts:
11121112
scope: punctuation.definition.string.end.powershell
11131113
pop: 1
11141114
- include: escape-sequences
1115-
- include: string-placeholders
11161115
- include: string-interpolations
1116+
- include: double-quoted-string-placeholders
11171117

11181118
inside-double-quoted-heredoc-string.syntax:
11191119
- meta_include_prototype: false
@@ -1145,20 +1145,84 @@ contexts:
11451145
- include: variables-without-members
11461146
- include: immediately-pop
11471147

1148-
string-placeholders:
1149-
- match: \{
1150-
scope: punctuation.definition.placeholder.begin.powershell
1151-
push: inside-string-placeholder
1148+
double-quoted-string-placeholders:
1149+
- match: \{\{|\}\}
1150+
scope: constant.character.escape.powershell
1151+
- match: (\{)(\d+)
1152+
captures:
1153+
1: punctuation.definition.placeholder.begin.powershell
1154+
2: meta.number.integer.decimal.powershell constant.numeric.value.powershell
1155+
push: inside-double-quoted-string-placeholder
11521156

1153-
inside-string-placeholder:
1157+
inside-double-quoted-string-placeholder:
11541158
- meta_include_prototype: false
11551159
- meta_scope: constant.other.placeholder.powershell
11561160
- match: \}
11571161
scope: punctuation.definition.placeholder.end.powershell
11581162
pop: 1
1159-
- match: (?={{single_quote}}|{{double_quote}})
1163+
- match: (?={{double_quote}})
11601164
pop: 1
1161-
- match: '[:,;]'
1165+
- match: ':'
1166+
scope: punctuation.separator.format-spec.powershell
1167+
push: inside-double-quoted-string-placeholder-formatspec
1168+
- include: string-placeholder-separators
1169+
- include: string-placeholder-numbers
1170+
1171+
inside-double-quoted-string-placeholder-formatspec:
1172+
- meta_include_prototype: false
1173+
- meta_content_scope: meta.format-spec.powershell constant.other.format-spec.powershell
1174+
- match: \}
1175+
scope: punctuation.definition.placeholder.end.powershell
1176+
pop: 2
1177+
- match: '{{double_quote}}{2}'
1178+
scope: constant.character.escape.powershell
1179+
- match: (?={{double_quote}})
1180+
pop: 2
1181+
- include: escape-sequences
1182+
- include: string-placeholder-separators
1183+
1184+
single-quoted-string-placeholders:
1185+
- match: \{\{|\}\}
1186+
scope: constant.character.escape.powershell
1187+
- match: (\{)(\d+)
1188+
captures:
1189+
1: punctuation.definition.placeholder.begin.powershell
1190+
2: meta.number.integer.decimal.powershell constant.numeric.value.powershell
1191+
push: inside-single-quoted-string-placeholder
1192+
1193+
inside-single-quoted-string-placeholder:
1194+
- meta_include_prototype: false
1195+
- meta_scope: constant.other.placeholder.powershell
1196+
- match: \}
1197+
scope: punctuation.definition.placeholder.end.powershell
1198+
pop: 1
1199+
- match: (?={{single_quote}})
1200+
pop: 1
1201+
- match: ':'
1202+
scope: punctuation.separator.format-spec.powershell
1203+
push: inside-single-quoted-string-placeholder-formatspec
1204+
- include: string-placeholder-separators
1205+
- include: string-placeholder-numbers
1206+
1207+
inside-single-quoted-string-placeholder-formatspec:
1208+
- meta_include_prototype: false
1209+
- meta_content_scope: meta.format-spec.powershell constant.other.format-spec.powershell
1210+
- match: \}
1211+
scope: punctuation.definition.placeholder.end.powershell
1212+
pop: 2
1213+
- match: '{{single_quote}}{2}'
1214+
scope: constant.character.escape.powershell
1215+
- match: (?={{single_quote}})
1216+
pop: 2
1217+
- include: escape-sequences
1218+
- include: string-placeholder-separators
1219+
1220+
string-placeholder-numbers:
1221+
- match: \d+
1222+
scope: meta.number.integer.decimal.powershell constant.numeric.value.powershell
1223+
1224+
string-placeholder-separators:
1225+
- match: '[,;]'
11621226
scope: punctuation.separator.powershell
11631227

11641228
string-wildcards:

0 commit comments

Comments
 (0)