sml.kak (3311B)
1 # https://smlfamily.github.io 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*\.(sml|fun|sig) %{ 8 set-option buffer filetype sml 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=sml %{ 15 require-module sml 16 set-option buffer extra_word_chars '_' "'" 17 set-option window static_words %opt{sml_static_words} 18 } 19 20 hook -group sml-highlight global WinSetOption filetype=sml %{ 21 add-highlighter window/sml ref sml 22 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sml } 23 } 24 25 provide-module sml %[ 26 27 # Highlighters 28 # ‾‾‾‾‾‾‾‾‾‾‾‾ 29 30 add-highlighter shared/sml regions 31 add-highlighter shared/sml/code default-region group 32 add-highlighter shared/sml/string region '#?"' '(?<!\\)(\\\\)*"' fill string 33 add-highlighter shared/sml/comment region -recurse '\(\*' '\(\*' '\*\)' fill comment 34 35 evaluate-commands %sh{ 36 keywords='abstype and andalso as case datatype do else end exception fn fun 37 handle if in infix infixr let local nonfix of op open orelse raise 38 rec then type val with withtype while eqtype functor include 39 sharing sig signature struct structure' 40 types='unit exn ref' 41 ops='before ignore o 42 div mod quot rem abs 43 not chr ord ceil floor round trunc 44 andb orb xorb notb' 45 46 join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } 47 48 printf %s\\n "declare-option str-list sml_static_words $(join "${keywords} ${types} ${ops}" ' ')" 49 50 printf %s " 51 add-highlighter shared/sml/code/ regex \b($(join "${keywords}" '|'))\b 0:keyword 52 add-highlighter shared/sml/code/ regex \b($(join "${types}" '|'))\b 0:builtin 53 add-highlighter shared/sml/code/ regex \b($(join "${ops}" '|'))\b 0:operator 54 " 55 } 56 57 # Symbolic identifiers 58 add-highlighter shared/sml/code/ regex "[!*/+\-~\^@=<>%%&$?`\\#:|]+" 0:operator 59 60 # Record projection functions 61 add-highlighter shared/sml/code/ regex "(?<![!*/+\-~\^@=<>%%&$?`\\#:|])#([\w']+)?(?![!*/+\-~\^@=<>%%&$?`\\#:|])" 0:function 62 63 # Symbolic keywords 64 add-highlighter shared/sml/code/ regex "(?<![!*/+\-~\^@=<>%%&$?`\\#:|])(=>|=|\*|->|:>|:|;|\.\.\.|\b_\b|\|)(?![!*/+\-~\^@=<>%%&$?`\\#:|])" 0:keyword 65 66 # Type variables 67 add-highlighter shared/sml/code/ regex "(?<![\w'])'[\w']+(?![\w'])" 0:variable 68 69 # Structure identifiers and value constructors 70 add-highlighter shared/sml/code/ regex "(?<![\w'])([A-Z][\w']*\.?)" 0:type 71 72 # Signature identifiers and all-caps value constructors 73 add-highlighter shared/sml/code/ regex "(?<![\w'])[A-Z]{2}[A-Z0-9_']+(?![\w'])" 0:attribute 74 75 # Constants 76 add-highlighter shared/sml/code/ regex "(?<![\w'])(true|false|nil)\b" 0:value 77 78 # Numeric literals 79 add-highlighter shared/sml/code/ regex "(?<![\w'])0w[0-9]+\b" 0:value 80 add-highlighter shared/sml/code/ regex "(?<![\w'])(0wx|0xw)[0-9a-fA-F]+\b" 0:value 81 add-highlighter shared/sml/code/ regex "(?<![\w'])(0wb|0bw)[01]+\b" 0:value 82 add-highlighter shared/sml/code/ regex "(~|(?<![\w']))0x[0-9a-fA-F]+\b" 0:value 83 add-highlighter shared/sml/code/ regex "(~|(?<![\w']))0b[01]+\b" 0:value 84 add-highlighter shared/sml/code/ regex "(?<!#)(~|(?<![\w']))[0-9]+(\.[0-9]+)?([eE]~?[0-9]+)?\b" 0:value 85 86 ]