diff --git a/syntax/zig.vim b/syntax/zig.vim index 031bf7a..bfe8309 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -1,3 +1,4 @@ +" PRELUDE {{{1 " Vim syntax file " Language: Zig " Maintainer: Andrew Kelley @@ -6,288 +7,184 @@ if exists("b:current_syntax") finish endif +let b:current_syntax = "zig" 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_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" - \ , "@alignCast" - \ , "@alignOf" - \ , "@cDefine" - \ , "@cImport" - \ , "@cInclude" - \ , "@cUndef" - \ , "@clz" - \ , "@cmpxchgWeak" - \ , "@cmpxchgStrong" - \ , "@compileError" - \ , "@compileLog" - \ , "@ctz" - \ , "@popCount" - \ , "@divExact" - \ , "@divFloor" - \ , "@divTrunc" - \ , "@embedFile" - \ , "@export" - \ , "@extern" - \ , "@tagName" - \ , "@TagType" - \ , "@errorName" - \ , "@call" - \ , "@errorReturnTrace" - \ , "@fence" - \ , "@fieldParentPtr" - \ , "@field" - \ , "@unionInit" - \ , "@frameAddress" - \ , "@import" - \ , "@newStackCall" - \ , "@asyncCall" - \ , "@intToPtr" - \ , "@maximum" - \ , "@minimum" - \ , "@memcpy" - \ , "@memset" - \ , "@mod" - \ , "@mulAdd" - \ , "@mulWithOverflow" - \ , "@splat" - \ , "@src" - \ , "@bitOffsetOf" - \ , "@byteOffsetOf" - \ , "@offsetOf" - \ , "@OpaqueType" - \ , "@panic" - \ , "@prefetch" - \ , "@ptrCast" - \ , "@ptrToInt" - \ , "@rem" - \ , "@returnAddress" - \ , "@setCold" - \ , "@Type" - \ , "@shuffle" - \ , "@reduce" - \ , "@select" - \ , "@setRuntimeSafety" - \ , "@setEvalBranchQuota" - \ , "@setFloatMode" - \ , "@shlExact" - \ , "@This" - \ , "@hasDecl" - \ , "@hasField" - \ , "@shlWithOverflow" - \ , "@shrExact" - \ , "@sizeOf" - \ , "@bitSizeOf" - \ , "@sqrt" - \ , "@byteSwap" - \ , "@subWithOverflow" - \ , "@intCast" - \ , "@floatCast" - \ , "@intToFloat" - \ , "@floatToInt" - \ , "@boolToInt" - \ , "@errSetCast" - \ , "@truncate" - \ , "@typeInfo" - \ , "@typeName" - \ , "@TypeOf" - \ , "@atomicRmw" - \ , "@intToError" - \ , "@errorToInt" - \ , "@intToEnum" - \ , "@enumToInt" - \ , "@setAlignStack" - \ , "@frame" - \ , "@Frame" - \ , "@frameSize" - \ , "@bitReverse" - \ , "@Vector" - \ , "@sin" - \ , "@cos" - \ , "@tan" - \ , "@exp" - \ , "@exp2" - \ , "@log" - \ , "@log2" - \ , "@log10" - \ , "@fabs" - \ , "@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" +" SYNTAX {{{1 +syn case match +syn iskeyword @,48-57,@-@,_ + +" KEYWORDS {{{2 +syn keyword zigConditional if else switch +syn keyword zigException catch errdefer orelse try +syn keyword zigKeyword asm +syn keyword zigKeyword async await +syn keyword zigKeyword break continue return +syn keyword zigKeyword comptime +syn keyword zigKeyword defer +syn keyword zigKeyword fn +syn keyword zigKeyword pub +syn keyword zigKeyword resume suspend nosuspend +syn keyword zigKeyword test +syn keyword zigKeyword unreachable +syn keyword zigKeyword usingnamespace +syn keyword zigOperator and or +syn keyword zigRepeat for while +syn keyword zigStorageClass align +syn keyword zigStorageClass allowzero +syn keyword zigStorageClass callconv +syn keyword zigStorageClass const var volatile +syn keyword zigStorageClass export extern +syn keyword zigStorageClass linksection +syn keyword zigStorageClass noalias +syn keyword zigStorageClass packed +syn keyword zigStorageClass threadlocal +syn keyword zigStructure enum error opaque struct union + +" BUILTINS {{{2 +syn keyword zigBuiltin @addWithOverflow @mulWithOverflow @subWithOverflow +syn keyword zigBuiltin @alignCast @bitCast +syn keyword zigBuiltin @alignOf @offsetOf @sizeOf +syn keyword zigBuiltin @as +syn keyword zigBuiltin @asyncCall +syn keyword zigBuiltin @atomicLoad @atomicStore @atomicRmw +syn keyword zigBuiltin @bitOffsetOf @bitSizeOf +syn keyword zigBuiltin @bitReverse +syn keyword zigBuiltin @boolToInt @enumToInt @errorToInt @floatToInt @ptrToInt +syn keyword zigBuiltin @breakpoint +syn keyword zigBuiltin @byteSwap +syn keyword zigBuiltin @call +syn keyword zigBuiltin @ceil @floor @round @trunc +syn keyword zigBuiltin @clz @ctz +syn keyword zigBuiltin @cmpxchgStrong @cmpxchgWeak +syn keyword zigBuiltin @compileError @compileLog +syn keyword zigBuiltin @divExact @divFloor @divTrunc +syn keyword zigBuiltin @embedFile +syn keyword zigBuiltin @errorName @errorReturnTrace +syn keyword zigBuiltin @errSetCast @floatCast @intCast @ptrCast +syn keyword zigBuiltin @exp @exp2 +syn keyword zigBuiltin @export @extern +syn keyword zigBuiltin @fabs +syn keyword zigBuiltin @fence +syn keyword zigBuiltin @field @fieldParentPtr @hasField +syn keyword zigBuiltin @Frame @frame @frameAddress @frameSize +syn keyword zigBuiltin @hasDecl +syn keyword zigBuiltin @import +syn keyword zigBuiltin @intToEnum @intToError @intToFloat @intToPtr +syn keyword zigBuiltin @log @log2 @log10 +syn keyword zigBuiltin @maximum @minimum +syn keyword zigBuiltin @memcpy @memset +syn keyword zigBuiltin @mod @rem +syn keyword zigBuiltin @mulAdd +syn keyword zigBuiltin @panic +syn keyword zigBuiltin @popCount +syn keyword zigBuiltin @prefetch +syn keyword zigBuiltin @reduce @select +syn keyword zigBuiltin @returnAddress +syn keyword zigBuiltin @setAlignStack @setCold +syn keyword zigBuiltin @setEvalBranchQuota @setFloatMode @setRuntimeSafety +syn keyword zigBuiltin @shlExact @shrExact @shlWithOverflow +syn keyword zigBuiltin @shuffle +syn keyword zigBuiltin @sin @cos @tan +syn keyword zigBuiltin @sqrt +syn keyword zigBuiltin @src +syn keyword zigBuiltin @tagName +syn keyword zigBuiltin @This +syn keyword zigBuiltin @truncate +syn keyword zigBuiltin @Type @TypeOf @typeInfo @typeName +syn keyword zigBuiltin @unionInit +syn keyword zigBuiltin @Vector @splat +syn keyword zigBuiltin @wasmMemoryGrow @wasmMemorySize + +" C ABI. +syn keyword zigBuiltin @cDefine @cImport @cInclude @cUndef + +" TYPES {{{2 +syn keyword zigType anyerror anyframe anyopaque anytype +syn keyword zigType bool +syn keyword zigType comptime_float comptime_int +syn keyword zigType f16 f32 f64 f128 +syn keyword zigType isize usize +syn keyword zigType noreturn +syn keyword zigType type +syn keyword zigType void + +" C ABI. +syn keyword zigType c_int c_uint +syn keyword zigType c_long c_ulong +syn keyword zigType c_longdouble +syn keyword zigType c_longlong c_ulonglong +syn keyword zigType c_short c_ushort + +" Integer types of arbitrary bit-width. +syn match zigType "\v<[iu]\d+>" display + +" LITERALS {{{2 +syn keyword zigBoolean true false +syn keyword zigConstant null undefined + +" Number literals. +syn match zigNumber "\v<\d(_?\d)*>" display +syn match zigNumber "\v<0b[01](_?[01])*>" display +syn match zigNumber "\v<0o\o(_?\o)*>" display +syn match zigNumber "\v<0x\x(_?\x)*>" display + +" Floating-point number literals. +syn match zigFloat "\v<\d(_?\d)*\.\d(_?\d)*>" display +syn match zigFloat "\v<\d(_?\d)*(\.\d(_?\d)*)?[Ee][+-]?\d(_?\d)*>" display +syn match zigFloat "\v<0x\x(_?\x)*\.\x(_?\x)*>" display +syn match zigFloat "\v<0x\x(_?\x)*(\.\x(_?\x)*)?[Pp][+-]?\x(_?\x)*>" display + +" String and character literals. +syn match zigEscape "\\[\\'"nrt]" contained display +syn match zigEscape "\\x\x\{2}" contained display +syn match zigEscape "\v\\u\{\x{1,6}}" contained display +syn match zigFormat "\v\{(\d+|\[\h\w*])?([!?]*([!?*Xbcdeosux]|any))?(:(([^\\]|\\([\\'"nrt]|x\x{2}|u\{\x{1,6}}))[<>^]|[<>^])?\d*(\.\d*)?)?}" contained contains=zigEscape display +syn region zigCharacter start="'" end="'\|$" skip="\\'" contains=zigEscape display extend +syn region zigString start=+"+ end=+"\|$+ skip=+\\"+ contains=zigEscape,zigFormat display extend +syn region zigString start="^\s*\\\\" end="$" display + +" MISCELLANEOUS {{{2 +syn keyword zigTodo FIXME TODO XXX contained + +" Blocks. +syn region zigBlock start="{" end="}" fold transparent + +" Comments. +syn region zigComment start="//" end="$" contains=zigTodo,@Spell display +syn region zigCommentDoc start="^\s*\zs//\(//\@!\|!\)" end="$" contains=zigTodo,@Spell display + +" Identifiers using the @"" syntax. +syn match zigIdentifier +@".*"+ display + +" Special operators. +syn match zigSpecial "\.\zs[*?]" display + +" DEFAULT HIGHLIGHTING {{{1 +hi def link zigBoolean Boolean +hi def link zigBuiltin Function +hi def link zigCharacter Character +hi def link zigComment Comment +hi def link zigCommentDoc SpecialComment +hi def link zigConditional Conditional +hi def link zigConstant Constant +hi def link zigEscape SpecialChar +hi def link zigException Exception +hi def link zigFloat Float +hi def link zigFormat SpecialChar +hi def link zigIdentifier Identifier +hi def link zigKeyword Keyword +hi def link zigNumber Number +hi def link zigOperator Operator +hi def link zigRepeat Repeat +hi def link zigSpecial Special +hi def link zigStorageClass StorageClass +hi def link zigString String +hi def link zigStructure Structure +hi def link zigTodo Todo +hi def link zigType Type let &cpo = s:cpo_save unlet! s:cpo_save