neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

zig.vim (11028B)


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