From 80a4e666221a10ba41bd1d00bf2e9c77794b3064 Mon Sep 17 00:00:00 2001 From: Alex Chapman Date: Wed, 30 Oct 2019 10:22:12 +1100 Subject: [PATCH 2/4] Add syntax support for the Dhall configuration language. --- rc/filetype/dhall.kak | 90 +++++++++++++++++++++++++++++++++++++++++++ rc/tools/comment.kak | 2 +- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 rc/filetype/dhall.kak diff --git a/rc/filetype/dhall.kak b/rc/filetype/dhall.kak new file mode 100644 index 00000000..0dcd8d28 --- /dev/null +++ b/rc/filetype/dhall.kak @@ -0,0 +1,90 @@ +# https://dhall-lang.org +# + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](dhall) %{ + set-option buffer filetype dhall +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=dhall %{ + require-module dhall + + hook window ModeChange insert:.* -group dhall-trim-indent dhall-trim-indent + hook window InsertChar \n -group dhall-indent dhall-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window dhall-.+ } +} + +hook -group dhall-highlight global WinSetOption filetype=dhall %{ + add-highlighter window/dhall ref dhall + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dhall } +} + + +provide-module dhall %[ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/dhall regions +add-highlighter shared/dhall/code default-region group +add-highlighter shared/dhall/string region '"' (?|\?|λ|\\|\^|⫽|//|\[|\]|\{|\}) 0:operator + +# Matches built-in functions +add-highlighter shared/dhall/code/ regex \b(Natural-fold|Natural-build|Natural-isZero|Natural-even|Natural-odd|Natural-toInteger|Natural-show|Integer-toDouble|Integer-show|Natural-subtract|Double-show|List-build|List-fold|List-length|List-head|List-last|List-indexed|List-reverse|Optional-fold|Optional-build|Text-show)\b 0:keyword + +# Matches http[s] imports +add-highlighter shared/dhall/code/ regex \b(http[s]://\S+)\b(\s+sha256:[a-f0-9]{64}\b)? 0:meta + +# Matches local imports +add-highlighter shared/dhall/code/ regex (~|\.|\.\.|/)\S+ 0:meta + +# Matches number (natural, integer, double) literals +add-highlighter shared/dhall/code/ regex \b(\+|-)?\d+(\.\d+)?(e(\+|-)?\d+)?\b 0:value + +# Matches union syntax +add-highlighter shared/dhall/union region -recurse < < > group +add-highlighter shared/dhall/union/sep regex (<|\|)\s*((?:_|[A-Z])(?:[a-zA-Z0-9-/_]*))\s*(?:(:)([^|>]*))? 1:operator 2:attribute 3:operator 4:type +add-highlighter shared/dhall/union/end regex > 0:operator + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden dhall-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden dhall-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : dhall-trim-indent } + # indent after lines ending with let, : or = + try %{ execute-keys -draft \; k x (let|:|=)$ j } + } +} + +] diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 586b516b..39d62501 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -20,7 +20,7 @@ hook global BufSetOption filetype=(c|cpp|dart|go|java|javascript|objc|php|rust|s set-option buffer comment_block_end '*/' } -hook global BufSetOption filetype=(cabal|haskell|moon|idris|elm) %{ +hook global BufSetOption filetype=(cabal|haskell|moon|idris|elm|dhall) %{ set-option buffer comment_line '--' set-option buffer comment_block_begin '{-' set-option buffer comment_block_end '-}' From 9381277274c823d6d8eeede6d522ed8ee46cda46 Mon Sep 17 00:00:00 2001 From: Alex Chapman Date: Wed, 30 Oct 2019 10:22:23 +1100 Subject: [PATCH 3/4] Add Dhall multi-line string literals --- rc/filetype/dhall.kak | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rc/filetype/dhall.kak b/rc/filetype/dhall.kak index 0dcd8d28..2876d383 100644 --- a/rc/filetype/dhall.kak +++ b/rc/filetype/dhall.kak @@ -37,6 +37,9 @@ add-highlighter shared/dhall/string region '"' (? Date: Wed, 30 Oct 2019 10:22:31 +1100 Subject: [PATCH 4/4] Add support for quoted labels, empty record values and their type --- rc/filetype/dhall.kak | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rc/filetype/dhall.kak b/rc/filetype/dhall.kak index 2876d383..631d9121 100644 --- a/rc/filetype/dhall.kak +++ b/rc/filetype/dhall.kak @@ -40,14 +40,17 @@ add-highlighter shared/dhall/line_comment region -- $ fill comment # Matches multi-line string literals add-highlighter shared/dhall/multiline_string region \Q''\E$ [^']''[^'] fill string +# Matches quoted labels +add-highlighter shared/dhall/quoted_label region ` ` fill normal + # Matches built-in types -add-highlighter shared/dhall/code/ regex \b(Location|Sort|Kind|Type|Text|Bool|Natural|Integer|Double|List|Optional)\b 0:type +add-highlighter shared/dhall/code/ regex \b(Location|Sort|Kind|Type|Text|Bool|Natural|Integer|Double|List|Optional|\{\})\b 0:type # Matches built-in keywords add-highlighter shared/dhall/code/ regex \b(if|then|else|let|in|using|missing|as|merge|toMap)\b 0:keyword # Matches bulit-in values -add-highlighter shared/dhall/code/ regex \b(True|False|Some|None|-?Infinity||NaN)\b 0:value +add-highlighter shared/dhall/code/ regex \b(True|False|Some|None|-?Infinity|\{=\}|NaN)\b 0:value # Matches built-in operators add-highlighter shared/dhall/code/ regex (,|:|\|\||&&|==|!=|=|\+|\*|\+\+|#|⩓|//\\\\|→|->|\?|λ|\\|\^|⫽|//|\[|\]|\{|\}) 0:operator