Skip to content

Commit 5236ffd

Browse files
committed
Push a context for membership
1 parent 1cddc0b commit 5236ffd

File tree

4 files changed

+210
-141
lines changed

4 files changed

+210
-141
lines changed

PowerShell.sublime-syntax

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ contexts:
3434

3535
main:
3636
- include: comments
37+
- include: expressions
38+
39+
expressions:
3740
- include: redirection
3841
- include: commands
3942
- include: variable
@@ -255,12 +258,12 @@ contexts:
255258
)\b
256259
)
257260
captures:
258-
1: punctuation.section.bracket.begin.powershell
261+
1: punctuation.section.brackets.begin.powershell
259262
2: support.function.attribute.powershell
260263
push:
261264
- meta_scope: meta.attribute.powershell
262265
- match: \]
263-
scope: punctuation.section.bracket.end.powershell
266+
scope: punctuation.section.brackets.end.powershell
264267
pop: true
265268
- match: \(
266269
scope: punctuation.section.group.begin.powershell
@@ -368,6 +371,41 @@ contexts:
368371
- include: pop-at-newline
369372
- include: comment-embedded-docs
370373

374+
static-members:
375+
# - meta_content_scope: debug.in.static-members
376+
- match: '::'
377+
scope: punctuation.accessor.double-colon.powershell
378+
set: members
379+
380+
members:
381+
# - meta_content_scope: debug.in.members
382+
- match: (?=\.\.)
383+
pop: true
384+
- match: \.(?=\w)
385+
scope: punctuation.accessor.dot.powershell
386+
- match: (\w+)(\()
387+
captures:
388+
1: meta.function-call.powershell variable.function.powershell
389+
2: meta.function-call.arguments.powershell punctuation.section.arguments.begin.powershell
390+
push:
391+
- meta_content_scope: meta.function-call.arguments.powershell
392+
- match: \)
393+
scope: meta.function-call.arguments.powershell punctuation.section.arguments.end.powershell
394+
pop: true
395+
- include: expressions
396+
- match: \w+
397+
scope: variable.other.member.powershell
398+
- match: \[
399+
scope: punctuation.section.brackets.begin.powershell
400+
push:
401+
- meta_scope: meta.brackets.indexer.powershell
402+
- match: \]
403+
scope: punctuation.section.brackets.end.powershell
404+
pop: true
405+
- include: expressions
406+
- match: ''
407+
pop: true
408+
371409
strings:
372410
- include: double-quoted-string
373411
- include: single-quoted-string
@@ -543,10 +581,13 @@ contexts:
543581
type:
544582
# TODO: push a maybe-static-members context
545583
- match: \[
546-
scope: punctuation.section.bracket.begin.powershell
584+
scope: punctuation.section.brackets.begin.powershell
547585
push:
586+
- match: \](?=::)
587+
scope: punctuation.section.brackets.end.powershell
588+
set: static-members
548589
- match: \]
549-
scope: punctuation.section.bracket.end.powershell
590+
scope: punctuation.section.brackets.end.powershell
550591
pop: true
551592
- match: (?!\d+|\.)[\p{L}\p{N}.]+
552593
scope: storage.type.powershell
@@ -564,12 +605,11 @@ contexts:
564605
|PID|Profile|Ps(?:CommandPath|Home|ScriptRoot|UiCulture|VersionTable)
565606
|ShellID)
566607
)
567-
((?:\.\w+)*\b)?\b
568608
)
569609
captures:
570610
1: support.constant.variable.powershell
571611
2: punctuation.definition.variable.powershell
572-
3: variable.other.member.powershell
612+
push: members
573613
- match: |-
574614
(?x:(
575615
(\$)
@@ -581,12 +621,11 @@ contexts:
581621
|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b
582622
)
583623
)
584-
((?:\.\w+)*\b)?
585624
)
586625
captures:
587626
1: variable.language.powershell
588627
2: punctuation.definition.variable.powershell
589-
3: variable.other.member.powershell
628+
push: members
590629
- match: |-
591630
(?x:(
592631
(\$)
@@ -600,40 +639,40 @@ contexts:
600639
|SessionConfigurationName|SessionOption)
601640
|ErrorView|FormatEnumerationLimit|OFS|OutputEncoding)
602641
)
603-
((?:\.\w+)*\b)?\b
604642
)
605643
captures:
606644
1: variable.language.powershell
607645
2: punctuation.definition.variable.powershell
608-
3: variable.other.member.powershell
609-
- match: ((\$|@)(?i:(global|local|private|script|using|workflow):\w+))((?:\.\w+)*\b)?
646+
push: members
647+
- match: ((\$|@)(?i:(global|local|private|script|using|workflow):\w+))
610648
captures:
611649
1: variable.other.readwrite.powershell
612650
2: punctuation.definition.variable.powershell
613651
3: storage.modifier.scope.powershell
614-
4: variable.other.member.powershell
615-
- match: ((\$)(\{)((?i:global|local|private|script|using|workflow)):([^}]*[^}`])(\}))((?:\.\w+)*\b)?
652+
push: members
653+
- match: ((\$)(\{)((?i:global|local|private|script|using|workflow)):([^}]*[^}`])(\}))
616654
captures:
617655
1: variable.other.readwrite.powershell
618656
2: punctuation.definition.variable.powershell
619657
3: punctuation.section.braces.begin.powershell
620658
4: storage.modifier.scope.powershell
621659
6: punctuation.section.braces.end.powershell
622-
7: variable.other.member.powershell
623-
- match: ((?i:(\$|@)(\w+:)?\w+))((?:\.\w+)*\b)?
660+
push: members
661+
- match: ((?i:(\$|@)(\w+:)?\w+))
624662
captures:
625663
1: variable.other.readwrite.powershell
626664
2: punctuation.definition.variable.powershell
627665
3: support.variable.drive.powershell
628666
4: variable.other.member.powershell
629-
- match: ((?i:(\$)(\{)(\w+:)?([^}]*[^}`])(\})))((?:\.\w+)*\b)?
667+
push: members
668+
- match: ((?i:(\$)(\{)(\w+:)?([^}]*[^}`])(\})))
630669
captures:
631670
1: variable.other.readwrite.powershell
632671
2: punctuation.definition.variable.powershell
633672
3: punctuation.section.braces.begin.powershell
634673
4: support.variable.drive.powershell
635674
6: punctuation.section.braces.end.powershell
636-
7: variable.other.member.powershell
675+
push: members
637676

