31383
|
1 " Vim syntax file
|
|
2 " Language: Zig
|
|
3 " Upstream: https://github.com/ziglang/zig.vim
|
|
4
|
|
5 if exists("b:current_syntax")
|
|
6 finish
|
|
7 endif
|
|
8
|
|
9 let s:cpo_save = &cpo
|
|
10 set cpo&vim
|
|
11
|
|
12 let 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
|
|
208 function! s:syntax_keyword(dict)
|
|
209 for key in keys(a:dict)
|
|
210 execute 'syntax keyword' key join(a:dict[key], ' ')
|
|
211 endfor
|
|
212 endfunction
|
|
213
|
|
214 call s:syntax_keyword(s:zig_syntax_keywords)
|
|
215
|
|
216 syntax match zigType "\v<[iu][1-9]\d*>"
|
|
217 syntax match zigOperator display "\V\[-+/*=^&?|!><%~]"
|
|
218 syntax match zigArrowCharacter display "\V->"
|
|
219
|
|
220 " 12_34 (. but not ..)? (12_34)? (exponent 12_34)?
|
|
221 syntax match zigDecNumber display "\v<\d%(_?\d)*%(\.\.@!)?%(\d%(_?\d)*)?%([eE][+-]?\d%(_?\d)*)?"
|
|
222 syntax match zigHexNumber display "\v<0x\x%(_?\x)*%(\.\.@!)?%(\x%(_?\x)*)?%([pP][+-]?\d%(_?\d)*)?"
|
|
223 syntax match zigOctNumber display "\v<0o\o%(_?\o)*"
|
|
224 syntax match zigBinNumber display "\v<0b[01]%(_?[01])*"
|
|
225
|
|
226 syntax match zigCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/
|
|
227 syntax match zigCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/
|
|
228 syntax match zigCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=zigEscape,zigEscapeError,zigCharacterInvalid,zigCharacterInvalidUnicode
|
|
229 syntax match zigCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{6}\)\)'/ contains=zigEscape,zigEscapeUnicode,zigEscapeError,zigCharacterInvalid
|
|
230
|
|
231 syntax region zigBlock start="{" end="}" transparent fold
|
|
232
|
|
233 syntax region zigCommentLine start="//" end="$" contains=zigTodo,@Spell
|
|
234 syntax region zigCommentLineDoc start="//[/!]/\@!" end="$" contains=zigTodo,@Spell
|
|
235
|
|
236 syntax match zigMultilineStringPrefix /c\?\\\\/ contained containedin=zigMultilineString
|
|
237 syntax region zigMultilineString matchgroup=zigMultilineStringDelimiter start="c\?\\\\" end="$" contains=zigMultilineStringPrefix display
|
|
238
|
|
239 syntax keyword zigTodo contained TODO
|
|
240
|
|
241 syntax region zigString matchgroup=zigStringDelimiter start=+c\?"+ skip=+\\\\\|\\"+ end=+"+ oneline contains=zigEscape,zigEscapeUnicode,zigEscapeError,@Spell
|
|
242 syntax match zigEscapeError display contained /\\./
|
|
243 syntax match zigEscape display contained /\\\([nrt\\'"]\|x\x\{2}\)/
|
|
244 syntax match zigEscapeUnicode display contained /\\\(u\x\{4}\|U\x\{6}\)/
|
|
245
|
|
246 highlight default link zigDecNumber zigNumber
|
|
247 highlight default link zigHexNumber zigNumber
|
|
248 highlight default link zigOctNumber zigNumber
|
|
249 highlight default link zigBinNumber zigNumber
|
|
250
|
|
251 highlight default link zigBuiltinFn Statement
|
|
252 highlight default link zigKeyword Keyword
|
|
253 highlight default link zigType Type
|
|
254 highlight default link zigCommentLine Comment
|
|
255 highlight default link zigCommentLineDoc Comment
|
|
256 highlight default link zigDummyVariable Comment
|
|
257 highlight default link zigTodo Todo
|
|
258 highlight default link zigString String
|
|
259 highlight default link zigStringDelimiter String
|
|
260 highlight default link zigMultilineString String
|
|
261 highlight default link zigMultilineStringContent String
|
|
262 highlight default link zigMultilineStringPrefix String
|
|
263 highlight default link zigMultilineStringDelimiter Delimiter
|
|
264 highlight default link zigCharacterInvalid Error
|
|
265 highlight default link zigCharacterInvalidUnicode zigCharacterInvalid
|
|
266 highlight default link zigCharacter Character
|
|
267 highlight default link zigEscape Special
|
|
268 highlight default link zigEscapeUnicode zigEscape
|
|
269 highlight default link zigEscapeError Error
|
|
270 highlight default link zigBoolean Boolean
|
|
271 highlight default link zigNull Boolean
|
|
272 highlight default link zigConstant Constant
|
|
273 highlight default link zigNumber Number
|
|
274 highlight default link zigArrowCharacter zigOperator
|
|
275 highlight default link zigOperator Operator
|
|
276 highlight default link zigStructure Structure
|
|
277 highlight default link zigExecution Special
|
|
278 highlight default link zigMacro Macro
|
|
279 highlight default link zigConditional Conditional
|
|
280 highlight default link zigComparatorWord Keyword
|
|
281 highlight default link zigRepeat Repeat
|
|
282 highlight default link zigSpecial Special
|
|
283 highlight default link zigVarDecl Function
|
|
284 highlight default link zigPreProc PreProc
|
|
285 highlight default link zigException Exception
|
|
286
|
|
287 delfunction s:syntax_keyword
|
|
288
|
|
289 let b:current_syntax = "zig"
|
|
290
|
|
291 let &cpo = s:cpo_save
|
|
292 unlet! s:cpo_save
|