From 5c9cb63c7671d45a8d19937939f310738c3ec293 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sun, 15 Jun 2025 19:44:35 +0200 Subject: [PATCH 01/10] flatten the zig_syntax_keywords dictionary in syntax/zig.vim This change shouldn't have any functional changes but should make the next commits more readable. --- syntax/zig.vim | 230 +++++-------------------------------------------- 1 file changed, 20 insertions(+), 210 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index e4fbc84..124389e 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -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 volatile linksection noreturn allowzero 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 error +syntax keyword zigStorageClass +syntax keyword zigVarDecl var const comptime threadlocal +syntax keyword zigDummyVariable _ +syntax keyword zigKeyword fn try test pub +syntax keyword zigExecution return break continue +syntax keyword zigMacro defer errdefer nosuspend suspend resume export extern +syntax keyword zigPreProc addrspace align asm callconv catch 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\[-+/*=^&?|!><%~]" @@ -290,8 +102,6 @@ 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 From c8dec45cf3b2b502138b593a4879727065d93ada Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sun, 15 Jun 2025 19:36:43 +0200 Subject: [PATCH 02/10] remove the zigVarDecl group which maps to Function The previous mapping made no sense. The mapping of threadlocal and comptime will be changed in future commits. As a reference I used the builtin syntax highlighting from neovim for the following languages that have similar keywords to Zig's `var` and `const`: - Rust: `let` - Go: `var` - Javascript: `var`,`let`, `const` They all map their keywords to the Keyword syntax highlighting group. --- syntax/zig.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 124389e..5c04875 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -23,12 +23,11 @@ syntax keyword zigComparatorWord and or orelse syntax keyword zigStructure struct enum union error packed opaque syntax keyword zigException error syntax keyword zigStorageClass -syntax keyword zigVarDecl var const comptime threadlocal syntax keyword zigDummyVariable _ -syntax keyword zigKeyword fn try test pub +syntax keyword zigKeyword var const fn try test pub comptime syntax keyword zigExecution return break continue syntax keyword zigMacro defer errdefer nosuspend suspend resume export extern -syntax keyword zigPreProc addrspace align asm callconv catch inline noalias noinline +syntax keyword zigPreProc addrspace align asm callconv catch inline noalias noinline threadlocal 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*>" @@ -98,7 +97,6 @@ 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 From a2d7c41451952c66c0c7351c662fd1758e837ff9 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sun, 22 Jun 2025 19:03:57 +0200 Subject: [PATCH 03/10] update mappings of control flow keywords All control flow keywords are now mapped to either Keyword, Statement or Conditional. Previously some of them would be mapped to Special, PreProc or Macro. As a reference I used the builtin syntax highlighting from neovim for the following languages that have similar control flow keywords to Zig: - Rust: - Keyword: return break continue - Conditional: match if else - Repeat: loop while (actually maps to Conditional) - C - Statement: goto break return continue asm - Conditional: if else switch - Repeat: while for do - C#: Conditional, Repeat - Conditional: else if switch - Repeat: break continue do for foreach goto return while - JS - Statement: return with await yield - Conditional: if else switch break continue - Repeat: while for do in of - Go - Statement: defer go goto return break continue fallthrough - Conditional: if else switch select - Repeat: for range - Zig (old) - Macro: defer errdefer - PreProc: asm - Special: return break continue - Conditional: if else switch - Repeat: while for - Keyword: and or orelse - Zig (new) - Statement: return break continue asm defer errdefer and or orelse - Conditional: if else switch - Repeat: while for The try and catch keywords will be adjusted in a future commit. --- syntax/zig.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 5c04875..ead8680 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -25,9 +25,9 @@ syntax keyword zigException error syntax keyword zigStorageClass syntax keyword zigDummyVariable _ syntax keyword zigKeyword var const fn try test pub comptime -syntax keyword zigExecution return break continue -syntax keyword zigMacro defer errdefer nosuspend suspend resume export extern -syntax keyword zigPreProc addrspace align asm callconv catch inline noalias noinline threadlocal +syntax keyword zigStatement return break continue asm defer errdefer +syntax keyword zigMacro nosuspend suspend resume export extern +syntax keyword zigPreProc addrspace align callconv catch inline noalias noinline threadlocal 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*>" @@ -91,10 +91,10 @@ 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 zigPreProc PreProc From 537c1cf69e84f697bff0709cd99c29c5d6563ad3 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 14 Jun 2025 12:12:48 +0200 Subject: [PATCH 04/10] map async related keywords to a zigAsync group and link it to Keyword The nosuspend keyword is syntactically different from the other keywords so this mapping isn't quite right. --- syntax/zig.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index ead8680..e5f7faa 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -26,7 +26,8 @@ syntax keyword zigStorageClass syntax keyword zigDummyVariable _ syntax keyword zigKeyword var const fn try test pub comptime syntax keyword zigStatement return break continue asm defer errdefer -syntax keyword zigMacro nosuspend suspend resume export extern +syntax keyword zigMacro export extern +syntax keyword zigAsync nosuspend suspend resume syntax keyword zigPreProc addrspace align callconv catch inline noalias noinline threadlocal 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 @@ -97,6 +98,7 @@ highlight default link zigConditional Conditional highlight default link zigComparatorWord zigStatement highlight default link zigRepeat Repeat highlight default link zigSpecial Special +highlight default link zigAsync Keyword highlight default link zigPreProc PreProc highlight default link zigException Exception From 3ef8ac2681d90d5c005ab5f572827b083b7918a6 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 14 Jun 2025 12:44:43 +0200 Subject: [PATCH 05/10] map various keywords to zigStorageClass that links to StorageClass - volatile, linksection and allowzero obviously aren't types. The differentiation between what is mapped to "StorageClass" or "PreProc" isn't very clear. At least it's less scattered than the previous mappings. --- syntax/zig.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index e5f7faa..4b0ffd3 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -12,7 +12,7 @@ set cpo&vim syntax keyword zigBoolean true false syntax keyword zigNull null -syntax keyword zigType bool void type anytype anyerror anyframe volatile linksection noreturn allowzero anyopaque +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 @@ -22,13 +22,12 @@ syntax keyword zigRepeat while for syntax keyword zigComparatorWord and or orelse syntax keyword zigStructure struct enum union error packed opaque syntax keyword zigException error -syntax keyword zigStorageClass +syntax keyword zigStorageClass addrspace align allowzero callconv extern export linksection threadlocal volatile syntax keyword zigDummyVariable _ syntax keyword zigKeyword var const fn try test pub comptime syntax keyword zigStatement return break continue asm defer errdefer -syntax keyword zigMacro export extern syntax keyword zigAsync nosuspend suspend resume -syntax keyword zigPreProc addrspace align callconv catch inline noalias noinline threadlocal +syntax keyword zigPreProc catch 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*>" @@ -92,12 +91,12 @@ highlight default link zigNumber Number highlight default link zigArrowCharacter zigOperator highlight default link zigOperator Operator highlight default link zigStructure Structure -highlight default link zigMacro Macro highlight default link zigStatement Statement highlight default link zigConditional Conditional highlight default link zigComparatorWord zigStatement highlight default link zigRepeat Repeat highlight default link zigSpecial Special +highlight default link zigStorageClass StorageClass highlight default link zigAsync Keyword highlight default link zigPreProc PreProc highlight default link zigException Exception From 452f68a6c889a1d9dae886cb967a8227f93927f1 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 14 Jun 2025 11:52:48 +0200 Subject: [PATCH 06/10] map pub keyword to a zigAccessModifier group and link it to StorageClass As a reference I used the syntax highlighting that neovim uses for the following languages that have similar keywords to Zig's `pub`: - C++: - Statement: public protected private - Rust: - Keyword: pub - C#: - StorageClass: internal private protected public - JS: - Keyword: private protected public --- syntax/zig.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 4b0ffd3..e047578 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -22,9 +22,10 @@ syntax keyword zigRepeat while for syntax keyword zigComparatorWord and or orelse syntax keyword zigStructure struct enum union error packed opaque syntax keyword zigException error +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 try test pub comptime +syntax keyword zigKeyword var const fn try test comptime syntax keyword zigStatement return break continue asm defer errdefer syntax keyword zigAsync nosuspend suspend resume syntax keyword zigPreProc catch inline noalias noinline @@ -96,6 +97,7 @@ highlight default link zigConditional Conditional highlight default link zigComparatorWord zigStatement highlight default link zigRepeat Repeat highlight default link zigSpecial Special +highlight default link zigAccessModifier StorageClass highlight default link zigStorageClass StorageClass highlight default link zigAsync Keyword highlight default link zigPreProc PreProc From 0bf9e945b3334644e4bf85be34f08a4fbd71296f Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 14 Jun 2025 12:31:16 +0200 Subject: [PATCH 07/10] map all error related keywords to zigException The `error` keyword has two different appearances in sytnax that should be differentiated between. For now, this keyword remains mapped twice which isn't correct. I have tested these changes with the following colorschemes: - folke/tokyonight.nvim - morhetz/gruvbox - catppuccin/nvim - joshdick/onedark.vim - Neovim's "vim" colorscheme All of themes appear to map "Exception" to "Statement" which matches well with other keywords in said group. --- syntax/zig.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index e047578..15e0791 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -21,14 +21,14 @@ 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 error +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 try test comptime +syntax keyword zigKeyword var const fn test comptime syntax keyword zigStatement return break continue asm defer errdefer syntax keyword zigAsync nosuspend suspend resume -syntax keyword zigPreProc catch inline noalias noinline +syntax keyword zigPreProc 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*>" From 67ad826c9d052b49518aabc70d7920868d76e1e4 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 14 Jun 2025 12:32:06 +0200 Subject: [PATCH 08/10] map comptime keyword to zigPreProc The "Keyword" group now only has keywords that introduce new declarations --- syntax/zig.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 15e0791..32d1a5c 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -25,10 +25,10 @@ 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 comptime +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 inline noalias noinline +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*>" From a6d71c5de9f4346dc14650aa5949d93dc9341b18 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 14 Jun 2025 11:54:16 +0200 Subject: [PATCH 09/10] link the zigBuiltinFn group to Function instead of Statement by default Previously builtin functions were the only thing mapped to "Statement". Now, some control flow keywords are mapped to "Statement", so builtin functions are instead mapped to the more reasonable "Function" group. I believe that "Statement" was previously picked to ensure that builtin functions get a color that would stand out and be unique. Function may not get an equally prominent color but still be unique (usually). Depending on how this affects various colorschemes, it may also make sense to map builtin functions to a different group like "Special". --- syntax/zig.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 32d1a5c..dfb9965 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -66,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 From aa241a57df595bc18912751adbadd43b0ce985bc Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 14 Jun 2025 11:54:47 +0200 Subject: [PATCH 10/10] link the zigNull group to Constant instead of Boolean by default Most colorschemes will still map "Boolean" to "Constant". --- syntax/zig.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index dfb9965..6949dd4 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -86,7 +86,7 @@ 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