638677
variable-no-property:
639678
- match: (\$)(?i:True|False|Null)\b

Tests/syntax_test_Class.ps1

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ class TypeName
1414
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line
1515
[ValidateSet("val1", "Val2")]
1616
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute
17-
# <- punctuation.section.bracket.begin
17+
# <- punctuation.section.brackets.begin
1818
# ^^^^^^^^^^ support.function.attribute
1919
# ^ punctuation.section.group.begin
2020
# ^^^^^^ string.quoted.double
2121
# ^ punctuation.separator
2222
# ^^^^^^ string.quoted.double
2323
# ^ punctuation.section.group.end
24-
# ^ punctuation.section.bracket.end
24+
# ^ punctuation.section.brackets.end
2525
[string] $P1
26-
# <- punctuation.section.bracket.begin
26+
# <- punctuation.section.brackets.begin
2727
# ^^^^^ storage.type
28-
# ^ punctuation.section.bracket.end
28+
# ^ punctuation.section.brackets.end
2929
# ^ punctuation.definition.variable
3030
# ^^ variable.other.readwrite
3131

@@ -34,9 +34,9 @@ class TypeName
3434
# ^^^^^^^^^^^^^^^ comment.line
3535
static [hashtable] $P2
3636
#^^^^^ storage.modifier
37-
# ^ punctuation.section.bracket.begin
37+
# ^ punctuation.section.brackets.begin
3838
# ^^^^^^^^^ storage.type
39-
# ^ punctuation.section.bracket.end
39+
# ^ punctuation.section.brackets.end
4040
# ^ punctuation.definition.variable
4141
# ^^ variable.other.readwrite
4242

@@ -45,9 +45,9 @@ class TypeName
4545
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line
4646
hidden [int] $P3
4747
#^^^^^ storage.modifier
48-
# ^ punctuation.section.bracket.begin
48+
# ^ punctuation.section.brackets.begin
4949
# ^ storage.type
50-
# ^ punctuation.section.bracket.end
50+
# ^ punctuation.section.brackets.end
5151
# ^ punctuation.definition.variable
5252
# ^^ variable.other.readwrite
5353

@@ -56,9 +56,9 @@ class TypeName
5656
# ^^^^^^^^^^^ comment.line
5757
TypeName ([string] $s) {
5858
# ^ punctuation.section.group.begin
59-
# ^ punctuation.section.bracket.begin
59+
# ^ punctuation.section.brackets.begin
6060
# ^^^^^^ storage.type
61-
# ^ punctuation.section.bracket.end
61+
# ^ punctuation.section.brackets.end
6262
# ^ punctuation.definition.variable
6363
# ^ variable.other.readwrite
6464
# ^ punctuation.section.group.end
@@ -76,20 +76,22 @@ class TypeName
7676
# ^^^^^^^^^^^^^ comment.line
7777
static [void] MemberMethod1([hashtable] $h) {
7878
# <- storage.modifier
79-
# ^ punctuation.section.bracket.begin
79+
# ^ punctuation.section.brackets.begin
8080
# ^^^^ storage.type
81-
# ^ punctuation.section.bracket.end
81+
# ^ punctuation.section.brackets.end
8282
# ^ punctuation.section.group.begin
83-
# ^ punctuation.section.bracket.begin
83+
# ^ punctuation.section.brackets.begin
8484
# ^^^^^^^^^ storage.type
85-
# ^ punctuation.section.bracket.end
85+
# ^ punctuation.section.brackets.end
8686
# ^ punctuation.definition.variable
8787
# ^ variable.other.readwrite
8888
# ^ punctuation.section.group.end
8989
[TypeName]::P2 = $h
90-
# <- punctuation.section.bracket.begin
90+
# <- punctuation.section.brackets.begin
9191
# ^ storage.type
92-
# ^ punctuation.section.bracket.end
92+
# ^ punctuation.section.brackets.end
93+
# ^^ punctuation.accessor.double-colon
94+
# ^^ variable.other.member
9395
# ^ keyword.operator.assignment
9496
# ^ punctuation.definition.variable
9597
# ^ variable.other.readwrite
@@ -99,13 +101,13 @@ class TypeName
99101
# <- punctuation.definition.comment
100102
# ^^^^^^^^^^^^^^^ comment.line
101103
[int] MemberMethod2([int] $i) {
102-
# <- punctuation.section.bracket.begin
104+
# <- punctuation.section.brackets.begin
103105
# ^ storage.type
104-
# ^ punctuation.section.bracket.end
106+
# ^ punctuation.section.brackets.end
105107
# ^ punctuation.section.group.begin
106-
# ^ punctuation.section.bracket.begin
108+
# ^ punctuation.section.brackets.begin
107109
# ^^^ storage.type
108-
# ^ punctuation.section.bracket.end
110+
# ^ punctuation.section.brackets.end
109111
# ^ punctuation.definition.variable
110112
# ^ variable.other.readwrite
111113
# ^ punctuation.section.group.end

0 commit comments

Comments
 (0)