From a26cb8627f7f89e7cb6094becb4eff89262500d5 Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Sun, 5 Nov 2023 15:37:27 -0500 Subject: [PATCH] languages: add koka --- book/src/generated/lang-support.md | 1 + languages.toml | 13 ++ runtime/queries/koka/highlights.scm | 272 ++++++++++++++++++++++++++++ runtime/queries/koka/indents.scm | 39 ++++ runtime/queries/koka/injections.scm | 2 + runtime/queries/koka/locals.scm | 30 +++ 6 files changed, 357 insertions(+) create mode 100644 runtime/queries/koka/highlights.scm create mode 100644 runtime/queries/koka/indents.scm create mode 100644 runtime/queries/koka/injections.scm create mode 100644 runtime/queries/koka/locals.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 0c5b35cc6f089..6332d5669ebf0 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -86,6 +86,7 @@ | julia | ✓ | ✓ | ✓ | `julia` | | just | ✓ | ✓ | ✓ | | | kdl | ✓ | ✓ | ✓ | | +| koka | ✓ | | ✓ | | | kotlin | ✓ | | | `kotlin-language-server` | | latex | ✓ | ✓ | | `texlab` | | lean | ✓ | | | `lean` | diff --git a/languages.toml b/languages.toml index b47fb4e2b8498..86bba166230bc 100644 --- a/languages.toml +++ b/languages.toml @@ -3006,3 +3006,16 @@ file-types = ["janet"] comment-token = "#" indent = { tab-width = 2, unit = " " } grammar = "clojure" + +[[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 = "2527e152d4b6a79fd50aebd8d0b4b4336c94a034" } diff --git a/runtime/queries/koka/highlights.scm b/runtime/queries/koka/highlights.scm new file mode 100644 index 0000000000000..fead98384243e --- /dev/null +++ b/runtime/queries/koka/highlights.scm @@ -0,0 +1,272 @@ +; Function calls + +(appexpr + function: (appexpr + (atom + (qidentifier + [ + (qvarid) @function + (qidop) @function + (identifier + [(varid) (idop)] @function) + ]))) + ["(" (block) (fnexpr)]) + +(ntlappexpr + function: (ntlappexpr + (atom + (qidentifier + [ + (qvarid) @function + (qidop) @function + (identifier + [(varid) (idop)] @function) + ]))) + ["(" (block) (fnexpr)]) + +(appexpr + field: (atom + (qidentifier + [ + (qvarid) @function + (qidop) @function + (identifier + [(varid) (idop)] @function) + ]))) + +(appexpr + (appexpr + field: (atom + (qidentifier + [ + (qvarid) @variable + (qidop) @variable + (identifier + [(varid) (idop)] @variable) + ]))) + "[") + +(ntlappexpr + field: (atom + (qidentifier + [ + (qvarid) @function + (qidop) @function + (identifier + [(varid) (idop)] @function) + ]))) + +(ntlappexpr + (ntlappexpr + field: (atom + (qidentifier + [ + (qvarid) @variable + (qidop) @variable + (identifier + [(varid) (idop)] @variable) + ]))) + "[") + +[ + "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))) + +; TODO: Highlight vars differently once helix has an appropriate highlight query +; for that purpose. + +(pparameter + (pattern + (identifier + (varid) @variable.parameter))) + +(paramid + (identifier + (varid) @variable.parameter)) + +(typedecl + "effect" + (varid) @type) + +(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" + "inject" + "mask" + "other" + "pub" + "public" + "some" +] @keyword + +[ + "con" + "control" + "ctl" + "fn" + "fun" + "rawctl" + "rcontrol" +] @keyword.function + +"with" @keyword.control + +[ + "elif" + "else" + "if" + "match" + "then" +] @keyword.control.conditional + +[ + "import" + "include" + "module" +] @keyword.control.import + +[ + "alias" + "effect" + "struct" + "type" + "val" + "var" +] @keyword.storage.type + +[ + "abstract" + "co" + "extend" + "extern" + "fbip" + "final" + "fip" + "inline" + "linear" + "named" + "noinline" + "open" + "override" + "raw" + "rec" + "ref" + "reference" + "scoped" + "tail" + "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..0a47bcbbd2413 --- /dev/null +++ b/runtime/queries/koka/indents.scm @@ -0,0 +1,39 @@ +[ + (appexpr ["[" "("]) ; Applications. + (ntlappexpr ["[" "("]) + (atom ["[" "("]) ; Lists and tuples. + (program (moduledecl "{")) ; Braced module declarations. + (funbody) + (block) + (handlerexpr) + (opclausex) +] @indent + +[ + (typedecl + [(typeid) (opdecls)]) ; Avoid matching single-operation effects. + (externdecl) + (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 "fun") @indent @extend +(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..f8a83e0cb4ba4 --- /dev/null +++ b/runtime/queries/koka/locals.scm @@ -0,0 +1,30 @@ +(modulebody) @local.scope + +(block) @local.scope + +(pattern + (identifier + (varid) @local.definition)) + +(decl + (apattern + (pattern + (identifier + (varid) @local.definition)))) + +(puredecl + (funid + (identifier + (varid) @local.definition))) + +(puredecl + (binder + (identifier + (varid) @local.definition))) + +(decl + (binder + (identifier + (varid) @local.definition))) + +(identifier (varid) @local.reference)