Skip to content

Commit 915f845

Browse files
committed
Add naive string placeholder scopes
1 parent 04f8b43 commit 915f845

File tree

2 files changed

+132
-4
lines changed

2 files changed

+132
-4
lines changed

PowerShell.sublime-syntax

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ contexts:
774774
- match: \'
775775
scope: punctuation.definition.string.end.powershell
776776
pop: 1
777+
- include: string-placeholders
777778

778779
double-quoted-strings:
779780
- match: '"'
@@ -792,6 +793,7 @@ contexts:
792793
# # Silently eat email addresses
793794
# - match: '(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b'
794795
- include: string-interpolations
796+
- include: string-placeholders
795797
- match: '`\s*$'
796798
scope: keyword.other.powershell
797799

@@ -821,6 +823,7 @@ contexts:
821823
pop: 1
822824
- match: "''"
823825
scope: constant.character.escape.powershell
826+
- include: string-placeholders
824827

825828
double-quoted-heredoc-strings:
826829
- match: \@"(?=$)
@@ -836,6 +839,7 @@ contexts:
836839
scope: punctuation.definition.string.end.powershell
837840
pop: 1
838841
- include: escape-sequences
842+
- include: string-placeholders
839843
- include: string-interpolations
840844

841845
inside-double-quoted-heredoc-string.syntax:
@@ -868,6 +872,22 @@ contexts:
868872
- include: variables-without-members
869873
- include: immediately-pop
870874

