@@ -12,7 +12,7 @@ file_extensions:
1212
1313first_line_match : |-
1414 (?x:
15- ^\#!.*\b(?:pwsh|powershell)\b
15+ ^\#!.*{{shebang_language}}
1616 | ^\# \s* -\*- [^*]* mode: \s* powershell [^*]* -\*-
1717 )
1818
@@ -21,7 +21,28 @@ contexts:
2121 - include : comments
2222
2323 main :
24- - include : statements
24+ - meta_include_prototype : false
25+ - match : ' '
26+ push : [statements, imports, shebang]
27+
28+ shebang :
29+ - meta_include_prototype : false
30+ - match : ^\s*(\#!)
31+ captures :
32+ 1 : punctuation.definition.comment.powershell
33+ set : shebang-body
34+ - include : else-pop
35+
36+ shebang-body :
37+ - meta_include_prototype : false
38+ - meta_scope : comment.line.shebang.powershell
39+ - match : ' {{shebang_language}}'
40+ scope : constant.language.shebang.powershell
41+ - include : pop-eol
42+
43+ imports :
44+ - include : using-directives
45+ - include : else-pop
2546
2647 statements :
2748 - include : redirection
@@ -88,7 +109,6 @@ contexts:
88109 - include : commands
89110 - include : constants
90111 - include : variables
91- - include : using-directives
92112 - include : types
93113 - include : hashtables
94114 - include : strings
@@ -127,13 +147,6 @@ contexts:
127147 captures :
128148 1 : punctuation.definition.parameter.powershell
129149
130- using-directives :
131- - match : \b(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+))
132- captures :
133- 1 : keyword.control.using.powershell
134- 2 : keyword.other.powershell
135- 3 : variable.parameter.powershell
136-
137150 requires-directives :
138151 - match : (#)((?i:requires))\s
139152 captures :
@@ -202,6 +215,40 @@ contexts:
202215 # Back to normal stuff
203216 - include : statements
204217
218+ # ##[ USINGS ]##################################################################
219+
220+ using-directives :
221+ - match : \b(?i)using(?=\s)
222+ scope : keyword.control.import.powershell
223+ push : inside-using
224+
225+ inside-using :
226+ - match : \bnamespace(?=\s)
227+ scope : keyword.control.import.powershell
228+ set : inside-using-namespace
229+ - match : \bmodule(?=\s)
230+ scope : keyword.control.import.powershell
231+ set : inside-using-module
232+ - include : else-pop
233+
234+ inside-using-namespace :
235+ - include : pop-eol
236+ - match : \p{L}[\p{L}\p{N}]+(\.)
237+ scope : meta.path.powershell
238+ captures :
239+ 1 : punctuation.accessor.dot.powershell
240+ - match : \p{L}[\p{L}\p{N}]+
241+ scope : meta.path.powershell
242+
243+ inside-using-module :
244+ - include : pop-eol
245+ - match : \p{L}[\p{L}\p{N}]+(\.)
246+ scope : meta.path.powershell
247+ captures :
248+ 1 : punctuation.accessor.dot.powershell
249+ - match : \p{L}[\p{L}\p{N}]+
250+ scope : meta.path.powershell support.type.powershell
251+
205252# ##[ FUNCTIONS ]###############################################################
206253
207254 functions :
@@ -278,7 +325,7 @@ contexts:
278325 1 : punctuation.accessor.dot.powershell
279326 - match : ' {{builtin_types}}'
280327 scope : storage.type.powershell
281- - match : (?!\d+|\.) [\p{L}\p{N}. ]+
328+ - match : \p{L} [\p{L}\p{N}]+
282329 scope : support.type.powershell
283330 - include : types-without-members
284331 - match : \,
@@ -819,6 +866,7 @@ variables:
819866 | int (?:32|64)? | long | byte | float | double | decimal
820867 | array | hashtable
821868 )\b
869+ shebang_language : \b(?:pwsh|powershell)\b
822870
823871 # Attributes
824872 attributes : |-
0 commit comments