blob: e8f6b2f8eda9ceae660f485d47f919776ac4ade2 [file] [log] [blame]
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02001" Vim syntax file
2" Language: Windows PowerShell
3" URL: https://github.com/PProvost/vim-ps1
4" Last Change: 2020 Nov 24
5"
6" The following settings are available for tuning syntax highlighting:
7" let ps1_nofold_blocks = 1
8" let ps1_nofold_sig = 1
9" let ps1_nofold_region = 1
10
11if exists("b:current_syntax")
12 finish
13endif
14
15" Operators contain dashes
16setlocal iskeyword+=-
17
18" PowerShell doesn't care about case
19syn case ignore
20
21" Sync-ing method
22syn sync minlines=100
23
24" Certain tokens can't appear at the top level of the document
25syn cluster ps1NotTop contains=@ps1Comment,ps1CDocParam,ps1FunctionDeclaration
26
27" Comments and special comment words
28syn keyword ps1CommentTodo TODO FIXME XXX TBD HACK NOTE contained
29syn match ps1CDocParam /.*/ contained
30syn match ps1CommentDoc /^\s*\zs\.\w\+\>/ nextgroup=ps1CDocParam contained
31syn match ps1CommentDoc /#\s*\zs\.\w\+\>/ nextgroup=ps1CDocParam contained
32syn match ps1Comment /#.*/ contains=ps1CommentTodo,ps1CommentDoc,@Spell
33syn region ps1Comment start="<#" end="#>" contains=ps1CommentTodo,ps1CommentDoc,@Spell
34
35" Language keywords and elements
36syn keyword ps1Conditional if else elseif switch default
37syn keyword ps1Repeat while for do until break continue foreach in
38syn match ps1Repeat /\<foreach\>/ nextgroup=ps1Block skipwhite
39syn match ps1Keyword /\<while\>/ nextgroup=ps1Block skipwhite
40syn match ps1Keyword /\<where\>/ nextgroup=ps1Block skipwhite
41
42syn keyword ps1Exception begin process end exit inlinescript parallel sequence
43syn keyword ps1Keyword try catch finally throw
44syn keyword ps1Keyword return filter in trap param data dynamicparam
45syn keyword ps1Constant $true $false $null
46syn match ps1Constant +\$?+
47syn match ps1Constant +\$_+
48syn match ps1Constant +\$\$+
49syn match ps1Constant +\$^+
50
51" Keywords reserved for future use
52syn keyword ps1Keyword class define from using var
53
54" Function declarations
55syn keyword ps1Keyword function nextgroup=ps1Function skipwhite
56syn keyword ps1Keyword filter nextgroup=ps1Function skipwhite
57syn keyword ps1Keyword workflow nextgroup=ps1Function skipwhite
58syn keyword ps1Keyword configuration nextgroup=ps1Function skipwhite
59syn keyword ps1Keyword class nextgroup=ps1Function skipwhite
60syn keyword ps1Keyword enum nextgroup=ps1Function skipwhite
61
62" Function declarations and invocations
63syn match ps1Cmdlet /\v(add|clear|close|copy|enter|exit|find|format|get|hide|join|lock|move|new|open|optimize|pop|push|redo|remove|rename|reset|search|select|Set|show|skip|split|step|switch|undo|unlock|watch)(-\w+)+/ contained
64syn match ps1Cmdlet /\v(connect|disconnect|read|receive|send|write)(-\w+)+/ contained
65syn match ps1Cmdlet /\v(backup|checkpoint|compare|compress|convert|convertfrom|convertto|dismount|edit|expand|export|group|import|initialize|limit|merge|mount|out|publish|restore|save|sync|unpublish|update)(-\w+)+/ contained
66syn match ps1Cmdlet /\v(debug|measure|ping|repair|resolve|test|trace)(-\w+)+/ contained
67syn match ps1Cmdlet /\v(approve|assert|build|complete|confirm|deny|deploy|disable|enable|install|invoke|register|request|restart|resume|start|stop|submit|suspend|uninstall|unregister|wait)(-\w+)+/ contained
68syn match ps1Cmdlet /\v(block|grant|protect|revoke|unblock|unprotect)(-\w+)+/ contained
69syn match ps1Cmdlet /\v(use)(-\w+)+/ contained
70
71" Other functions
72syn match ps1Function /\w\+\(-\w\+\)\+/ contains=ps1Cmdlet
73
74" Type declarations
75syn match ps1Type /\[[a-z_][a-z0-9_.,\[\]]\+\]/
76
77" Variable references
78syn match ps1ScopeModifier /\(global:\|local:\|private:\|script:\)/ contained
79syn match ps1Variable /\$\w\+\(:\w\+\)\?/ contains=ps1ScopeModifier
80syn match ps1Variable /\${\w\+\(:\?[[:alnum:]_()]\+\)\?}/ contains=ps1ScopeModifier
81
82" Operators
83syn keyword ps1Operator -eq -ne -ge -gt -lt -le -like -notlike -match -notmatch -replace -split -contains -notcontains
84syn keyword ps1Operator -ieq -ine -ige -igt -ile -ilt -ilike -inotlike -imatch -inotmatch -ireplace -isplit -icontains -inotcontains
85syn keyword ps1Operator -ceq -cne -cge -cgt -clt -cle -clike -cnotlike -cmatch -cnotmatch -creplace -csplit -ccontains -cnotcontains
86syn keyword ps1Operator -in -notin
87syn keyword ps1Operator -is -isnot -as -join
88syn keyword ps1Operator -and -or -not -xor -band -bor -bnot -bxor
89syn keyword ps1Operator -f
90syn match ps1Operator /!/
91syn match ps1Operator /=/
92syn match ps1Operator /+=/
93syn match ps1Operator /-=/
94syn match ps1Operator /\*=/
95syn match ps1Operator /\/=/
96syn match ps1Operator /%=/
97syn match ps1Operator /+/
98syn match ps1Operator /-\(\s\|\d\|\.\|\$\|(\)\@=/
99syn match ps1Operator /\*/
100syn match ps1Operator /\//
101syn match ps1Operator /|/
102syn match ps1Operator /%/
103syn match ps1Operator /&/
104syn match ps1Operator /::/
105syn match ps1Operator /,/
106syn match ps1Operator /\(^\|\s\)\@<=\. \@=/
107
108" Regular Strings
109" These aren't precisely correct and could use some work
110syn region ps1String start=/"/ skip=/`"/ end=/"/ contains=@ps1StringSpecial,@Spell
111syn region ps1String start=/'/ skip=/''/ end=/'/
112
113" Here-Strings
114syn region ps1String start=/@"$/ end=/^"@/ contains=@ps1StringSpecial,@Spell
115syn region ps1String start=/@'$/ end=/^'@/
116
117" Interpolation
118syn match ps1Escape /`./
119syn region ps1Interpolation matchgroup=ps1InterpolationDelimiter start="$(" end=")" contained contains=ALLBUT,@ps1NotTop
120syn region ps1NestedParentheses start="(" skip="\\\\\|\\)" matchgroup=ps1Interpolation end=")" transparent contained
121syn cluster ps1StringSpecial contains=ps1Escape,ps1Interpolation,ps1Variable,ps1Boolean,ps1Constant,ps1BuiltIn,@Spell
122
123" Numbers
124syn match ps1Number "\(\<\|-\)\@<=\(0[xX]\x\+\|\d\+\)\([KMGTP][B]\)\=\(\>\|-\)\@="
125syn match ps1Number "\(\(\<\|-\)\@<=\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[dD]\="
126syn match ps1Number "\<\d\+[eE][-+]\=\d\+[dD]\=\>"
127syn match ps1Number "\<\d\+\([eE][-+]\=\d\+\)\=[dD]\>"
128
129" Constants
130syn match ps1Boolean "$\%(true\|false\)\>"
131syn match ps1Constant /\$null\>/
132syn match ps1BuiltIn "$^\|$?\|$_\|$\$"
133syn match ps1BuiltIn "$\%(args\|error\|foreach\|home\|input\)\>"
134syn match ps1BuiltIn "$\%(match\(es\)\?\|myinvocation\|host\|lastexitcode\)\>"
135syn match ps1BuiltIn "$\%(ofs\|shellid\|stacktrace\)\>"
136
137" Named Switch
138syn match ps1Label /\s-\w\+/
139
140" Folding blocks
141if !exists('g:ps1_nofold_blocks')
142 syn region ps1Block start=/{/ end=/}/ transparent fold
143endif
144
145if !exists('g:ps1_nofold_region')
146 syn region ps1Region start=/#region/ end=/#endregion/ transparent fold keepend extend
147endif
148
149if !exists('g:ps1_nofold_sig')
150 syn region ps1Signature start=/# SIG # Begin signature block/ end=/# SIG # End signature block/ transparent fold
151endif
152
153" Setup default color highlighting
154hi def link ps1Number Number
155hi def link ps1Block Block
156hi def link ps1Region Region
157hi def link ps1Exception Exception
158hi def link ps1Constant Constant
159hi def link ps1String String
160hi def link ps1Escape SpecialChar
161hi def link ps1InterpolationDelimiter Delimiter
162hi def link ps1Conditional Conditional
163hi def link ps1Cmdlet Function
164hi def link ps1Function Identifier
165hi def link ps1Variable Identifier
166hi def link ps1Boolean Boolean
167hi def link ps1Constant Constant
168hi def link ps1BuiltIn StorageClass
169hi def link ps1Type Type
170hi def link ps1ScopeModifier StorageClass
171hi def link ps1Comment Comment
172hi def link ps1CommentTodo Todo
173hi def link ps1CommentDoc Tag
174hi def link ps1CDocParam Identifier
175hi def link ps1Operator Operator
176hi def link ps1Repeat Repeat
177hi def link ps1RepeatAndCmdlet Repeat
178hi def link ps1Keyword Keyword
179hi def link ps1KeywordAndCmdlet Keyword
180hi def link ps1Label Label
181
182let b:current_syntax = "ps1"