875+
string-placeholders:
876+
- match: \{
877+
scope: punctuation.definition.placeholder.begin.powershell
878+
push: inside-string-placeholder
879+
880+
inside-string-placeholder:
881+
- meta_include_prototype: false
882+
- meta_scope: constant.other.placeholder.powershell
883+
- match: \}
884+
scope: punctuation.definition.placeholder.end.powershell
885+
pop: 1
886+
- match: (?=['"])
887+
pop: 1
888+
- match: '[:,;]'
889+
scope: punctuation.separator.powershell
890+
871891
numbers:
872892
# Binary numbers
873893
- match: \b(0[bB])([01]*)({{int_suffix}}?{{unit_suffix}}?)

Tests/syntax_test_strings.ps1

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@
213213
"{0:N2}" -f $a
214214
# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
215215
# ^ punctuation.definition.string.begin.powershell
216+
# ^^^^^^ constant.other.placeholder.powershell
217+
# ^ punctuation.definition.placeholder.begin.powershell
218+
# ^ punctuation.separator.powershell
219+
# ^ punctuation.definition.placeholder.end.powershell
216220
# ^ punctuation.definition.string.end.powershell
217221
# ^^ keyword.operator.string-format.powershell
218222
# ^ punctuation.definition.keyword.powershell
@@ -222,6 +226,10 @@
222226
"{0:D8}" -f $a
223227
# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
224228
# ^ punctuation.definition.string.begin.powershell
229+
# ^^^^^^ constant.other.placeholder.powershell
230+
# ^ punctuation.definition.placeholder.begin.powershell
231+
# ^ punctuation.separator.powershell
232+
# ^ punctuation.definition.placeholder.end.powershell
225233
# ^ punctuation.definition.string.end.powershell
226234
# ^^ keyword.operator.string-format.powershell
227235
# ^ punctuation.definition.keyword.powershell
@@ -231,6 +239,10 @@
231239
"{0:C2}" -f $a
232240
# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
233241
# ^ punctuation.definition.string.begin.powershell
242+
# ^^^^^^ constant.other.placeholder.powershell
243+
# ^ punctuation.definition.placeholder.begin.powershell
244+
# ^ punctuation.separator.powershell
245+
# ^ punctuation.definition.placeholder.end.powershell
234246
# ^ punctuation.definition.string.end.powershell
235247
# ^^ keyword.operator.string-format.powershell
236248
# ^ punctuation.definition.keyword.powershell
@@ -240,6 +252,10 @@
240252
"{0:P0}" -f $a
241253
# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
242254
# ^ punctuation.definition.string.begin.powershell
255+
# ^^^^^^ constant.other.placeholder.powershell
256+
# ^ punctuation.definition.placeholder.begin.powershell
257+
# ^ punctuation.separator.powershell
258+
# ^ punctuation.definition.placeholder.end.powershell
243259
# ^ punctuation.definition.string.end.powershell
244260
# ^^ keyword.operator.string-format.powershell
245261
# ^ punctuation.definition.keyword.powershell
@@ -249,6 +265,10 @@
249265
"{0:X0}" -f $a
250266
# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
251267
# ^ punctuation.definition.string.begin.powershell
268+
# ^^^^^^ constant.other.placeholder.powershell
269+
# ^ punctuation.definition.placeholder.begin.powershell
270+
# ^ punctuation.separator.powershell
271+
# ^ punctuation.definition.placeholder.end.powershell
252272
# ^ punctuation.definition.string.end.powershell
253273
# ^^ keyword.operator.string-format.powershell
254274
# ^ punctuation.definition.keyword.powershell
@@ -274,6 +294,19 @@
274294
"{1,10} {0,10} {2,10:x}" -f "First", "Second", 255
275295
# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
276296
# ^ punctuation.definition.string.begin.powershell
297+
# ^^^^^^ constant.other.placeholder.powershell
298+
# ^ punctuation.definition.placeholder.begin.powershell
299+
# ^ punctuation.separator.powershell
300+
# ^ punctuation.definition.placeholder.end.powershell
301+
# ^^^^^^ constant.other.placeholder.powershell
302+
# ^ punctuation.definition.placeholder.begin.powershell
303+
# ^ punctuation.separator.powershell
304+
# ^ punctuation.definition.placeholder.end.powershell
305+
# ^^^^^^^^ constant.other.placeholder.powershell
306+
# ^ punctuation.definition.placeholder.begin.powershell
307+
# ^ punctuation.separator.powershell
308+
# ^ punctuation.separator.powershell
309+
# ^ punctuation.definition.placeholder.end.powershell
277310
# ^ punctuation.definition.string.end.powershell
278311
# ^^ keyword.operator.string-format.powershell
279312
# ^ punctuation.definition.keyword.powershell
@@ -292,6 +325,10 @@
292325
# ^ punctuation.section.group.begin.powershell
293326
# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
294327
# ^ punctuation.definition.string.begin.powershell
328+
# ^^^^^ constant.other.placeholder.powershell
329+
# ^ punctuation.definition.placeholder.begin.powershell
330+
# ^ punctuation.separator.powershell
331+
# ^ punctuation.definition.placeholder.end.powershell
295332
# ^ punctuation.definition.string.end.powershell
296333
# ^^ keyword.operator.string-format.powershell
297334
# ^ punctuation.definition.keyword.powershell
@@ -303,6 +340,11 @@
303340
# ^ punctuation.section.group.begin.powershell
304341
# ^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
305342
# ^ punctuation.definition.string.begin.powershell
343+
# ^^^^^^^^^^^ constant.other.placeholder.powershell
344+
# ^ punctuation.definition.placeholder.begin.powershell
345+
# ^ punctuation.separator.powershell
346+
# ^ punctuation.separator.powershell
347+
# ^ punctuation.definition.placeholder.end.powershell
306348
# ^ punctuation.definition.string.end.powershell
307349
# ^^ keyword.operator.string-format.powershell
308350
# ^ punctuation.definition.keyword.powershell
@@ -313,6 +355,10 @@
313355
"{0:R}" -f (1mb/2.0)
314356
# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
315357
# ^ punctuation.definition.string.begin.powershell
358+
# ^^^^^ constant.other.placeholder.powershell
359+
# ^ punctuation.definition.placeholder.begin.powershell
360+
# ^ punctuation.separator.powershell
361+
# ^ punctuation.definition.placeholder.end.powershell
316362
# ^ punctuation.definition.string.end.powershell
317363
# ^^ keyword.operator.string-format.powershell
318364
# ^ punctuation.definition.keyword.powershell
@@ -329,6 +375,10 @@
329375
"{0:00.0}" -f 4.12341234
330376
# ^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
331377
# ^ punctuation.definition.string.begin.powershell
378+
# ^^^^^^^^ constant.other.placeholder.powershell
379+
# ^ punctuation.definition.placeholder.begin.powershell
380+
# ^ punctuation.separator.powershell
381+
# ^ punctuation.definition.placeholder.end.powershell
332382
# ^ punctuation.definition.string.end.powershell
333383
# ^^ keyword.operator.string-format.powershell
334384
# ^ punctuation.definition.keyword.powershell
@@ -338,6 +388,10 @@
338388
"{0:##.#}" -f 4.12341234
339389
# ^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
340390
# ^ punctuation.definition.string.begin.powershell
391+
# ^^^^^^^^ constant.other.placeholder.powershell
392+
# ^ punctuation.definition.placeholder.begin.powershell
393+
# ^ punctuation.separator.powershell
394+
# ^ punctuation.definition.placeholder.end.powershell
341395
# ^ punctuation.definition.string.end.powershell
342396
# ^^ keyword.operator.string-format.powershell
343397
# ^ punctuation.definition.keyword.powershell
@@ -347,6 +401,11 @@
347401
"{0:#,#.#}" -f 1234.121234
348402
# ^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
349403
# ^ punctuation.definition.string.begin.powershell
404+
# ^^^^^^^^^ constant.other.placeholder.powershell
405+
# ^ punctuation.definition.placeholder.begin.powershell
406+
# ^ punctuation.separator.powershell
407+
# ^ punctuation.separator.powershell
408+
# ^ punctuation.definition.placeholder.end.powershell
350409
# ^ punctuation.definition.string.end.powershell
351410
# ^^ keyword.operator.string-format.powershell
352411
# ^ punctuation.definition.keyword.powershell
@@ -356,6 +415,11 @@
356415
"{0:##,,.000}" -f 1048576
357416
# ^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
358417
# ^ punctuation.definition.string.begin.powershell
418+
# ^^^^^^^^^^^^ constant.other.placeholder.powershell
419+
# ^ punctuation.definition.placeholder.begin.powershell
420+
# ^ punctuation.separator.powershell
421+
# ^^ punctuation.separator.powershell
422+
# ^ punctuation.definition.placeholder.end.powershell
359423
# ^ punctuation.definition.string.end.powershell
360424
# ^^ keyword.operator.string-format.powershell
361425
# ^ punctuation.definition.keyword.powershell
@@ -364,20 +428,31 @@
364428
"{this is not a #comment}"
365429
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell - comment
366430
# ^ punctuation.definition.string.begin.powershell
431+
# ^^^^^^^^^^^^^^^^^^^^^^^^ constant.other.placeholder.powershell
432+
# ^ punctuation.definition.placeholder.begin.powershell
433+
# ^ punctuation.definition.placeholder.end.powershell
367434
# ^ punctuation.definition.string.end.powershell
368435

369436
"{0:##.#E000}" -f 2.71828
370437
# ^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
371438
# ^ punctuation.definition.string.begin.powershell
439+
# ^^^^^^^^^^^^ constant.other.placeholder.powershell
440+
# ^ punctuation.definition.placeholder.begin.powershell
441+
# ^ punctuation.separator.powershell
442+
# ^ punctuation.definition.placeholder.end.powershell
372443
# ^ punctuation.definition.string.end.powershell
373444
# ^^ keyword.operator.string-format.powershell
374445
# ^ punctuation.definition.keyword.powershell
375446
# ^^^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell
376447
# ^ punctuation.separator.decimal.powershell
377448

449+
# TODO: Let placeholders contain quotes
378450
"{0:#.00'##'}" -f 2.71828
379451
# ^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
380452
# ^ punctuation.definition.string.begin.powershell
453+
# ^^^^^^^ constant.other.placeholder.powershell
454+
# ^ punctuation.definition.placeholder.begin.powershell
455+
# ^ punctuation.separator.powershell
381456
# ^ punctuation.definition.string.end.powershell
382457
# ^^ keyword.operator.string-format.powershell
383458
# ^ punctuation.definition.keyword.powershell
@@ -387,18 +462,25 @@
387462
"{0:POS;NEG;ZERO}" -f -14
388463
# ^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
389464
# ^ punctuation.definition.string.begin.powershell
465+
# ^^^^^^^^^^^^^^^^ constant.other.placeholder.powershell
466+
# ^ punctuation.definition.placeholder.begin.powershell
467+
# ^ punctuation.separator.powershell
468+
# ^ punctuation.separator.powershell
469+
# ^ punctuation.separator.powershell
470+
# ^ punctuation.definition.placeholder.end.powershell
390471
# ^ punctuation.definition.string.end.powershell
391472
# ^^ keyword.operator.string-format.powershell
392473
# ^ punctuation.definition.keyword.powershell
393474
# ^ keyword.operator.unary.powershell
394475
# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell
395476

396477
"{0:$## Please}" -f 14
397-
# ^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell
398-
# ^^^^ string.quoted.double.powershell
478+
# ^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell - comment
399479
# ^ punctuation.definition.string.begin.powershell
400-
# ^ meta.interpolation.powershell
401-
# ^^^^^^^^^^^ string.quoted.double.powershell
480+
# ^^^^^^^^^^^^^^ constant.other.placeholder.powershell
481+
# ^ punctuation.definition.placeholder.begin.powershell
482+
# ^ punctuation.separator.powershell
483+
# ^ punctuation.definition.placeholder.end.powershell
402484
# ^ punctuation.definition.string.end.powershell
403485
# ^^ keyword.operator.string-format.powershell
404486
# ^ punctuation.definition.keyword.powershell
@@ -407,6 +489,11 @@
407489
"{0,-8:P1}" -f 1.75
408490
# ^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
409491
# ^ punctuation.definition.string.begin.powershell
492+
# ^^^^^^^^^ constant.other.placeholder.powershell
493+
# ^ punctuation.definition.placeholder.begin.powershell
494+
# ^ punctuation.separator.powershell
495+
# ^ punctuation.separator.powershell
496+
# ^ punctuation.definition.placeholder.end.powershell
410497
# ^ punctuation.definition.string.end.powershell
411498
# ^^ keyword.operator.string-format.powershell
412499
# ^ punctuation.definition.keyword.powershell
@@ -416,6 +503,23 @@
416503
"{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91
417504
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
418505
# ^ punctuation.definition.string.begin.powershell
506+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.other.placeholder.powershell
507+
# ^ punctuation.definition.placeholder.begin.powershell
508+
# ^ punctuation.separator.powershell
509+
# ^ punctuation.separator.powershell
510+
# ^ punctuation.definition.placeholder.end.powershell
511+
# ^ punctuation.definition.placeholder.begin.powershell
512+
# ^ punctuation.separator.powershell
513+
# ^ punctuation.separator.powershell
514+
# ^ punctuation.definition.placeholder.end.powershell
515+
# ^ punctuation.definition.placeholder.begin.powershell
516+
# ^ punctuation.separator.powershell
517+
# ^ punctuation.separator.powershell
518+
# ^ punctuation.definition.placeholder.end.powershell
519+
# ^ punctuation.definition.placeholder.begin.powershell
520+
# ^ punctuation.separator.powershell
521+
# ^ punctuation.separator.powershell
522+
# ^ punctuation.definition.placeholder.end.powershell
419523
# ^ punctuation.definition.string.end.powershell
420524
# ^^ keyword.operator.string-format.powershell
421525
# ^ punctuation.definition.keyword.powershell
@@ -435,6 +539,10 @@
435539
'{0:00000.000}' -f 7.125
436540
# ^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell
437541
# ^ punctuation.definition.string.begin.powershell
542+
# ^^^^^^^^^^^^^ constant.other.placeholder.powershell
543+
# ^ punctuation.definition.placeholder.begin.powershell
544+
# ^ punctuation.separator.powershell
545+
# ^ punctuation.definition.placeholder.end.powershell
438546
# ^ punctuation.definition.string.end.powershell
439547
# ^^ keyword.operator.string-format.powershell
440548
# ^ punctuation.definition.keyword.powershell

0 commit comments

Comments
 (0)