From 289b57bb67dd96b7d1da495eaf4bd06b0321541d Mon Sep 17 00:00:00 2001 From: SolitudeSF Date: Mon, 7 Jan 2019 22:01:39 +0200 Subject: [PATCH] rc: nim - properly highlight hex/oct/bin literals, refactor, fix more edgecases --- rc/extra/nim.kak | 71 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/rc/extra/nim.kak b/rc/extra/nim.kak index 48645cef..901ce68a 100644 --- a/rc/extra/nim.kak +++ b/rc/extra/nim.kak @@ -14,45 +14,70 @@ hook global BufCreate .*\.nim(s|ble)? %{ add-highlighter shared/nim regions add-highlighter shared/nim/code default-region group add-highlighter shared/nim/triple_string region '([A-Za-z](_?\w)*)?"""' '"""(?!")' fill string -add-highlighter shared/nim/raw_string region '[A-Za-z](_?\w)*"' '(?@$~&%|!?^.:\\*]+ 0:operator -add-highlighter shared/nim/code/ regex \b(0[xXocCbB])?[\d_]+('[iIuU](8|16|32|64)|'d|'f(32|64|128)?)?\b 0:value -add-highlighter shared/nim/code/ regex \b\d[\d_]*\.\d[\d_]*([eE]\d[\d_]*)?('d|'f(32|64|128))?\b 0:value -add-highlighter shared/nim/code/ regex %{'(\\([rcnlftvabe\\"']|\d+|x[0-9a-fA-F]{2})|[^'\n])'} 0:string - evaluate-commands %sh{ # Grammar - keywords="addr|and|as|asm|atomic|bind|block|break|case|cast|concept|const" - keywords="${keywords}|continue|converter|defer|discard|distinct|div|do|elif" - keywords="${keywords}|else|end|enum|except|export|finally|for|from|func" - keywords="${keywords}|generic|if|import|in|include|interface|is|isnot" - keywords="${keywords}|iterator|let|macro|method|mixin|mod|nil|not|notin" - keywords="${keywords}|of|or|out|proc|ptr|raise|ref|return|shl|shr" - keywords="${keywords}|static|template|try|type|using|var|when|while" - keywords="${keywords}|with|without|xor|yield" - types="int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float" - types="${types}|float32|float64|bool|char|object|seq|array|cstring|string" - types="${types}|tuple|varargs|typedesc|pointer|byte|set|typed|untyped" - types="${types}|void" - values="false|true" + opchars='[=+-/<>@$~&%|!?^.:\\*]' + opnocol='[=+-/<>@$~&%|!?^.\\*]' + suffix="('[iIuU](8|16|32|64)|'[fF](32|64)?|'[dDuU]|[fF])?" + floatsuffix="('[fF](32|64)?|'[dD]|[fF])?" + hexdigit='[0-9a-fA-F]' + octdigit='[0-7]' + bindigit='[01]' + hexlit="0[xX]${hexdigit}(_?${hexdigit})*" + declit="\d(_?\d)*" + octlit="0o${octdigit}(_?${octdigit})*" + binlit="0[bB]${bindigit}(_?${bindigit})*" + intlit="\b(${declit}|${hexlit}|${octlit}|${binlit})${suffix}\b" + exponent="([eE][+-]?${declit})" + floatlit="\b${declit}(\.${declit}${exponent}?|${exponent})${floatsuffix}\b" + + keywords="addr as asm bind block break case cast concept const continue + converter defer discard distinct do elif else end enum except export + finally for from func if import include interface iterator let macro + method mixin nil out proc ptr raise ref return static template try type + unsafeAddr using var when while yield with without atomic generic" + operators="or xor and is isnot in notin of div mod shl shr not" + types="int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float + float32 float64 bool char object seq array cstring string tuple varargs + typedesc pointer byte set typed untyped void auto" + values="false true" + + join() { sep=$2; set -- $1; IFS="$sep"; echo "$*"; } + + static_words="$(join "${keywords} ${types} ${operator} ${values}" ' ')" # Add the language's grammar to the static completion list - printf %s\\n "hook global WinSetOption filetype=nim %{ - set-option window static_words ${keywords} ${types} ${values} - }" | tr '|' ' ' + printf %s "hook global WinSetOption filetype=nim %{ + set-option window static_words ${static_words} + }" + + keywords="$(join "${keywords}" '|')" + operators="$(join "${operators}" '|')" + types="$(join "${types}" '|')" + values="$(join "${values}" '|')" # Highlight keywords printf %s " + add-highlighter shared/nim/code/ regex ${opchars}+ 0:operator + add-highlighter shared/nim/code/ regex (?