From 6393e88fb42a1bcb9fe96db3435495b384e24409 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Thu, 30 Sep 2021 12:38:54 -0500 Subject: [PATCH 1/9] Make string delimiters the same color as strings --- syntax/zig.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index e150ab4..2753d2e 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -248,7 +248,7 @@ highlight default link zigCommentLineDoc Comment highlight default link zigDummyVariable Comment highlight default link zigTodo Todo highlight default link zigString String -highlight default link zigStringDelimiter Delimiter +highlight default link zigStringDelimiter String highlight default link zigMultilineString String highlight default link zigMultilineStringContent String highlight default link zigMultilineStringPrefix String From 204860e562509c8d2d9c80703959e5bfe2fcdeaf Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:05:09 -0700 Subject: [PATCH 2/9] syntax: reorganize keywords This commit is a substantial reorganization and general cleanup of existing keywords. Several highlight groups have been adjusted and compiler builtins that no longer exist have been removed. --- syntax/zig.vim | 339 +++++++++++++++++-------------------------------- 1 file changed, 116 insertions(+), 223 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 031bf7a..64a300b 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -10,209 +10,110 @@ 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_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) +syn case match +syn iskeyword @,48-57,@-@,_ + +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 + +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 + +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 + +syn keyword zigBoolean true false +syn keyword zigConstant null undefined syntax match zigType "\v<[iu][1-9]\d*>" syntax match zigOperator display "\V\[-+/*=^&?|!><%~]" @@ -244,17 +145,25 @@ 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}\)/ +hi def link zigBoolean Boolean +hi def link zigBuiltin Function +hi def link zigConditional Conditional +hi def link zigConstant Constant +hi def link zigException Exception +hi def link zigKeyword Keyword +hi def link zigOperator Operator +hi def link zigRepeat Repeat +hi def link zigStorageClass StorageClass +hi def link zigStructure Structure +hi def link zigType Type + 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 @@ -268,24 +177,8 @@ 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" From 7c5a33c7ec997344b06661532fc77789b3405f78 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:07:30 -0700 Subject: [PATCH 3/9] syntax: improve arbitrary bit=width integer types The previous syntax highlighting did not match all valid arbitrary bit-width integer types. This commit allows those with leading zeros to be highlighted as well. --- syntax/zig.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 64a300b..81af16b 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -112,10 +112,12 @@ 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 + syn keyword zigBoolean true false syn keyword zigConstant null undefined -syntax match zigType "\v<[iu][1-9]\d*>" syntax match zigOperator display "\V\[-+/*=^&?|!><%~]" syntax match zigArrowCharacter display "\V->" From 3515c51b387530258e16d1e501fc4af71770817c Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:11:10 -0700 Subject: [PATCH 4/9] syntax: reorganize syntax highlighting for numbers --- syntax/zig.vim | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 81af16b..5de2f8f 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -118,15 +118,21 @@ syn match zigType "\v<[iu]\d+>" display 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 + 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 @@ -152,18 +158,15 @@ hi def link zigBuiltin Function hi def link zigConditional Conditional hi def link zigConstant Constant hi def link zigException Exception +hi def link zigFloat Float hi def link zigKeyword Keyword +hi def link zigNumber Number hi def link zigOperator Operator hi def link zigRepeat Repeat hi def link zigStorageClass StorageClass hi def link zigStructure Structure hi def link zigType Type -highlight default link zigDecNumber zigNumber -highlight default link zigHexNumber zigNumber -highlight default link zigOctNumber zigNumber -highlight default link zigBinNumber zigNumber - highlight default link zigCommentLine Comment highlight default link zigCommentLineDoc Comment highlight default link zigTodo Todo @@ -179,7 +182,6 @@ highlight default link zigCharacter Character highlight default link zigEscape Special highlight default link zigEscapeUnicode zigEscape highlight default link zigEscapeError Error -highlight default link zigNumber Number highlight default link zigArrowCharacter zigOperator let b:current_syntax = "zig" From 03d19a6ec31b66725242e7f649455d2515770735 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:13:55 -0700 Subject: [PATCH 5/9] syntax: improve string and character literals This commit heavily reorganizes the syntax highlighting for strings and characters and adds new support for format strings. --- syntax/zig.vim | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 5de2f8f..8234226 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -130,58 +130,46 @@ 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 + syntax match zigOperator display "\V\[-+/*=^&?|!><%~]" syntax match zigArrowCharacter display "\V->" -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}\)/ - hi def link zigBoolean Boolean hi def link zigBuiltin Function +hi def link zigCharacter Character 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 zigKeyword Keyword hi def link zigNumber Number hi def link zigOperator Operator hi def link zigRepeat Repeat hi def link zigStorageClass StorageClass +hi def link zigString String hi def link zigStructure Structure hi def link zigType Type highlight default link zigCommentLine Comment highlight default link zigCommentLineDoc 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 zigArrowCharacter zigOperator let b:current_syntax = "zig" From 7bb71e6de634085e96ce6227d3a8af4843399605 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:16:57 -0700 Subject: [PATCH 6/9] syntax: organize file into distinct sections This commit reorganizes the syntax file into several sections. The heading of each section can be folded with :set foldmethod=marker. --- syntax/zig.vim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 8234226..05f74b4 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -1,3 +1,4 @@ +" PRELUDE {{{1 " Vim syntax file " Language: Zig " Maintainer: Andrew Kelley @@ -6,13 +7,16 @@ if exists("b:current_syntax") finish endif +let b:current_syntax = "zig" let s:cpo_save = &cpo set cpo&vim +" 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 @@ -39,6 +43,7 @@ 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 @@ -96,6 +101,7 @@ 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 @@ -115,6 +121,7 @@ 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 @@ -139,6 +146,7 @@ syn region zigCharacter start="'" end="'\|$" skip="\\'" contains=zigEscape displ syn region zigString start=+"+ end=+"\|$+ skip=+\\"+ contains=zigEscape,zigFormat display extend syn region zigString start="^\s*\\\\" end="$" display +" MISCELLANEOUS {{{2 syntax match zigOperator display "\V\[-+/*=^&?|!><%~]" syntax match zigArrowCharacter display "\V->" @@ -149,6 +157,7 @@ syntax region zigCommentLineDoc start="//[/!]/\@!" end="$" contains=zigTodo,@Spe syntax keyword zigTodo contained TODO +" DEFAULT HIGHLIGHTING {{{1 hi def link zigBoolean Boolean hi def link zigBuiltin Function hi def link zigCharacter Character @@ -172,7 +181,5 @@ highlight default link zigCommentLineDoc Comment highlight default link zigTodo Todo highlight default link zigArrowCharacter zigOperator -let b:current_syntax = "zig" - let &cpo = s:cpo_save unlet! s:cpo_save From 0d0be32f90756e29336c9c3728e396e49e5a6320 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:21:30 -0700 Subject: [PATCH 7/9] syntax: organize miscellaneous syntax highlighting --- syntax/zig.vim | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/syntax/zig.vim b/syntax/zig.vim index 05f74b4..ec59bf4 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -147,20 +147,21 @@ syn region zigString start=+"+ end=+"\|$+ skip=+\\"+ contains=zigEscape,zigForma syn region zigString start="^\s*\\\\" end="$" display " MISCELLANEOUS {{{2 -syntax match zigOperator display "\V\[-+/*=^&?|!><%~]" -syntax match zigArrowCharacter display "\V->" +syn keyword zigTodo FIXME TODO XXX contained -syntax region zigBlock start="{" end="}" transparent fold +" Blocks. +syn region zigBlock start="{" end="}" fold transparent -syntax region zigCommentLine start="//" end="$" contains=zigTodo,@Spell -syntax region zigCommentLineDoc start="//[/!]/\@!" end="$" contains=zigTodo,@Spell - -syntax keyword zigTodo contained TODO +" Comments. +syn region zigComment start="//" end="$" contains=zigTodo,@Spell display +syn region zigCommentDoc start="^\s*\zs//\(//\@!\|!\)" end="$" contains=zigTodo,@Spell 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 @@ -174,12 +175,8 @@ hi def link zigRepeat Repeat 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 -highlight default link zigCommentLine Comment -highlight default link zigCommentLineDoc Comment -highlight default link zigTodo Todo -highlight default link zigArrowCharacter zigOperator - let &cpo = s:cpo_save unlet! s:cpo_save From 4c892f94df2099aa8d5b748f2d611fe311eb44e9 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:22:48 -0700 Subject: [PATCH 8/9] syntax: add syntax highlighting for .? and .* --- syntax/zig.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/syntax/zig.vim b/syntax/zig.vim index ec59bf4..6180166 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -156,6 +156,9 @@ syn region zigBlock start="{" end="}" fold transparent syn region zigComment start="//" end="$" contains=zigTodo,@Spell display syn region zigCommentDoc start="^\s*\zs//\(//\@!\|!\)" end="$" contains=zigTodo,@Spell display +" Special operators. +syn match zigSpecial "\.\zs[*?]" display + " DEFAULT HIGHLIGHTING {{{1 hi def link zigBoolean Boolean hi def link zigBuiltin Function @@ -172,6 +175,7 @@ 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 From 269048b81bd0b9b560812a0bb464ff57d092f634 Mon Sep 17 00:00:00 2001 From: Amelia Clarke Date: Tue, 16 Aug 2022 14:23:55 -0700 Subject: [PATCH 9/9] syntax: correctly highlight @"" identifiers --- syntax/zig.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/syntax/zig.vim b/syntax/zig.vim index 6180166..bfe8309 100644 --- a/syntax/zig.vim +++ b/syntax/zig.vim @@ -156,6 +156,9 @@ syn region zigBlock start="{" end="}" fold transparent 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 @@ -171,6 +174,7 @@ 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