From 07a8ae7a4f3427f839a4fbff0907b96de19a6f19 Mon Sep 17 00:00:00 2001 From: movva Date: Tue, 14 Oct 2025 16:52:00 +0200 Subject: [PATCH 1/2] Adds multiple highlighters, static_words & updates the keywords and builtins --- kakoune/c3.kak | 56 ++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/kakoune/c3.kak b/kakoune/c3.kak index c089729..cfc492b 100644 --- a/kakoune/c3.kak +++ b/kakoune/c3.kak @@ -1,12 +1,13 @@ hook global BufCreate .*[.]c3[it]? %{ - set-option buffer filetype c3 + set-option buffer filetype c3 } hook -group c3-highlight global WinSetOption filetype=c3 %{ - require-module c3 + require-module c3 + set-option window static_words %opt{c3_static_words} - add-highlighter window/c3 ref c3 - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/c3 } + add-highlighter window/c3 ref c3 + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/c3 } } @@ -21,37 +22,38 @@ addhl shared/c3/comment-doc region <\*(?!>) \*> fill comment addhl shared/c3/double-string region '"' (??\])' 1:value addhl shared/c3/code/module-decl regex '(module|import)\s*[a-z0-9_]+(?:::[a-z0-9_]+)*(?:(?:,\s*[a-z0-9_]+(?:::[a-z0-9_]+)*)+|\s*(\{(?:\s*_*[A-Z][A-z0-9_]*,?\s*)+\}))?(?=;)' 0:module 1:Default 2:Default addhl shared/c3/code/num regex '\b[+-]?(?:0(?:[xX][0-9a-fA-F](?:_*[0-9a-fA-F])*|[oO][0-7](?:_*[0-7])*|[bB][10](?:_*[10])*)|[0-9](?:_*[0-9])*(?:_*[eE][+-]?[0-9]+)?)(?:[iIuU](?:8|16|32|64|128)?|[fF](?:32|64)?|[uU][lL])?\b' 0:value -addhl shared/c3/code/ident regex '\$?\b_*[A-Z]\w*\b' 0:value -addhl shared/c3/code/user-attr regex '@[A-Z]\w*?[a-z]\w*\b' 0:attribute +addhl shared/c3/code/const regex '\$?\b_*[A-Z][A-Z_0-9]*\b' 0:value +addhl shared/c3/code/type regex '\$?\b_*[A-Z][A-Z_0-9]*[a-z][A-Z_0-9a-z]*\b' 0:value +addhl shared/c3/code/user-attr regex '@\b[A-Z][A-Z_0-9]*[a-z][A-Z_0-9a-z]*\b' 0:attribute addhl shared/c3/code/func regex '(?:[@#$])?\b_*[a-z][a-zA-Z0-9_]*\s*(?=\()' 0:function addhl shared/c3/code/module regex '([a-z0-9_]+)(?=::)' 1:module -# code/module-decl highlights '::' as modules, but they should not be highlighted addhl shared/c3/code/namespace regex '::' 0:Default -addhl shared/c3/code/shebang regex '\A#! ?/.*?\n' 0:comment evaluate-commands %sh{ - # generated using "c3c --list-{} | string join ' '" in fish - keywords='alias assert asm attrdef bitstruct break case catch const continue default defer do else enum extern false faultdef for foreach foreach_r fn tlocal if inline import macro module nextcase null interface return static struct switch true try typedef union var while' - attributes='@align @benchmark @bigendian @builtin @callconv @compact @const @deprecated @dynamic @export @extern @finalizer @format @if @inline @init @link @littleendian @local @maydiscard @naked @noalias @nodiscard @noinit @noinline @nopadding @norecurse @noreturn @nosanitize @nostrip @obfuscate @operator @operator_r @operator_s @optional @overlap @packed @private @public @pure @reflect @safemacro @section @tag @test @unused @used @wasm @weak @winmain' - builtins='$$abs $$any_make $$atomic_load $$atomic_store $$atomic_fetch_exchange $$atomic_fetch_add $$atomic_fetch_sub $$atomic_fetch_and $$atomic_fetch_nand $$atomic_fetch_or $$atomic_fetch_xor $$atomic_fetch_max $$atomic_fetch_min $$atomic_fetch_inc_wrap $$atomic_fetch_dec_wrap $$bitreverse $$breakpoint $$bswap $$ceil $$compare_exchange $$copysign $$cos $$clz $$ctz $$add $$div $$mod $$mul $$neg $$sub $$exp $$exp2 $$expect $$expect_with_probability $$floor $$fma $$fmuladd $$frameaddress $$fshl $$fshr $$gather $$get_rounding_mode $$log $$log10 $$log2 $$masked_load $$masked_store $$max $$memcpy $$memcpy_inline $$memmove $$memset $$memset_inline $$min $$nearbyint $$overflow_add $$overflow_mul $$overflow_sub $$popcount $$pow $$pow_int $$prefetch $$reduce_add $$reduce_and $$reduce_fadd $$reduce_fmul $$reduce_max $$reduce_min $$reduce_mul $$reduce_or $$reduce_xor $$reverse $$returnaddress $$rint $$round $$roundeven $$sat_add $$sat_shl $$sat_sub $$scatter $$select $$set_rounding_mode $$str_hash $$str_upper $$str_lower $$str_find $$swizzle $$swizzle2 $$sin $$sqrt $$syscall $$sysclock $$trap $$trunc $$unaligned_load $$unaligned_store $$unreachable $$veccomplt $$veccomple $$veccompgt $$veccompge $$veccompeq $$veccompne $$volatile_load $$volatile_store $$wasm_memory_size $$wasm_memory_grow $$wstr16 $$wstr32 $$DATE $$FILE $$FILEPATH $$FUNC $$FUNCTION $$LINE $$LINE_RAW $$MODULE $$BENCHMARK_NAMES $$BENCHMARK_FNS $$TEST_NAMES $$TEST_FNS $$TIME' - # Manually extracted from c3c --list-keywords - types='void bool char double float float16 bfloat int128 ichar int iptr isz long short uint128 uint ulong uptr ushort usz float128 any fault typeid' - # Needs to be separate from keywords due to the '$' prefix causing issues with '\b' resulting in things like '$endfor' not being highlighted at all - comptime_keywords='alignof assert assignable case default defined echo else embed endfor endforeach endif endswitch eval evaltype error exec extnameof feature for foreach if include is_const nameof offsetof qnameof sizeof stringify switch typefrom typeof vacount vatype vaconst vaarg vaexpr vasplat' - - # Both joins with a separator and escapes '$' characters - join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*" | sed -e 's/\$/\\\$/g'; } - - printf %s " - addhl shared/c3/code/keywords regex '(? Date: Wed, 15 Oct 2025 13:08:10 +0200 Subject: [PATCH 2/2] Fix comptime keywords --- kakoune/c3.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kakoune/c3.kak b/kakoune/c3.kak index cfc492b..825653e 100644 --- a/kakoune/c3.kak +++ b/kakoune/c3.kak @@ -40,7 +40,7 @@ evaluate-commands %sh{ attributes='align allow_deprecated benchmark bigendian builtin callconv compact const deprecated dynamic export extern finalizer format if inline init jump link littleendian local maydiscard naked noalias nodiscard noinit noinline nopadding norecurse noreturn nosanitize nostrip obfuscate operator operator_r operator_s optional overlap packed private public pure reflect safeinfer safemacro section structlike tag test unused used wasm weak winmain' builtins='abs add any_make atomic_fetch_add atomic_fetch_and atomic_fetch_dec_wrap atomic_fetch_exchange atomic_fetch_inc_wrap atomic_fetch_max atomic_fetch_min atomic_fetch_nand atomic_fetch_or atomic_fetch_sub atomic_fetch_xor atomic_load atomic_store bitreverse breakpoint bswap ceil clz compare_exchange copysign cos ctz div exp exp2 expect expect_with_probability fence floor fma fmuladd frameaddress fshl fshr gather get_rounding_mode log log10 log2 masked_load masked_store matrix_mul matrix_transpose max memcpy memcpy_inline memmove memset memset_inline min mod mul nearbyint neg overflow_add overflow_mul overflow_sub popcount pow pow_int prefetch reduce_add reduce_and reduce_fadd reduce_fmul reduce_max reduce_min reduce_mul reduce_or reduce_xor returnaddress reverse rint rnd round roundeven sat_add sat_mul sat_shl sat_sub scatter select set_rounding_mode sin sprintf sqrt str_find str_hash str_lower str_pascalcase str_replace str_snakecase str_upper sub swizzle swizzle2 syscall sysclock trap trunc unaligned_load unaligned_store unreachable veccompeq veccompge veccompgt veccomple veccomplt veccompne volatile_load volatile_store wasm_memory_grow wasm_memory_size wstr16 wstr32 BENCHMARK_FNS BENCHMARK_NAMES DATE FILE FILEPATH FUNC FUNCTION LINE LINE_RAW MODULE TEST_FNS TEST_NAMES TIME ADDRESS_SANITIZER ARCH_TYPE AUTHOR_EMAILS AUTHORS BACKTRACE BENCHMARKING BUILD_DATE BUILD_HASH COMPILER_LIBC_AVAILABLE COMPILER_OPT_LEVEL COMPILER_SAFE_MODE DEBUG_SYMBOLS LANGUAGE_DEV_VERSION LLVM_VERSION MAX_VECTOR_SIZE MEMORY_ENVIRONMENT MEMORY_SANITIZER OS_TYPE PANIC_MSG PLATFORM_BIG_ENDIAN PLATFORM_F128_SUPPORTED PLATFORM_F16_SUPPORTED PLATFORM_I128_SUPPORTED PROJECT_VERSION REGISTER_SIZE TESTING THREAD_SANITIZER' types='void bool char double float float16 bfloat int128 ichar int iptr isz long short uint128 uint ulong uptr ushort usz float128 any fault typeid' - comptime_keywords='$alignof $assert $assignable $case $default $defined $echo $else $embed $endfor $endforeach $endif $endswitch $eval $evaltype $error $exec $extnameof $feature $for $foreach $if $include $is_const $kindof $nameof $offsetof $qnameof $sizeof $stringify $switch $typefrom $typeof $vacount $vatype $vaconst $vaarg $vaexpr $vasplat' + comptime_keywords='alignof assert assignable case default defined echo else embed endfor endforeach endif endswitch eval evaltype error exec extnameof feature for foreach if include is_const kindof nameof offsetof qnameof sizeof stringify switch typefrom typeof vacount vatype vaconst vaarg vaexpr vasplat' # Both joins with a separator and escapes '$' characters join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*" | sed -e 's/\$/\\\$/g'; }