Skip to content

Commit d313f4b

Browse files
committed
Refactor variables
so we can stop synchronizing the with/without members matches We also get to mark escaped chars in the full-unicode var names
1 parent 8b5394f commit d313f4b

File tree

2 files changed

+57
-62
lines changed

2 files changed

+57
-62
lines changed

PowerShell.sublime-syntax

Lines changed: 40 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ contexts:
107107

108108
- include: commands
109109
- include: constants
110-
- include: variables
111110
- include: types
112111
- include: hashtables
112+
- include: variables
113113
- include: strings
114114
- include: script-blocks
115115
- include: escape-sequences
@@ -537,86 +537,64 @@ contexts:
537537
###[ VARIABLES ]###############################################################
538538

539539
variables:
540+
- match: (?=[$@](?:[{$^]|{{identifier_simple}}))
541+
push: [members, expect-variable]
542+
543+
variables-without-property:
544+
- match: (?=[$@](?:[{$^]|{{identifier_simple}}))
545+
push: [expect-variable]
546+
547+
expect-variable:
540548
- match: (\$|@){{var_constants}}
541549
scope: support.constant.variable.powershell
542550
captures:
543551
1: punctuation.definition.variable.powershell
544-
push: members
545552
- match: (\$|@){{var_language}}
546553
scope: variable.language.powershell
547554
captures:
548555
1: punctuation.definition.variable.powershell
549-
push: members
550-
- match: (\$|@)({{var_scope_mod}})(:){{identifier_simple}}
551-
scope: variable.other.readwrite.powershell
552-
captures:
553-
1: punctuation.definition.variable.powershell
554-
2: storage.modifier.scope.powershell
555-
3: punctuation.separator.sequence.powershell
556-
push: members
557-
- match: (\$|@)(\{)({{var_scope_mod}})(:){{identifier_special}}(\})
558-
scope: variable.other.readwrite.powershell
556+
- match: (\$)(\{)
559557
captures:
560558
1: punctuation.definition.variable.powershell
561559
2: punctuation.section.interpolation.begin.powershell
562-
3: storage.modifier.scope.powershell
563-
4: punctuation.separator.sequence.powershell
564-
5: punctuation.section.interpolation.end.powershell
565-
push: members
566-
- match: (\$|@)(?:({{identifier_simple}})(:))?{{identifier_simple}}
567-
scope: variable.other.readwrite.powershell
568-
captures:
569-
1: punctuation.definition.variable.powershell
570-
2: support.variable.drive.powershell
571-
3: punctuation.separator.sequence.powershell
572-
push: members
573-
- match: (\$|@)(\{)(?:({{identifier_special}})(:))?{{identifier_special}}(\})
574-
scope: variable.other.readwrite.powershell
560+
push: inside-variable-special-char
561+
- match: (\$|@)(?!\{)
575562
captures:
576563
1: punctuation.definition.variable.powershell
577564
2: punctuation.section.interpolation.begin.powershell
578-
3: support.variable.drive.powershell
579-
4: punctuation.separator.sequence.powershell
580-
5: punctuation.section.interpolation.end.powershell
581-
push: members
565+
push: inside-variable-simple
566+
- include: immediately-pop
582567

583-
variables-without-property:
584-
- match: (\$|@){{var_constants}}
585-
scope: support.constant.variable.powershell
586-
captures:
587-
1: punctuation.definition.variable.powershell
588-
- match: (\$|@){{var_language}}
589-
scope: variable.language.powershell
590-
captures:
591-
1: punctuation.definition.variable.powershell
592-
- match: (\$|@)({{var_scope_mod}})(:){{identifier_simple}}
593-
scope: variable.other.readwrite.powershell
568+
inside-variable-simple:
569+
- meta_include_prototype: false
570+
- meta_scope: variable.other.readwrite.powershell
571+
- match: ({{var_scope_mod}})(:)
594572
captures:
595-
1: punctuation.definition.variable.powershell
596-
2: storage.modifier.scope.powershell
597-
3: punctuation.separator.sequence.powershell
598-
- match: (\$|@)(\{)({{var_scope_mod}})(:){{identifier_special}}(\})
599-
scope: variable.other.readwrite.powershell
573+
1: storage.modifier.scope.powershell
574+
2: punctuation.separator.sequence.powershell
575+
- match: ({{identifier_simple}})(:)
600576
captures:
601-
1: punctuation.definition.variable.powershell
602-
2: punctuation.section.interpolation.begin.powershell
603-
3: storage.modifier.scope.powershell
604-
4: punctuation.separator.sequence.powershell
605-
5: punctuation.section.interpolation.end.powershell
606-
- match: (\$|@)(?:({{identifier_simple}})(:))?{{identifier_simple}}
607-
scope: variable.other.readwrite.powershell
577+
1: support.variable.drive.powershell
578+
2: punctuation.separator.sequence.powershell
579+
- match: '{{identifier_simple}}'
580+
- include: immediately-pop
581+
582+
inside-variable-special-char:
583+
- meta_include_prototype: false
584+
- meta_scope: variable.other.readwrite.powershell
585+
- match: '`.'
586+
scope: constant.character.escape.powershell
587+
- match: \}
588+
scope: punctuation.section.interpolation.end.powershell
589+
pop: 1
590+
- match: ({{var_scope_mod}})(:)
608591
captures:
609-
1: punctuation.definition.variable.powershell
610-
2: support.variable.drive.powershell
611-
3: punctuation.separator.sequence.powershell
612-
- match: (\$|@)(\{)(?:({{identifier_special}})(:))?{{identifier_special}}(\})
613-
scope: variable.other.readwrite.powershell
592+
1: storage.modifier.scope.powershell
593+
2: punctuation.separator.sequence.powershell
594+
- match: ({{identifier_simple}})(:)
614595
captures:
615-
1: punctuation.definition.variable.powershell
616-
2: punctuation.section.interpolation.begin.powershell
617-
3: support.variable.drive.powershell
618-
4: punctuation.separator.sequence.powershell
619-
5: punctuation.section.interpolation.end.powershell
596+
1: support.variable.drive.powershell
597+
2: punctuation.separator.sequence.powershell
620598

621599
members:
622600
- match: (?=\.\.)

Tests/syntax_test_PowerShell.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ throw "Do not run this file!"
183183
# ^ punctuation.definition.variable.powershell
184184
# ^ punctuation.section.interpolation.begin.powershell
185185
# ^ punctuation.section.interpolation.end.powershell
186+
${vari-able}
187+
# ^^^^^^^^^^^^ variable.other.readwrite.powershell
188+
# ^ punctuation.definition.variable.powershell
189+
# ^ punctuation.section.interpolation.begin.powershell
190+
# ^ punctuation.section.interpolation.end.powershell
191+
${var`iable}
192+
# ^^^^^^^^^^^^ variable.other.readwrite.powershell
193+
# ^ punctuation.definition.variable.powershell
194+
# ^ punctuation.section.interpolation.begin.powershell
195+
# ^^ constant.character.escape.powershell
196+
# ^ punctuation.section.interpolation.end.powershell
197+
${variable`}}
198+
# ^^^^^^^^^^^^^ variable.other.readwrite.powershell
199+
# ^ punctuation.definition.variable.powershell
200+
# ^ punctuation.section.interpolation.begin.powershell
201+
# ^^ constant.character.escape.powershell
202+
# ^ punctuation.section.interpolation.end.powershell
186203
${script:variable}
187204
# ^^^^^^^^^^^^^^^^^^ variable.other.readwrite.powershell
188205
# ^ punctuation.definition.variable.powershell

0 commit comments

Comments
 (0)