Skip to content

Commit

Permalink
add koka language support (helix-editor#8727)
Browse files Browse the repository at this point in the history
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
  • Loading branch information
2 people authored and postsolar committed Apr 4, 2024
1 parent 4a4949e commit b750989
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
| julia |||| `julia` |
| just |||| |
| kdl |||| |
| koka || || |
| kotlin || | | `kotlin-language-server` |
| latex ||| | `texlab` |
| ld || || |
Expand Down
12 changes: 12 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,18 @@ indent = { tab-width = 2, unit = " " }
name = "hocon"
source = { git = "https://github.com/antosha417/tree-sitter-hocon", rev = "c390f10519ae69fdb03b3e5764f5592fb6924bcc" }

[[language]]
name = "koka"
scope = "source.koka"
injection-regex = "koka"
file-types = ["kk"]
comment-token = "//"
indent = { tab-width = 8, unit = " " }

[[grammar]]
name = "koka"
source = { git = "https://github.com/mtoohey31/tree-sitter-koka", rev = "2527e152d4b6a79fd50aebd8d0b4b4336c94a034" }

[[language]]
name = "tact"
scope = "source.tact"
Expand Down
272 changes: 272 additions & 0 deletions runtime/queries/koka/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions runtime/queries/koka/indents.scm
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions runtime/queries/koka/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
([(linecomment) (blockcomment)] @injection.content
(#set! injection.language "comment"))
30 changes: 30 additions & 0 deletions runtime/queries/koka/locals.scm
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b750989

Please sign in to comment.