diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 3b2a115f2a5ce..ad201a2db8297 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -82,6 +82,7 @@ | julia | ✓ | ✓ | ✓ | `julia` | | just | ✓ | ✓ | ✓ | | | kdl | ✓ | ✓ | ✓ | | +| koka | ✓ | | ✓ | | | kotlin | ✓ | | | `kotlin-language-server` | | latex | ✓ | ✓ | | `texlab` | | lean | ✓ | | | `lean` | diff --git a/languages.toml b/languages.toml index 9b7d93ed2f206..51bc2cc1b27fd 100644 --- a/languages.toml +++ b/languages.toml @@ -3055,3 +3055,16 @@ language-servers = [ "templ" ] [[grammar]] name = "templ" source = { git = "https://github.com/vrischmann/tree-sitter-templ", rev = "ea56ac0655243490a4929a988f4eaa91dfccc995" } + +[[language]] +name = "koka" +scope = "source.koka" +injection-regex = "koka" +file-types = ["kk"] +roots = [] +comment-token = "//" +indent = { tab-width = 8, unit = " " } + +[[grammar]] +name = "koka" +source = { git = "https://github.com/mtoohey31/tree-sitter-koka", rev = "08389b35b5e4f224ddb953158cbdcec3cf2b05da" } diff --git a/runtime/queries/koka/highlights.scm b/runtime/queries/koka/highlights.scm new file mode 100644 index 0000000000000..6bbdb008df071 --- /dev/null +++ b/runtime/queries/koka/highlights.scm @@ -0,0 +1,217 @@ +; Function calls + +(appexpr + function: (appexpr + (atom + (qidentifier + [ + (qvarid) + (qidop) + (identifier + [(varid) (idop)] @function) + ] @function)))) + +(appexpr + function: (appexpr + field: (atom + (qidentifier + [ + (qvarid) + (qidop) + (identifier + [(varid) (idop)] @function.method) + ] @function.method)))) + +[ + "initially" + "finally" +] @function.special + +; Function definitions + +(puredecl + (funid + (identifier + [(varid) (idop)] @function))) + +(fundecl + (funid + (identifier + [(varid) (idop)] @function))) + +(operation + (identifier + [(varid) (idop)] @function)) + +; Identifiers + +(puredecl + (binder + (identifier + [(varid) (idop)] @constant))) + +(pparameter + (pattern + (identifier + (varid) @variable.parameter))) + +(paramid + (identifier + (varid) @variable.parameter)) + +(appexpr + field: (atom + (qidentifier + [ + (qvarid) + (qidop) + (identifier + [(varid) (idop)] @variable.other.member) + ] @variable.other.member))) + +(typeid + (varid) @type) + +(tbinder + (varid) @type) + +(typecon + (varid) @type) + +(qvarid + (qid) @namespace) + +(modulepath (varid) @namespace) + +(qconid) @namespace + +(qidop) @namespace + +(varid) @variable + +(conid) @constructor + +; Operators + +[ + "!" + "~" + "=" + ":=" + (idop) + (op) + (qidop) +] @operator + +; Keywords + +[ + "as" + "behind" + (externtarget) + "forall" + "handle" + "handler" + "in" + "infix" + "infixl" + "infixr" + "mask" + "pub" + "some" +] @keyword + +[ + "con" + "ctl" + "fn" + "fun" +] @keyword.function + +"with" @keyword.control + +[ + "elif" + "else" + "if" + "match" + "then" +] @keyword.control.conditional + +[ + "import" + "module" +] @keyword.control.import + +[ + "alias" + "effect" + "struct" + "type" + "val" + "var" +] @keyword.storage.type + +[ + "abstract" + "co" + "extend" + "extern" + "final" + "inline" + "linear" + "named" + "noinline" + "open" + "override" + "raw" + "rec" + "reference" + "value" +] @keyword.storage.modifier + +"return" @keyword.control.return + +; Delimiters + +(matchrule "|" @punctuation.delimiter) + +[ + "," + "->" + "." + ":" + "::" + "<-" + ";" +] @punctuation.delimiter + +[ + "<" + ">" + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +; Literals + +[ + (string) + (char) +] @string + +(escape) @constant.character.escape + +(float) @constant.numeric.float +(int) @constant.numeric.integer + +; Comment + +[ + (linecomment) + (blockcomment) +] @comment diff --git a/runtime/queries/koka/indents.scm b/runtime/queries/koka/indents.scm new file mode 100644 index 0000000000000..a4f4fd1527a69 --- /dev/null +++ b/runtime/queries/koka/indents.scm @@ -0,0 +1,35 @@ +[ + (appexpr ["[" "("]) ; Applications. + (atom ["[" "("]) ; Lists and tuples. + (program (moduledecl "{")) ; Braced module declarations. +] @indent + +[ + (funbody) + (typedecl + [(typeid) (opdecls)]) ; Avoid matching single-operation effects. + (externdecl) + (block) + (matchexpr) + (matchrule) + + ; For ifexprs, branches (once they exist) will contain blocks if they're + ; indented so we just need to make sure the initial indent happens when we're + ; creating them. + "then" + "else" +] @indent @extend + +(matchrule "->" @indent @extend) + +; Handling for error recovery. +(ERROR "match") @indent @extend +(ERROR "->" @indent.always @extend) + +; Don't outdent on function parameter declarations. +(atom ")" @outdent @extend.prevent-once) + +[ + "]" + "}" +] @outdent @extend.prevent-once diff --git a/runtime/queries/koka/injections.scm b/runtime/queries/koka/injections.scm new file mode 100644 index 0000000000000..1d5b8e331fd0e --- /dev/null +++ b/runtime/queries/koka/injections.scm @@ -0,0 +1,2 @@ +([(linecomment) (blockcomment)] @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/koka/locals.scm b/runtime/queries/koka/locals.scm new file mode 100644 index 0000000000000..20d3c8944d4c7 --- /dev/null +++ b/runtime/queries/koka/locals.scm @@ -0,0 +1,18 @@ +(block) @local.scope + +(pattern + (identifier + (varid) @local.definition)) + +(decl + (apattern + (pattern + (identifier + (varid) @local.definition)))) + +(decl + (binder + (identifier + (varid) @local.definition))) + +(varid) @local.reference