Skip to content

Commit 5017fc8

Browse files
committed
Refactor types
1 parent 0ed6442 commit 5017fc8

4 files changed

Lines changed: 116 additions & 66 deletions

File tree

PowerShell.sublime-syntax

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,6 @@ contexts:
238238
- match: \b(?i:(?:foreach|where|sort|tee)-object)\b
239239
scope: support.function.powershell
240240

241-
static-members:
242-
- match: '::'
243-
scope: punctuation.accessor.double-colon.powershell
244-
set: members
245-
246241
members:
247242
- match: (?=\.\.)
248243
pop: 1
@@ -318,32 +313,43 @@ contexts:
318313

319314
types:
320315
# TODO: push a maybe-static-members context
316+
- match: \[
317+
scope: punctuation.section.brackets.begin.powershell
318+
push: [maybe-static-member, inside-type]
319+
320+
types-without-members:
321321
- match: \[
322322
scope: punctuation.section.brackets.begin.powershell
323323
push: inside-type
324324

325325
inside-type:
326326
- meta_include_prototype: false
327-
- match: \](?=::)
328-
scope: punctuation.section.brackets.end.powershell
329-
set: static-members
330327
- match: \]
331328
scope: punctuation.section.brackets.end.powershell
332329
pop: 1
333330
- match: \p{L}[\p{L}\p{N}]+(\.)
334331
scope: meta.generic-name.powershell
335332
captures:
336333
1: punctuation.accessor.dot.powershell
337-
- match: \b(?:void|null|object|bool|char|string|int(?:32|64)?|long|byte|float|double|decimal)\b
334+
- match: '{{builtin_types}}'
338335
scope: storage.type.powershell
339336
- match: (?!\d+|\.)[\p{L}\p{N}.]+
340337
scope: support.type.powershell
341-
- include: types
338+
- include: types-without-members
342339
- match: \,
343340
scope: punctuation.separator.sequence.powershell
344341
- match: \+
345342
scope: punctuation.accessor.plus.powershell
346343

344+
static-members:
345+
- match: '::'
346+
scope: punctuation.accessor.double-colon.powershell
347+
set: members
348+
349+
maybe-static-member:
350+
- include: static-members
351+
- include: immediately-pop
352+
347353
###[ OPERATORS ]###############################################################
348354

349355
operators:
@@ -925,3 +931,9 @@ variables:
925931
int_suffix: (?i:u[lsy]?|[lnsy])
926932
unit_suffix: (?i:[kmgtp]b\b)
927933
kebab_break: (?![\w-])
934+
builtin_types: |-
935+
\b(?x:
936+
void | null | object | bool | char | string
937+
| int (?:32|64)? | long | byte | float | double | decimal
938+
| array | hashtable
939+
)\b

Tests/syntax_test_Class.ps1

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,39 +90,37 @@ class TypeName
9090
# ^ variable.other.readwrite
9191
# ^ punctuation.section.group.end
9292
[TypeName]::P2 = $h
93-
# <- punctuation.section.brackets.begin
94-
# ^ storage.type
95-
# ^ punctuation.section.brackets.end
96-
# ^^ punctuation.accessor.double-colon
97-
# ^^ variable.other.member
98-
# ^ keyword.operator.assignment
99-
# ^ punctuation.definition.variable
100-
# ^ variable.other.readwrite
93+
#^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell meta.block.powershell
94+
# ^ punctuation.section.brackets.begin.powershell
95+
# ^^^^^^^^ support.type.powershell
96+
# ^ punctuation.section.brackets.end.powershell
97+
# ^^ punctuation.accessor.double-colon.powershell
98+
# ^^ variable.other.member.powershell
99+
# ^ keyword.operator.assignment.powershell
100+
# ^^ variable.other.readwrite.powershell
101+
# ^ punctuation.definition.variable.powershell
101102
}
102103

