Skip to content

update syntax highlighting to more closely match existing languages #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
243 changes: 27 additions & 216 deletions syntax/zig.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,214 +10,26 @@ 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"]
\ , 'zigExecution': ["return"
\ , "break"
\ , "continue"]
\ , 'zigMacro': ["defer"
\ , "errdefer"
\ , "nosuspend"
\ , "suspend"
\ , "resume"
\ , "export"
\ , "extern"]
\ , 'zigPreProc': ["addrspace"
\ , "align"
\ , "asm"
\ , "callconv"
\ , "catch"
\ , "inline"
\ , "noalias"
\ , "noinline"]
\ , 'zigBuiltinFn': ["@addrSpaceCast"
\ , "@addWithOverflow"
\ , "@alignCast"
\ , "@alignOf"
\ , "@as"
\ , "@atomicLoad"
\ , "@atomicRmw"
\ , "@atomicStore"
\ , "@bitCast"
\ , "@bitOffsetOf"
\ , "@bitSizeOf"
\ , "@branchHint"
\ , "@breakpoint"
\ , "@mulAdd"
\ , "@byteSwap"
\ , "@bitReverse"
\ , "@offsetOf"
\ , "@call"
\ , "@cDefine"
\ , "@cImport"
\ , "@cInclude"
\ , "@clz"
\ , "@cmpxchgStrong"
\ , "@cmpxchgWeak"
\ , "@compileError"
\ , "@compileLog"
\ , "@constCast"
\ , "@ctz"
\ , "@cUndef"
\ , "@cVaArg"
\ , "@cVaCopy"
\ , "@cVaEnd"
\ , "@cVaStart"
\ , "@disableInstrumentation"
\ , "@disableIntrinsics"
\ , "@divExact"
\ , "@divFloor"
\ , "@divTrunc"
\ , "@embedFile"
\ , "@enumFromInt"
\ , "@errorFromInt"
\ , "@errorName"
\ , "@errorReturnTrace"
\ , "@errorCast"
\ , "@export"
\ , "@extern"
\ , "@field"
\ , "@fieldParentPtr"
\ , "@FieldType"
\ , "@floatCast"
\ , "@floatFromInt"
\ , "@frameAddress"
\ , "@hasDecl"
\ , "@hasField"
\ , "@import"
\ , "@inComptime"
\ , "@intCast"
\ , "@intFromBool"
\ , "@intFromEnum"
\ , "@intFromError"
\ , "@intFromFloat"
\ , "@intFromPtr"
\ , "@max"
\ , "@memcpy"
\ , "@memmove"
\ , "@memset"
\ , "@min"
\ , "@wasmMemorySize"
\ , "@wasmMemoryGrow"
\ , "@mod"
\ , "@mulWithOverflow"
\ , "@panic"
\ , "@popCount"
\ , "@prefetch"
\ , "@ptrCast"
\ , "@ptrFromInt"
\ , "@rem"
\ , "@returnAddress"
\ , "@select"
\ , "@setEvalBranchQuota"
\ , "@setFloatMode"
\ , "@setRuntimeSafety"
\ , "@shlExact"
\ , "@shlWithOverflow"
\ , "@shrExact"
\ , "@shuffle"
\ , "@sizeOf"
\ , "@splat"
\ , "@reduce"
\ , "@src"
\ , "@sqrt"
\ , "@sin"
\ , "@cos"
\ , "@tan"
\ , "@exp"
\ , "@exp2"
\ , "@log"
\ , "@log2"
\ , "@log10"
\ , "@abs"
\ , "@floor"
\ , "@ceil"
\ , "@trunc"
\ , "@round"
\ , "@subWithOverflow"
\ , "@tagName"
\ , "@This"
\ , "@trap"
\ , "@truncate"
\ , "@Type"
\ , "@typeInfo"
\ , "@typeName"
\ , "@TypeOf"
\ , "@unionInit"
\ , "@Vector"
\ , "@volatileCast"
\ , "@workGroupId"
\ , "@workGroupSize"
\ , "@workItemId"]
\ }

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 keyword zigBoolean true false
syntax keyword zigNull null
syntax keyword zigType bool void type anytype anyerror anyframe noreturn anyopaque
syntax keyword zigType i0 u0 isize usize comptime_int comptime_float
syntax keyword zigType f16 f32 f64 f80 f128
syntax keyword zigType c_char c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_longdouble
syntax keyword zigConstant undefined unreachable
syntax keyword zigConditional if else switch
syntax keyword zigRepeat while for
syntax keyword zigComparatorWord and or orelse
syntax keyword zigStructure struct enum union error packed opaque
syntax keyword zigException catch error try
syntax keyword zigAccessModifier pub
syntax keyword zigStorageClass addrspace align allowzero callconv extern export linksection threadlocal volatile
syntax keyword zigDummyVariable _
syntax keyword zigKeyword var const fn test
syntax keyword zigStatement return break continue asm defer errdefer
syntax keyword zigAsync nosuspend suspend resume
syntax keyword zigPreProc comptime inline noalias noinline
syntax keyword zigBuiltinFn @addrSpaceCast @addWithOverflow @alignCast @alignOf @as @atomicLoad @atomicRmw @atomicStore @bitCast @bitOffsetOf @bitSizeOf @branchHint @breakpoint @mulAdd @byteSwap @bitReverse @offsetOf @call @cDefine @cImport @cInclude @clz @cmpxchgStrong @cmpxchgWeak @compileError @compileLog @constCast @ctz @cUndef @cVaArg @cVaCopy @cVaEnd @cVaStart @disableInstrumentation @disableIntrinsics @divExact @divFloor @divTrunc @embedFile @enumFromInt @errorFromInt @errorName @errorReturnTrace @errorCast @export @extern @field @fieldParentPtr @FieldType @floatCast @floatFromInt @frameAddress @hasDecl @hasField @import @inComptime @intCast @intFromBool @intFromEnum @intFromError @intFromFloat @intFromPtr @max @memcpy @memmove @memset @min @wasmMemorySize @wasmMemoryGrow @mod @mulWithOverflow @panic @popCount @prefetch @ptrCast @ptrFromInt @rem @returnAddress @select @setEvalBranchQuota @setFloatMode @setRuntimeSafety @shlExact @shlWithOverflow @shrExact @shuffle @sizeOf @splat @reduce @src @sqrt @sin @cos @tan @exp @exp2 @log @log2 @log10 @abs @floor @ceil @trunc @round @subWithOverflow @tagName @This @trap @truncate @Type @typeInfo @typeName @TypeOf @unionInit @Vector @volatileCast @workGroupId @workGroupSize @workItemId

syntax match zigType "\v<[iu][1-9]\d*>"
syntax match zigOperator display "\V\[-+/*=^&?|!><%~]"
Expand Down Expand Up @@ -254,7 +66,7 @@ highlight default link zigHexNumber zigNumber
highlight default link zigOctNumber zigNumber
highlight default link zigBinNumber zigNumber

highlight default link zigBuiltinFn Statement
highlight default link zigBuiltinFn Function
highlight default link zigKeyword Keyword
highlight default link zigType Type
highlight default link zigCommentLine Comment
Expand All @@ -274,24 +86,23 @@ 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 zigNull Constant
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 zigStatement Statement
highlight default link zigConditional Conditional
highlight default link zigComparatorWord Keyword
highlight default link zigComparatorWord zigStatement
highlight default link zigRepeat Repeat
highlight default link zigSpecial Special
highlight default link zigVarDecl Function
highlight default link zigAccessModifier StorageClass
highlight default link zigStorageClass StorageClass
highlight default link zigAsync Keyword
highlight default link zigPreProc PreProc
highlight default link zigException Exception

delfunction s:syntax_keyword

let b:current_syntax = "zig"

let &cpo = s:cpo_save
Expand Down