Skip to content

Instantly share code, notes, and snippets.

@divarvel
Created April 6, 2023 07:55
Show Gist options
  • Save divarvel/11d934e90e642fc184bbfa1332173e61 to your computer and use it in GitHub Desktop.
Save divarvel/11d934e90e642fc184bbfa1332173e61 to your computer and use it in GitHub Desktop.
Kakoune support for biscuit datalog
# http://https://datalog-biscuit-lang.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.biscuit-datalog %{
set-option buffer filetype biscuitdl
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/biscuitdl regions
add-highlighter shared/biscuitdl/code default-region group
add-highlighter shared/biscuitdl/string region '"' '(?<!\\)"' fill string
add-highlighter shared/biscuitdl/line_comment region '//' '$' fill comment
add-highlighter shared/biscuitdl/block_comment region '/\*' '\*/' fill comment
#add-highlighter shared/dhall/code/op regex <- 0:operator
add-highlighter shared/biscuitdl/code/symbol regex '#[A-Za-z0-9]+' 0:type
add-highlighter shared/biscuitdl/code/variable regex \$[A-Za-z0-9]+ 0:variable
add-highlighter shared/biscuitdl/code/date regex (?<!')\b\d{1,4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})(.\d+)?(Z|[\+\-]\d{2}:\d{2}) 0:value
add-highlighter shared/biscuitdl/code/number regex (?<!')\b\d+([.]\d+)? 0:value
add-highlighter shared/biscuitdl/code/boolean regex (?<!')\b(true|false) 0:value
add-highlighter shared/biscuitdl/code/bytes regex (?<!')\bhex:[A-Fa-f0-9]+ 0:string
add-highlighter shared/biscuitdl/code/head regex (?<!')\b\w+(?=\() 0:function
add-highlighter shared/biscuitdl/code/kw regex (?<!')\b(check|allow|deny|if) 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden biscuitdl-filter-around-selections %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
}
#
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group biscuitdl-highlight global WinSetOption filetype=biscuitdl %{ add-highlighter window/biscuitdl ref biscuitdl }
hook global WinSetOption filetype=biscuitdl %{
set-option window extra_word_chars "'"
hook window ModeChange insert:.* -group biscuitdl-hooks biscuitdl-filter-around-selections
}
hook -group biscuitdl-highlight global WinSetOption filetype=(?!biscuitdl).* %{ remove-highlighter window/biscuitdl }
hook global WinSetOption filetype=(?!biscuitdl).* %{
remove-hooks window biscuitdl-hooks
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment