Skip to content

Commit

Permalink
languages: add koka
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoohey31 committed Nov 16, 2023
1 parent a98ad13 commit 54c34b9
Show file tree
Hide file tree
Showing 6 changed files with 302 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 @@ -82,6 +82,7 @@
| julia |||| `julia` |
| just |||| |
| kdl |||| |
| koka || || |
| kotlin || | | `kotlin-language-server` |
| latex ||| | `texlab` |
| lean || | | `lean` |
Expand Down
13 changes: 13 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
221 changes: 221 additions & 0 deletions runtime/queries/koka/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions runtime/queries/koka/indents.scm
Original file line number Diff line number Diff line change
@@ -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
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)))

(varid) @local.reference

0 comments on commit 54c34b9

Please sign in to comment.