Add an example and the kak script

This commit is contained in:
Francesco Magliocca 2022-05-17 21:33:25 +02:00
parent 5073f33c9f
commit dfbe469fb3
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,46 @@
# Helpers
datatype 'a list {
Cons ('a, 'a list),
Empty,
}
datatype 'a maybe {
Just 'a,
Nothing,
}
# Lambda calculus term, nameless representation
datatype term {
Var int
Int int
Abs term
App (term, term)
}
# Result of the evaluation
datatype value {
Int int
Closure (env, term)
}
alias env = value list
typecheck add_binding : value -> env -> env
def add_binding v env = Cons v env
typecheck lookup : int -> env -> value maybe
def lookup _ <Empty> = Nothing
| lookup 0 <Cons x xs> = Just x
| lookup n <Cons x xs> = lookup (subtract n 1) xs
typecheck eval : env -> term -> value
def eval e <Var idx> = match lookup idx e {
case <Just v> -> v
case <Nothing> -> abort "Variable out of scope"
}
| eval e <Int x> = Int x
| eval e <Abs t> = Closure e t
| eval e <App t1 t2> =
let def new_env = add_binding (eval e t2) e
in eval new_env t1

49
extra/milly.kak Normal file
View File

@ -0,0 +1,49 @@
# Detection
hook global BufCreate .*\.(mil) %{
set-option buffer filetype milly
}
hook global WinSetOption filetype=milly %{
require-module milly
}
hook -group milly-highlighter global WinSetOption filetype=milly %{
add-highlighter window/milly ref milly
hook -once -always window WinSetOption filetype=.* %{
remove-highlighter window/milly
}
}
provide-module milly %§
# Highlighters & Completion
add-highlighter shared/milly regions
add-highlighter shared/milly/code default-region group
add-highlighter shared/milly/comment region (^|\h)\K# $ fill comment
add-highlighter shared/milly/double_string region -recurse %{(?<!")("")+(?!")} %{(^|\h)\K"} %{"(?!")} group
evaluate-commands %sh{
# Grammar
keywords="case let in match of def datatype alias typecheck"
types="int bool string list"
values="true false"
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
# Add the language's grammar to the static completion list
printf %s\\n "declare-option str-list kak_static_words $(join "${keywords} ${attributes} ${types} ${values}" ' ')'"
# Highlight keywords (which are always surrounded by whitespace)
printf '%s\n' "add-highlighter shared/milly/code/keywords regex (?:\s|\A)\K($(join "${keywords}" '|'))(?:(?=\s)|\z) 0:keyword
add-highlighter shared/milly/code/types regex (?:\s|\A)\K($(join "${types}" '|'))(?:(?=\s)|\z) 0:type
add-highlighter shared/milly/code/values regex (?:\s|\A)\K($(join "${values}" '|'))(?:(?=\s)|\z) 0:value"
}
add-highlighter shared/milly/code/numbers regex \b\d+\b 0:value
add-highlighter shared/milly/double_string/fill fill string
add-highlighter shared/milly/double_string/escape regex '""' 0:default+b
§