rc: add hare language module
This commit is contained in:
parent
ac6f928ad4
commit
3aaee810be
122
rc/filetype/hare.kak
Normal file
122
rc/filetype/hare.kak
Normal file
|
@ -0,0 +1,122 @@
|
|||
# detection
|
||||
hook global BufCreate .*[.]ha %{
|
||||
set-option buffer filetype hare
|
||||
}
|
||||
|
||||
# initialisation
|
||||
hook global WinSetOption filetype=hare %{
|
||||
require-module hare
|
||||
hook window ModeChange pop:insert:.* -group hare-trim-indent hare-trim-indent
|
||||
hook window InsertChar \n -group hare-indent hare-indent-on-new-line
|
||||
hook window InsertChar \n -group hare-insert hare-insert-on-new-line
|
||||
}
|
||||
|
||||
hook -group hare-highlight global WinSetOption filetype=hare %{
|
||||
add-highlighter window/hare ref hare
|
||||
hook -once -always window WinSetOption filetype=*. %{ remove-highlighter window/hare }
|
||||
}
|
||||
|
||||
# highlighters
|
||||
provide-module hare %{
|
||||
add-highlighter shared/hare regions
|
||||
add-highlighter shared/hare/code default-region group
|
||||
add-highlighter shared/hare/comment region // $ fill comment
|
||||
|
||||
add-highlighter shared/hare/rawstring region ` ` group
|
||||
add-highlighter shared/hare/rawstring/ fill string
|
||||
|
||||
add-highlighter shared/hare/string region '"' (?<!\\)(\\\\)*" group
|
||||
add-highlighter shared/hare/string/ fill string
|
||||
add-highlighter shared/hare/string/ regex '(\\0|\\a|\\b|\\f|\\n|\\r|\\t|\\v|\\\\|\\")' 0:meta
|
||||
add-highlighter shared/hare/string/ regex "\\'" 0:meta
|
||||
add-highlighter shared/hare/string/ regex "(\\x[0-9a-fA-F]{2})" 0:meta
|
||||
add-highlighter shared/hare/string/ regex "(\\u[0-9a-fA-F]{4})" 0:meta
|
||||
add-highlighter shared/hare/string/ regex "(\\U[0-9a-fA-F]{8})" 0:meta
|
||||
|
||||
add-highlighter shared/hare/rune region "'" (?<!\\)(\\\\)*' group
|
||||
add-highlighter shared/hare/rune/ fill string
|
||||
add-highlighter shared/hare/rune/ regex "(\\0|\\a|\\b|\\f|\\n|\\r|\\t|\\v|\\\\|\\')" 0:meta
|
||||
add-highlighter shared/hare/rune/ regex '\\"' 0:meta
|
||||
add-highlighter shared/hare/rune/ regex "(\\x[0-9a-fA-F]{2})" 0:meta
|
||||
add-highlighter shared/hare/rune/ regex "(\\u[0-9a-fA-F]{4})" 0:meta
|
||||
add-highlighter shared/hare/rune/ regex "(\\U[0-9a-fA-F]{8})" 0:meta
|
||||
|
||||
# imports
|
||||
add-highlighter shared/hare/code/ regex "\buse\b" 0:meta
|
||||
add-highlighter shared/hare/code/ regex "\buse\s.*?;" 0:meta
|
||||
|
||||
# attributes
|
||||
add-highlighter shared/hare/code/ regex "@(offset|init|fini|test|noreturn|symbol)\b" 0:attribute
|
||||
|
||||
# declarations
|
||||
add-highlighter shared/hare/code/ regex "\b(let|export|const)\b" 0:meta
|
||||
add-highlighter shared/hare/code/ regex "\b(fn|type|def)\b" 0:keyword
|
||||
|
||||
# builtins
|
||||
add-highlighter shared/hare/code/ regex "\b(len|offset|free|alloc|assert|append|abort|delete|insert|vastart|vaarg|vaend)\b" 0:builtin
|
||||
add-highlighter shared/hare/code/ regex "\b(as|is)\b" 0:builtin
|
||||
|
||||
# types
|
||||
add-highlighter shared/hare/code/ regex "\b(struct|union|enum)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(nullable|null|void)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(u8|u16|u32|u64|uint)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(i8|i16|i32|i64|int)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(size|uintptr|char)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(f32|f64)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(str|rune)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(bool)\b" 0:type
|
||||
add-highlighter shared/hare/code/ regex "\b(valist)\b" 0:type
|
||||
|
||||
# literals
|
||||
add-highlighter shared/hare/code/ regex "\b(true|false)\b" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b[0-9]+([eE][-+]?[0-9]+)?(z|(i|u)(8|16|32|64)?)?\b" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b[0-9]+([eE][-+]?[0-9]+)?((?=e)|(?=u)|(?=i))" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b0b[0-1]+(z|(i|u)(8|16|32|64)?)?\b" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b0b[0-1]+((?=u)|(?=i))" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b0o[0-7]+(z|(i|u)(8|16|32|64)?)?\b" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b0o[0-7]+((?=u)|(?=i))" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b0x[0-9a-fA-F]+(z|(i|u)(8|16|32|64)?)?\b" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b0x[0-9a-fA-F]+((?=u)|(?=i))" 0:value
|
||||
|
||||
# floats
|
||||
add-highlighter shared/hare/code/ regex "\b[0-9]+\.[0-9]+([eE][-+]?[0-9]+)?(f32|f64)?\b" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b[0-9]+\.[0-9]+([eE][-+]?[0-9]+)?((?=e)|(?=f))" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b[0-9]+([eE][-+]?[0-9]+)?(f32|f64)\b" 0:value
|
||||
add-highlighter shared/hare/code/ regex "\b[0-9]+([eE][-+]?[0-9]+)?(?=f)" 0:value
|
||||
|
||||
|
||||
# control flow
|
||||
add-highlighter shared/hare/code/ regex "\b(for|if|else|switch|match|return|break|continue|defer|yield|case|static)\b" 0:keyword
|
||||
|
||||
# commands
|
||||
define-command -hidden hare-indent-on-new-line %{ evaluate-commands -draft -itersel %{
|
||||
# preserve indentation on new lines
|
||||
try %{ execute-keys -draft <semicolon> K <a-&> }
|
||||
# remove trailing whitespace on the above line
|
||||
execute-keys -draft k :hare-trim-indent <ret>
|
||||
} }
|
||||
|
||||
define-command -hidden hare-insert-on-new-line %{ evaluate-commands -draft -itersel %{
|
||||
try %{ evaluate-commands -draft -save-regs '/"' %{
|
||||
# copy the comment prefix
|
||||
execute-keys -save-regs '' k <a-x> s ^\h*\K//\h* <ret> y
|
||||
try %{
|
||||
# paste the comment prefix
|
||||
execute-keys <a-x> j <a-x> s ^\h* <ret>P
|
||||
}
|
||||
} }
|
||||
try %{
|
||||
# remove trailing whitespace on the above line
|
||||
execute-keys -draft k :hare-trim-indent <ret>
|
||||
}
|
||||
} }
|
||||
|
||||
define-command -hidden hare-trim-indent %{ evaluate-commands -draft -itersel %{
|
||||
# remove trailing whitespace
|
||||
try %{ execute-keys -draft <a-x> s \h+$ <ret> d }
|
||||
} }
|
||||
|
||||
# TODO
|
||||
# const/null/void/size are ambiguous
|
||||
# indentation (copy c-family.kak)
|
||||
}
|
Loading…
Reference in New Issue
Block a user