From 54c34b9854e8ab9a752c8edab9fc7705397ffab1 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 | 221 ++++++++++++++++++++++++++++ runtime/queries/koka/indents.scm | 35 +++++ runtime/queries/koka/injections.scm | 2 + runtime/queries/koka/locals.scm | 30 ++++ 6 files changed, 302 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 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..6461d9d573ad5 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 = "68ff667bc4e0c00435c49cad0e82d57213708081" } diff --git a/runtime/queries/koka/highlights.scm b/runtime/queries/koka/highlights.scm new file mode 100644 index 0000000000000..cbf01fb42a0b7 --- /dev/null +++ b/runtime/queries/koka/highlights.scm @@ -0,0 +1,221 @@ +; 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" + "fbip" + "final" + "fip" + "inline" + "linear" + "named" + "noinline" + "open" + "override" + "raw" + "rec" + "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..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..21fc659b584a3 --- /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))) + +(varid) @local.reference