blob: e09b5e8815cdb74e9dfccadf971ebfb233a9c6a8 [file] [log] [blame]
Bram Moolenaar86b48162022-12-06 18:20:10 +00001" Vim syntax file
2" Language: Zig
3" Upstream: https://github.com/ziglang/zig.vim
4
5if exists("b:current_syntax")
6 finish
7endif
8
9let s:cpo_save = &cpo
10set cpo&vim
11
12let s:zig_syntax_keywords = {
13 \ 'zigBoolean': ["true"
14 \ , "false"]
15 \ , 'zigNull': ["null"]
16 \ , 'zigType': ["bool"
17 \ , "f16"
18 \ , "f32"
19 \ , "f64"
20 \ , "f80"
21 \ , "f128"
22 \ , "void"
23 \ , "type"
24 \ , "anytype"
25 \ , "anyerror"
26 \ , "anyframe"
27 \ , "volatile"
28 \ , "linksection"
29 \ , "noreturn"
30 \ , "allowzero"
31 \ , "i0"
32 \ , "u0"
33 \ , "isize"
34 \ , "usize"
35 \ , "comptime_int"
36 \ , "comptime_float"
37 \ , "c_short"
38 \ , "c_ushort"
39 \ , "c_int"
40 \ , "c_uint"
41 \ , "c_long"
42 \ , "c_ulong"
43 \ , "c_longlong"
44 \ , "c_ulonglong"
45 \ , "c_longdouble"
46 \ , "anyopaque"]
47 \ , 'zigConstant': ["undefined"
48 \ , "unreachable"]
49 \ , 'zigConditional': ["if"
50 \ , "else"
51 \ , "switch"]
52 \ , 'zigRepeat': ["while"
53 \ , "for"]
54 \ , 'zigComparatorWord': ["and"
55 \ , "or"
56 \ , "orelse"]
57 \ , 'zigStructure': ["struct"
58 \ , "enum"
59 \ , "union"
60 \ , "error"
61 \ , "packed"
62 \ , "opaque"]
63 \ , 'zigException': ["error"]
64 \ , 'zigVarDecl': ["var"
65 \ , "const"
66 \ , "comptime"
67 \ , "threadlocal"]
68 \ , 'zigDummyVariable': ["_"]
69 \ , 'zigKeyword': ["fn"
70 \ , "try"
71 \ , "test"
72 \ , "pub"
73 \ , "usingnamespace"]
74 \ , 'zigExecution': ["return"
75 \ , "break"
76 \ , "continue"]
77 \ , 'zigMacro': ["defer"
78 \ , "errdefer"
79 \ , "async"
80 \ , "nosuspend"
81 \ , "await"
82 \ , "suspend"
83 \ , "resume"
84 \ , "export"
85 \ , "extern"]
86 \ , 'zigPreProc': ["catch"
87 \ , "inline"
88 \ , "noinline"
89 \ , "asm"
90 \ , "callconv"
91 \ , "noalias"]
92 \ , 'zigBuiltinFn': ["align"
93 \ , "@addWithOverflow"
94 \ , "@as"
95 \ , "@atomicLoad"
96 \ , "@atomicStore"
97 \ , "@bitCast"
98 \ , "@breakpoint"
99 \ , "@alignCast"
100 \ , "@alignOf"
101 \ , "@cDefine"
102 \ , "@cImport"
103 \ , "@cInclude"
104 \ , "@cUndef"
105 \ , "@clz"
106 \ , "@cmpxchgWeak"
107 \ , "@cmpxchgStrong"
108 \ , "@compileError"
109 \ , "@compileLog"
110 \ , "@ctz"
111 \ , "@popCount"
112 \ , "@divExact"
113 \ , "@divFloor"
114 \ , "@divTrunc"
115 \ , "@embedFile"
116 \ , "@export"
117 \ , "@extern"
118 \ , "@tagName"
119 \ , "@TagType"
120 \ , "@errorName"
121 \ , "@call"
122 \ , "@errorReturnTrace"
123 \ , "@fence"
124 \ , "@fieldParentPtr"
125 \ , "@field"
126 \ , "@unionInit"
127 \ , "@frameAddress"
128 \ , "@import"
129 \ , "@newStackCall"
130 \ , "@asyncCall"
131 \ , "@intToPtr"
132 \ , "@max"
133 \ , "@min"
134 \ , "@memcpy"
135 \ , "@memset"
136 \ , "@mod"
137 \ , "@mulAdd"
138 \ , "@mulWithOverflow"
139 \ , "@splat"
140 \ , "@src"
141 \ , "@bitOffsetOf"
142 \ , "@byteOffsetOf"
143 \ , "@offsetOf"
144 \ , "@OpaqueType"
145 \ , "@panic"
146 \ , "@prefetch"
147 \ , "@ptrCast"
148 \ , "@ptrToInt"
149 \ , "@rem"
150 \ , "@returnAddress"
151 \ , "@setCold"
152 \ , "@Type"
153 \ , "@shuffle"
154 \ , "@reduce"
155 \ , "@select"
156 \ , "@setRuntimeSafety"
157 \ , "@setEvalBranchQuota"
158 \ , "@setFloatMode"
159 \ , "@shlExact"
160 \ , "@This"
161 \ , "@hasDecl"
162 \ , "@hasField"
163 \ , "@shlWithOverflow"
164 \ , "@shrExact"
165 \ , "@sizeOf"
166 \ , "@bitSizeOf"
167 \ , "@sqrt"
168 \ , "@byteSwap"
169 \ , "@subWithOverflow"
170 \ , "@intCast"
171 \ , "@floatCast"
172 \ , "@intToFloat"
173 \ , "@floatToInt"
174 \ , "@boolToInt"
175 \ , "@errSetCast"
176 \ , "@truncate"
177 \ , "@typeInfo"
178 \ , "@typeName"
179 \ , "@TypeOf"
180 \ , "@atomicRmw"
181 \ , "@intToError"
182 \ , "@errorToInt"
183 \ , "@intToEnum"
184 \ , "@enumToInt"
185 \ , "@setAlignStack"
186 \ , "@frame"
187 \ , "@Frame"
188 \ , "@frameSize"
189 \ , "@bitReverse"
190 \ , "@Vector"
191 \ , "@sin"
192 \ , "@cos"
193 \ , "@tan"
194 \ , "@exp"
195 \ , "@exp2"
196 \ , "@log"
197 \ , "@log2"
198 \ , "@log10"
199 \ , "@fabs"
200 \ , "@floor"
201 \ , "@ceil"
202 \ , "@trunc"
203 \ , "@wasmMemorySize"
204 \ , "@wasmMemoryGrow"
205 \ , "@round"]
206 \ }
207
208function! s:syntax_keyword(dict)
209 for key in keys(a:dict)
210 execute 'syntax keyword' key join(a:dict[key], ' ')
211 endfor
212endfunction
213
214call s:syntax_keyword(s:zig_syntax_keywords)
215
216syntax match zigType "\v<[iu][1-9]\d*>"
217syntax match zigOperator display "\V\[-+/*=^&?|!><%~]"
218syntax match zigArrowCharacter display "\V->"
219
220" 12_34 (. but not ..)? (12_34)? (exponent 12_34)?
221syntax match zigDecNumber display "\v<\d%(_?\d)*%(\.\.@!)?%(\d%(_?\d)*)?%([eE][+-]?\d%(_?\d)*)?"
222syntax match zigHexNumber display "\v<0x\x%(_?\x)*%(\.\.@!)?%(\x%(_?\x)*)?%([pP][+-]?\d%(_?\d)*)?"
223syntax match zigOctNumber display "\v<0o\o%(_?\o)*"
224syntax match zigBinNumber display "\v<0b[01]%(_?[01])*"
225
226syntax match zigCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/
227syntax match zigCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/
228syntax match zigCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=zigEscape,zigEscapeError,zigCharacterInvalid,zigCharacterInvalidUnicode
229syntax match zigCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{6}\)\)'/ contains=zigEscape,zigEscapeUnicode,zigEscapeError,zigCharacterInvalid
230
231syntax region zigBlock start="{" end="}" transparent fold
232
233syntax region zigCommentLine start="//" end="$" contains=zigTodo,@Spell
234syntax region zigCommentLineDoc start="//[/!]/\@!" end="$" contains=zigTodo,@Spell
235
236syntax match zigMultilineStringPrefix /c\?\\\\/ contained containedin=zigMultilineString
237syntax region zigMultilineString matchgroup=zigMultilineStringDelimiter start="c\?\\\\" end="$" contains=zigMultilineStringPrefix display
238
239syntax keyword zigTodo contained TODO
240
241syntax region zigString matchgroup=zigStringDelimiter start=+c\?"+ skip=+\\\\\|\\"+ end=+"+ oneline contains=zigEscape,zigEscapeUnicode,zigEscapeError,@Spell
242syntax match zigEscapeError display contained /\\./
243syntax match zigEscape display contained /\\\([nrt\\'"]\|x\x\{2}\)/
244syntax match zigEscapeUnicode display contained /\\\(u\x\{4}\|U\x\{6}\)/
245
246highlight default link zigDecNumber zigNumber
247highlight default link zigHexNumber zigNumber
248highlight default link zigOctNumber zigNumber
249highlight default link zigBinNumber zigNumber
250
251highlight default link zigBuiltinFn Statement
252highlight default link zigKeyword Keyword
253highlight default link zigType Type
254highlight default link zigCommentLine Comment
255highlight default link zigCommentLineDoc Comment
256highlight default link zigDummyVariable Comment
257highlight default link zigTodo Todo
258highlight default link zigString String
259highlight default link zigStringDelimiter String
260highlight default link zigMultilineString String
261highlight default link zigMultilineStringContent String
262highlight default link zigMultilineStringPrefix String
263highlight default link zigMultilineStringDelimiter Delimiter
264highlight default link zigCharacterInvalid Error
265highlight default link zigCharacterInvalidUnicode zigCharacterInvalid
266highlight default link zigCharacter Character
267highlight default link zigEscape Special
268highlight default link zigEscapeUnicode zigEscape
269highlight default link zigEscapeError Error
270highlight default link zigBoolean Boolean
271highlight default link zigNull Boolean
272highlight default link zigConstant Constant
273highlight default link zigNumber Number
274highlight default link zigArrowCharacter zigOperator
275highlight default link zigOperator Operator
276highlight default link zigStructure Structure
277highlight default link zigExecution Special
278highlight default link zigMacro Macro
279highlight default link zigConditional Conditional
280highlight default link zigComparatorWord Keyword
281highlight default link zigRepeat Repeat
282highlight default link zigSpecial Special
283highlight default link zigVarDecl Function
284highlight default link zigPreProc PreProc
285highlight default link zigException Exception
286
287delfunction s:syntax_keyword
288
289let b:current_syntax = "zig"
290
291let &cpo = s:cpo_save
292unlet! s:cpo_save