103104
# Instance method
104105
# <- punctuation.definition.comment
105106
# ^^^^^^^^^^^^^^^ comment.line
106107
[int] MemberMethod2([int] $i) {
107-
# <- punctuation.section.brackets.begin
108-
# ^ storage.type
109-
# ^ punctuation.section.brackets.end
110-
# ^^^^^^^^^^^^^ entity.name.function
111-
# @@@@@@@@@@@@@ definition
112-
# ^ punctuation.section.group.begin
113-
# ^ punctuation.section.brackets.begin
114-
# ^^^ storage.type
115-
# ^ punctuation.section.brackets.end
116-
# ^ punctuation.definition.variable
117-
# ^ variable.other.readwrite
118-
# ^ punctuation.section.group.end
119-
$this.P3 = $i
120-
# <- punctuation.definition.variable
121-
# ^^^ variable.language
122-
# ^^ variable.other.member
123-
# ^ keyword.operator.assignment
124-
# ^ punctuation.definition.variable
125-
# ^ variable.other.readwrite
108+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell
109+
#^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
110+
# ^ punctuation.section.brackets.begin.powershell
111+
# ^^^ storage.type.powershell
112+
# ^ punctuation.section.brackets.end.powershell
113+
# ^^^^^^^^^^^^^ entity.name.function.powershell
114+
# @@@@@@@@@@@@@ definition
115+
# ^^^^^^^^^^ meta.group.powershell
116+
# ^ punctuation.section.group.begin.powershell
117+
# ^ punctuation.section.brackets.begin.powershell
118+
# ^^^ storage.type.powershell
119+
# ^ punctuation.section.brackets.end.powershell
120+
# ^^ variable.other.readwrite.powershell
121+
# ^ punctuation.definition.variable.powershell
122+
# ^ punctuation.section.group.end.powershell
123+
# ^ meta.block.powershell punctuation.section.braces.begin.powershell
126124
return $this.P3
127125
# <- keyword.control
128126
# ^ punctuation.definition.variable

Tests/syntax_test_Function.ps1

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ function Verb-Noun {
9393
# ^ meta.attribute punctuation.section.group.end
9494
# ^ meta.attribute punctuation.section.brackets.end
9595
[OutputType([String])]
96-
# <- meta.attribute punctuation.section.brackets.begin
97-
# ^ meta.attribute support.function.attribute
98-
# ^ meta.attribute punctuation.section.group.begin
99-
# ^ meta.attribute punctuation.section.brackets.begin
100-
# ^^^^^^ meta.attribute storage.type
101-
# ^ meta.attribute punctuation.section.brackets.end
102-
# ^ meta.attribute punctuation.section.group.end
103-
# ^ meta.attribute punctuation.section.brackets.end
96+
#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell
97+
# ^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell
98+
# ^ punctuation.section.brackets.begin.powershell
99+
# ^^^^^^^^^^ support.function.attribute.powershell
100+
# ^ punctuation.section.group.begin.powershell
101+
# ^ punctuation.section.brackets.begin.powershell
102+
# ^^^^^^ support.type.powershell
103+
# ^ punctuation.section.brackets.end.powershell
104+
# ^ punctuation.section.group.end.powershell
105+
# ^ punctuation.section.brackets.end.powershell
104106
Param
105107
#^^^^^ keyword.declaration.parameter
106108
(
@@ -302,9 +304,10 @@ function Verb-Noun {
302304
# ^ meta.attribute punctuation.section.group.end
303305
# ^ meta.attribute punctuation.section.brackets.end
304306
[String]
305-
# <- punctuation.section.brackets.begin
306-
#^^^^^^ storage.type
307-
# ^ punctuation.section.brackets.end
307+
#^^^^^^^^^^^^^^^ meta.block.powershell meta.group.powershell
308+
# ^ punctuation.section.brackets.begin.powershell
309+
# ^^^^^^ support.type.powershell
310+
# ^ punctuation.section.brackets.end.powershell
308311
$Param3,
309312
# <- punctuation.definition.variable
310313
#^^^^^^ variable.other.readwrite
@@ -335,9 +338,10 @@ function Verb-Noun {
335338
# ^ meta.attribute punctuation.section.group.end
336339
# ^ meta.attribute punctuation.section.brackets.end
337340
[string]
338-
# <- punctuation.section.brackets.begin
339-
# ^ storage.type
340-
# ^ punctuation.section.brackets.end
341+
#^^^^^^^^^^^^^^^ meta.block.powershell meta.group.powershell
342+
# ^ punctuation.section.brackets.begin.powershell
343+
# ^^^^^^ storage.type.powershell
344+
# ^ punctuation.section.brackets.end.powershell
341345
$Param4,
342346
# <- punctuation.definition.variable
343347
# ^ variable.other.readwrite
@@ -365,9 +369,10 @@ function Verb-Noun {
365369
# ^ comment.line punctuation.definition.comment
366370
# ^ comment.line
367371
[string]
368-
# <- punctuation.section.brackets.begin
369-
# ^ storage.type
370-
# ^ punctuation.section.brackets.end
372+
#^^^^^^^^^^^^^^^ meta.block.powershell meta.group.powershell
373+
# ^ punctuation.section.brackets.begin.powershell
374+
# ^^^^^^ storage.type.powershell
375+
# ^ punctuation.section.brackets.end.powershell
371376
$Param5
372377
# <- punctuation.definition.variable
373378
# ^ variable.other.readwrite

Tests/syntax_test_PowerShell.ps1

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ $a3[1..2]
725725
# ^ punctuation.section.brackets.end.powershell
726726
# ^^ punctuation.accessor.double-colon.powershell
727727
# ^^^^^ meta.function-call.powershell variable.function.powershell
728+
# @@@@@ reference
728729
# ^^^^^^^^^^^^^^ meta.function-call.arguments.powershell
729730
# ^ punctuation.section.arguments.begin.powershell
730731
# ^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell
@@ -1359,14 +1360,26 @@ $a -ceq 4 -and $a -ine $d -or
13591360
# ^^^^ keyword.operator.comparison
13601361
# ^^^ keyword.operator.logical
13611362
$c -is [Type]
1362-
# ^^^ keyword.operator.logical
1363-
# ^ storage.type
1363+
#^ variable.other.readwrite.powershell
1364+
# ^^^ keyword.operator.logical.powershell
1365+
# ^ punctuation.definition.keyword.powershell
1366+
# ^ punctuation.section.brackets.begin.powershell
1367+
# ^^^^ support.type.powershell
1368+
# ^ punctuation.section.brackets.end.powershell
13641369
$c -isnot [Type]
1365-
# ^^^^^^ keyword.operator.logical
1366-
# ^ storage.type
1370+
#^ variable.other.readwrite.powershell
1371+
# ^^^^^^ keyword.operator.logical.powershell
1372+
# ^ punctuation.definition.keyword.powershell
1373+
# ^ punctuation.section.brackets.begin.powershell
1374+
# ^^^^ support.type.powershell
1375+
# ^ punctuation.section.brackets.end.powershell
13671376
$c -as [Type]
1368-
# ^^^ keyword.operator.cast
1369-
# ^ storage.type
1377+
#^ variable.other.readwrite.powershell
1378+
# ^^^ keyword.operator.cast.powershell
1379+
# ^ punctuation.definition.keyword.powershell
1380+
# ^ punctuation.section.brackets.begin.powershell
1381+
# ^^^^ support.type.powershell
1382+
# ^ punctuation.section.brackets.end.powershell
13701383
$k = $y -bor $k
13711384
# ^ keyword.operator.assignment
13721385
# ^ keyword.operator.bitwise
@@ -1474,17 +1487,39 @@ echo `"test`"
14741487
# ^ meta.group.array-expression
14751488
# ^ keyword.control
14761489
# ^ meta.block
1490+
14771491
function join-path {}
14781492
# @@@@@@@@@ definition
1493+
14791494
$file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1"
1480-
# <- punctuation.definition.variable
1495+
#^^^^ variable.other.readwrite.powershell
1496+
# ^ keyword.operator.assignment.powershell
1497+
# ^^^^^^^^^ meta.function-call.powershell support.function.powershell
14811498
# @@@@@@@@@ reference
1482-
# ^ support.function
1483-
# ^ support.variable.drive
1484-
# ^ variable.other.readwrite
1485-
# ^^ meta.string meta.interpolation punctuation.section.interpolation.begin
1486-
# ^ storage.type
1499+
# ^^^^^^^^^^^^^^^^ variable.other.readwrite.powershell
1500+
# ^ punctuation.definition.variable.powershell
1501+
# ^^^^ support.variable.drive.powershell
1502+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell
1503+
# ^ string.quoted.double.powershell punctuation.definition.string.begin.powershell
1504+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.powershell
1505+
# ^^ punctuation.section.interpolation.begin.powershell
1506+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.powershell.embedded
1507+
# ^ punctuation.section.brackets.begin.powershell
1508+
# ^^^^^^^^^^ meta.generic-name.powershell
1509+
# ^ punctuation.accessor.dot.powershell
1510+
# ^ punctuation.accessor.dot.powershell
1511+
# ^^^^ support.type.powershell
1512+
# ^ punctuation.section.brackets.end.powershell
1513+
# ^^ punctuation.accessor.double-colon.powershell
1514+
# ^^^^^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell
14871515
# @@@@@@@@@@@@@@@@@ reference
1516+
# ^^ meta.function-call.arguments.powershell
1517+
# ^ punctuation.section.arguments.begin.powershell
1518+
# ^ punctuation.section.arguments.end.powershell
1519+
# ^ punctuation.section.interpolation.end.powershell
1520+
# ^^^^^ string.quoted.double.powershell
1521+
# ^ punctuation.definition.string.end.powershell
1522+
14881523
function out-file {}
14891524
# @@@@@@@@ definition
14901525
$ScriptBlock | Out-File $file -Force

0 commit comments

Comments
 (0)