diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2025-01-28 09:14:32 +0000 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2025-01-28 09:14:32 +0000 |
commit | 904cec3c4a329cf89fc3219d359239910d61f3f6 (patch) | |
tree | 8d113899921dfbaca0e77c49ab5fc827362d1091 /autoload/filetype/sml.kak |
Diffstat (limited to 'autoload/filetype/sml.kak')
-rw-r--r-- | autoload/filetype/sml.kak | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/autoload/filetype/sml.kak b/autoload/filetype/sml.kak new file mode 100644 index 0000000..961d58d --- /dev/null +++ b/autoload/filetype/sml.kak @@ -0,0 +1,86 @@ +# https://smlfamily.github.io +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.(sml|fun|sig) %{ + set-option buffer filetype sml +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=sml %{ + require-module sml + set-option buffer extra_word_chars '_' "'" + set-option window static_words %opt{sml_static_words} +} + +hook -group sml-highlight global WinSetOption filetype=sml %{ + add-highlighter window/sml ref sml + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sml } +} + +provide-module sml %[ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/sml regions +add-highlighter shared/sml/code default-region group +add-highlighter shared/sml/string region '#?"' '(?<!\\)(\\\\)*"' fill string +add-highlighter shared/sml/comment region -recurse '\(\*' '\(\*' '\*\)' fill comment + +evaluate-commands %sh{ + keywords='abstype and andalso as case datatype do else end exception fn fun + handle if in infix infixr let local nonfix of op open orelse raise + rec then type val with withtype while eqtype functor include + sharing sig signature struct structure' + types='unit exn ref' + ops='before ignore o + div mod quot rem abs + not chr ord ceil floor round trunc + andb orb xorb notb' + + join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } + + printf %s\\n "declare-option str-list sml_static_words $(join "${keywords} ${types} ${ops}" ' ')" + + printf %s " + add-highlighter shared/sml/code/ regex \b($(join "${keywords}" '|'))\b 0:keyword + add-highlighter shared/sml/code/ regex \b($(join "${types}" '|'))\b 0:builtin + add-highlighter shared/sml/code/ regex \b($(join "${ops}" '|'))\b 0:operator + " +} + +# Symbolic identifiers +add-highlighter shared/sml/code/ regex "[!*/+\-~\^@=<>%%&$?`\\#:|]+" 0:operator + +# Record projection functions +add-highlighter shared/sml/code/ regex "(?<![!*/+\-~\^@=<>%%&$?`\\#:|])#([\w']+)?(?![!*/+\-~\^@=<>%%&$?`\\#:|])" 0:function + +# Symbolic keywords +add-highlighter shared/sml/code/ regex "(?<![!*/+\-~\^@=<>%%&$?`\\#:|])(=>|=|\*|->|:>|:|;|\.\.\.|\b_\b|\|)(?![!*/+\-~\^@=<>%%&$?`\\#:|])" 0:keyword + +# Type variables +add-highlighter shared/sml/code/ regex "(?<![\w'])'[\w']+(?![\w'])" 0:variable + +# Structure identifiers and value constructors +add-highlighter shared/sml/code/ regex "(?<![\w'])([A-Z][\w']*\.?)" 0:type + +# Signature identifiers and all-caps value constructors +add-highlighter shared/sml/code/ regex "(?<![\w'])[A-Z]{2}[A-Z0-9_']+(?![\w'])" 0:attribute + +# Constants +add-highlighter shared/sml/code/ regex "(?<![\w'])(true|false|nil)\b" 0:value + +# Numeric literals +add-highlighter shared/sml/code/ regex "(?<![\w'])0w[0-9]+\b" 0:value +add-highlighter shared/sml/code/ regex "(?<![\w'])(0wx|0xw)[0-9a-fA-F]+\b" 0:value +add-highlighter shared/sml/code/ regex "(?<![\w'])(0wb|0bw)[01]+\b" 0:value +add-highlighter shared/sml/code/ regex "(~|(?<![\w']))0x[0-9a-fA-F]+\b" 0:value +add-highlighter shared/sml/code/ regex "(~|(?<![\w']))0b[01]+\b" 0:value +add-highlighter shared/sml/code/ regex "(?<!#)(~|(?<![\w']))[0-9]+(\.[0-9]+)?([eE]~?[0-9]+)?\b" 0:value + +] |