Unnamed repository; edit this file 'description' to name the repository.
Update koka grammar and queries to support koka v3 (#14135)
chtenb 7 months ago
parent fdfc6df · commit 93cf3b1
-rw-r--r--languages.toml2
-rw-r--r--runtime/queries/koka/highlights.scm313
-rw-r--r--runtime/queries/koka/indents.scm4
-rw-r--r--runtime/queries/koka/locals.scm25
4 files changed, 156 insertions, 188 deletions
diff --git a/languages.toml b/languages.toml
index 19133a86..34035907 100644
--- a/languages.toml
+++ b/languages.toml
@@ -3806,7 +3806,7 @@ language-servers = ["koka"]
[[grammar]]
name = "koka"
-source = { git = "https://github.com/mtoohey31/tree-sitter-koka", rev = "96d070c3700692858035f3524cc0ad944cef2594" }
+source = { git = "https://github.com/koka-community/tree-sitter-koka", rev = "fd3b482274d6988349ba810ea5740e29153b1baf" }
[[language]]
name = "tact"
diff --git a/runtime/queries/koka/highlights.scm b/runtime/queries/koka/highlights.scm
index cec2881f..65eb441d 100644
--- a/runtime/queries/koka/highlights.scm
+++ b/runtime/queries/koka/highlights.scm
@@ -1,122 +1,51 @@
-; Identifiers
-
-(qconid) @namespace
-
-(qidop) @namespace
-
-(varid) @variable
-
-(conid) @constructor
-
-(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))
+; Comment
-(typedecl
- "effect"
- (varid) @type)
+[
+ (linecomment)
+ (blockcomment)
+] @comment
-(typeid
- (varid) @type)
+; Literals
-(tbinder
- (varid) @type)
+(string) @string
+(char) @constant.character
-(typecon
- (varid) @type)
+(escape) @constant.character.escape
-(qvarid
- (qid) @namespace)
+(float) @constant.numeric.float
+(int) @constant.numeric.integer
-(modulepath (varid) @namespace)
+; Delimiters
-; Function calls
+(matchrule "|" @punctuation.delimiter)
-(appexpr
- function: (appexpr
- (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)
- ])))
- "[")
+(tatomic "|" @punctuation.delimiter)
[
- "initially"
- "finally"
-] @function.special
-
-; Function definitions
-
-(puredecl
- (funid
- (identifier
- [(varid) (idop)] @function)))
-
-(fundecl
- (funid
- (identifier
- [(varid) (idop)] @function)))
-
-(operation
- (identifier
- [(varid) (idop)] @function))
-
-; Operators
+ ","
+ "->"
+ "."
+ ":"
+ "::"
+ "<-"
+ ";"
+] @punctuation.delimiter
[
- "!"
- "~"
- "="
- ":="
- (idop)
- (op)
- (qidop)
-] @operator
+ "<"
+ ">"
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
; Keywords
[
"as"
- "behind"
(externtarget)
"forall"
"handle"
@@ -125,22 +54,25 @@
"infix"
"infixl"
"infixr"
- "inject"
"mask"
- "other"
- "pub"
- "public"
+ (behindmod)
+ (pub)
"some"
] @keyword
+; Lazy constructor
+(constructor
+ "lazy" @keyword)
+
+; Lazy match
+(matchexpr
+ "lazy" @keyword)
+
[
- "con"
- "control"
+ (con)
"ctl"
"fn"
"fun"
- "rawctl"
- "rcontrol"
] @keyword.function
"with" @keyword.control
@@ -155,7 +87,7 @@
[
"import"
- "include"
+ ;"include"
"module"
] @keyword.control.import
@@ -170,69 +102,130 @@
[
"abstract"
- "co"
- "extend"
"extern"
- "fbip"
"final"
- "fip"
- "inline"
- "linear"
+ (inlinemod)
+ (externinline)
+ (typemod)
+ (structmod)
+ (effectmod)
"named"
- "noinline"
- "open"
- "override"
- "raw"
- "rec"
- "ref"
- "reference"
- "scoped"
- "tail"
- "value"
+ (override)
+ (controlmod)
+ ;"scoped" ; scoped is actually an effect modifier, but it is not in the current parser.
+ (tailmod)
] @keyword.storage.modifier
-"return" @keyword.control.return
+(fipmod
+ ["fip" "fbip"] @keyword.storage.modifier)
-; Delimiters
+"return" @keyword.control.return
-(matchrule "|" @punctuation.delimiter)
+; Operators
[
- ","
- "->"
- "."
- ":"
- "::"
- "<-"
- ";"
-] @punctuation.delimiter
+ "!"
+ "~"
+ "="
+ ":="
+ (idop)
+ (op)
+ (qidop)
+] @operator
-[
- "<"
- ">"
- "("
- ")"
- "["
- "]"
- "{"
- "}"
-] @punctuation.bracket
+(modulepath) @namespace
-; Literals
+; Variables
-[
- (string)
- (char)
-] @string
+(pattern
+ (identifier
+ (varid) @variable))
-(escape) @constant.character.escape
+(paramid
+ (identifier
+ (varid) @variable.parameter))
-(float) @constant.numeric.float
-(int) @constant.numeric.integer
+(pparameter
+ (pattern
+ (identifier
+ (varid) @variable.parameter)))
-; Comment
+(pparameter
+ (qimplicit) @variable.parameter)
+
+(puredecl
+ (binder
+ (qidentifier) @constant))
+
+; Named arguments
+(argument
+ [(identifier) (qimplicit)] @variable.parameter
+ "="
+ (expr))
+
+; Types
+
+(typecon
+ [(varid) (qvarid)] @type)
+
+(tbinder
+ (varid) @type)
+
+(typeid
+ (varid) @type)
+
+(typedecl
+ "effect"
+ (varid) @type)
+
+; Function definitions
+
+(fundecl
+ (identifier) @function)
+
+(puredecl
+ (qidentifier) @function)
+
+(externdecl
+ (qidentifier) @function)
+
+; Effect definitions/usages
+
+(opclause
+ (qidentifier) @function)
+
+(operation
+ (identifier) @function)
+
+
+; Function calls
+
+(opexpr
+ (atom
+ (name) @function)
+ .
+ [
+ call: "(" (arguments)? ")"
+ trailing_lambda: [(block) (fnexpr)]
+ ])
+
+(opexpr
+ (atom)
+ (name) @function)
+
+(ntlexpr
+ (atom
+ (name) @function)
+ .
+ ("(" (arguments)? ")"))
+
+(ntlexpr
+ (atom)
+ (name) @function)
+
+[(conid) (qconid)] @constructor
[
- (linecomment)
- (blockcomment)
-] @comment
+ "initially"
+ "finally"
+] @function.builtin
diff --git a/runtime/queries/koka/indents.scm b/runtime/queries/koka/indents.scm
index 6045373d..e496f30b 100644
--- a/runtime/queries/koka/indents.scm
+++ b/runtime/queries/koka/indents.scm
@@ -1,9 +1,9 @@
[
- (appexpr ["[" "("]) ; Applications.
+ (opexpr [index: (arguments) call: (arguments)]) ; Applications.
(atom ["[" "("]) ; Lists and tuples.
- (program (moduledecl "{")) ; Braced module declarations.
(funbody)
(block)
+ (constructor)
(handlerexpr)
(opclausex)
] @indent
diff --git a/runtime/queries/koka/locals.scm b/runtime/queries/koka/locals.scm
deleted file mode 100644
index e654f70c..00000000
--- a/runtime/queries/koka/locals.scm
+++ /dev/null
@@ -1,25 +0,0 @@
-(modulebody) @local.scope
-
-(block) @local.scope
-
-(pparameter
- (pattern
- (identifier
- (varid) @local.definition.variable.parameter)))
-
-(puredecl
- (funid
- (identifier
- (varid) @local.definition.function)))
-
-(puredecl
- (binder
- (identifier
- (varid) @local.definition.function)))
-
-(decl
- (binder
- (identifier
- (varid) @local.definition.function)))
-
-(identifier (varid) @local.reference)