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