Skip to content

Commit bd6e42e

Browse files
committed
languages: add koka
1 parent 783ff27 commit bd6e42e

6 files changed

Lines changed: 355 additions & 0 deletions

File tree

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
| julia |||| `julia` |
8787
| just |||| |
8888
| kdl |||| |
89+
| koka || || |
8990
| kotlin || | | `kotlin-language-server` |
9091
| latex ||| | `texlab` |
9192
| lean || | | `lean` |

languages.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,3 +3006,16 @@ file-types = ["janet"]
30063006
comment-token = "#"
30073007
indent = { tab-width = 2, unit = " " }
30083008
grammar = "clojure"
3009+
3010+
[[language]]
3011+
name = "koka"
3012+
scope = "source.koka"
3013+
injection-regex = "koka"
3014+
file-types = ["kk"]
3015+
roots = []
3016+
comment-token = "//"
3017+
indent = { tab-width = 8, unit = " " }
3018+
3019+
[[grammar]]
3020+
name = "koka"
3021+
source = { git = "https://github.com/mtoohey31/tree-sitter-koka", rev = "1fbed3cc448b162f955b48fb1a913df551b728d3" }
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
; Function calls
2+
3+
(appexpr
4+
function: (appexpr
5+
(atom
6+
(qidentifier
7+
[
8+
(qvarid)
9+
(qidop)
10+
(identifier
11+
[(varid) (idop)] @function)
12+
] @function)))
13+
["(" (block) (fnexpr)])
14+
15+
(ntlappexpr
16+
function: (ntlappexpr
17+
(atom
18+
(qidentifier
19+
[
20+
(qvarid)
21+
(qidop)
22+
(identifier
23+
[(varid) (idop)] @function)
24+
] @function)))
25+
["(" (block) (fnexpr)])
26+
27+
(appexpr
28+
field: (atom
29+
(qidentifier
30+
[
31+
(qvarid)
32+
(qidop)
33+
(identifier
34+
[(varid) (idop)] @function)
35+
] @function)))
36+
37+
(appexpr
38+
(appexpr
39+
field: (atom
40+
(qidentifier
41+
[
42+
(qvarid)
43+
(qidop)
44+
(identifier
45+
[(varid) (idop)] @variable)
46+
] @variable)))
47+
"[")
48+
49+
(ntlappexpr
50+
field: (atom
51+
(qidentifier
52+
[
53+
(qvarid)
54+
(qidop)
55+
(identifier
56+
[(varid) (idop)] @function)
57+
] @function)))
58+
59+
(ntlappexpr
60+
(ntlappexpr
61+
field: (atom
62+
(qidentifier
63+
[
64+
(qvarid)
65+
(qidop)
66+
(identifier
67+
[(varid) (idop)] @variable)
68+
] @variable)))
69+
"[")
70+
71+
[
72+
"initially"
73+
"finally"
74+
] @function.special
75+
76+
; Function definitions
77+
78+
(puredecl
79+
(funid
80+
(identifier
81+
[(varid) (idop)] @function)))
82+
83+
(fundecl
84+
(funid
85+
(identifier
86+
[(varid) (idop)] @function)))
87+
88+
(operation
89+
(identifier
90+
[(varid) (idop)] @function))
91+
92+
; Identifiers
93+
94+
(puredecl
95+
(binder
96+
(identifier
97+
[(varid) (idop)] @constant)))
98+
99+
; TODO: Highlight vars differently once helix has an appropriate highlight query
100+
; for that purpose.
101+
102+
(pparameter
103+
(pattern
104+
(identifier
105+
(varid) @variable.parameter)))
106+
107+
(paramid
108+
(identifier
109+
(varid) @variable.parameter))
110+
111+
(typedecl
112+
"effect"
113+
(varid) @type)
114+
115+
(typeid
116+
(varid) @type)
117+
118+
(tbinder
119+
(varid) @type)
120+
121+
(typecon
122+
(varid) @type)
123+
124+
(qvarid
125+
(qid) @namespace)
126+
127+
(modulepath (varid) @namespace)
128+
129+
(qconid) @namespace
130+
131+
(qidop) @namespace
132+
133+
(varid) @variable
134+
135+
(conid) @constructor
136+
137+
; Operators
138+
139+
[
140+
"!"
141+
"~"
142+
"="
143+
":="
144+
(idop)
145+
(op)
146+
(qidop)
147+
] @operator
148+
149+
; Keywords
150+
151+
[
152+
"as"
153+
"behind"
154+
(externtarget)
155+
"forall"
156+
"handle"
157+
"handler"
158+
"in"
159+
"infix"
160+
"infixl"
161+
"infixr"
162+
"inject"
163+
"mask"
164+
"other"
165+
"pub"
166+
"public"
167+
"some"
168+
] @keyword
169+
170+
[
171+
"con"
172+
"control"
173+
"ctl"
174+
"fn"
175+
"fun"
176+
"rawctl"
177+
"rcontrol"
178+
] @keyword.function
179+
180+
"with" @keyword.control
181+
182+
[
183+
"elif"
184+
"else"
185+
"if"
186+
"match"
187+
"then"
188+
] @keyword.control.conditional
189+
190+
[
191+
"import"
192+
"include"
193+
"module"
194+
] @keyword.control.import
195+
196+
[
197+
"alias"
198+
"effect"
199+
"struct"
200+
"type"
201+
"val"
202+
"var"
203+
] @keyword.storage.type
204+
205+
[
206+
"abstract"
207+
"co"
208+
"extend"
209+
"extern"
210+
"fbip"
211+
"final"
212+
"fip"
213+
"inline"
214+
"linear"
215+
"named"
216+
"noinline"
217+
"open"
218+
"override"
219+
"raw"
220+
"rec"
221+
"ref"
222+
"reference"
223+
"scoped"
224+
"tail"
225+
"value"
226+
] @keyword.storage.modifier
227+
228+
"return" @keyword.control.return
229+
230+
; Delimiters
231+
232+
(matchrule "|" @punctuation.delimiter)
233+
234+
[
235+
","
236+
"->"
237+
"."
238+
":"
239+
"::"
240+
"<-"
241+
";"
242+
] @punctuation.delimiter
243+
244+
[
245+
"<"
246+
">"
247+
"("
248+
")"
249+
"["
250+
"]"
251+
"{"
252+
"}"
253+
] @punctuation.bracket
254+
255+
; Literals
256+
257+
[
258+
(string)
259+
(char)
260+
] @string
261+
262+
(escape) @constant.character.escape
263+
264+
(float) @constant.numeric.float
265+
(int) @constant.numeric.integer
266+
267+
; Comment
268+
269+
[
270+
(linecomment)
271+
(blockcomment)
272+
] @comment

runtime/queries/koka/indents.scm

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
(appexpr ["[" "("]) ; Applications.
3+
(ntlappexpr ["[" "("])
4+
(atom ["[" "("]) ; Lists and tuples.
5+
(program (moduledecl "{")) ; Braced module declarations.
6+
(funbody)
7+
] @indent
8+
9+
[
10+
(typedecl
11+
[(typeid) (opdecls)]) ; Avoid matching single-operation effects.
12+
(externdecl)
13+
(block)
14+
(matchexpr)
15+
(matchrule)
16+
17+
; For ifexprs, branches (once they exist) will contain blocks if they're
18+
; indented so we just need to make sure the initial indent happens when we're
19+
; creating them.
20+
"then"
21+
"else"
22+
] @indent @extend
23+
24+
(matchrule "->" @indent @extend)
25+
26+
; Handling for error recovery.
27+
(ERROR "fun") @indent @extend
28+
(ERROR "match") @indent @extend
29+
(ERROR "->" @indent.always @extend)
30+
31+
; Don't outdent on function parameter declarations.
32+
(atom ")" @outdent @extend.prevent-once)
33+
34+
[
35+
"]"
36+
"}"
37+
] @outdent @extend.prevent-once
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
([(linecomment) (blockcomment)] @injection.content
2+
(#set! injection.language "comment"))

runtime/queries/koka/locals.scm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(modulebody) @local.scope
2+
3+
(block) @local.scope
4+
5+
(pattern
6+
(identifier
7+
(varid) @local.definition))
8+
9+
(decl
10+
(apattern
11+
(pattern
12+
(identifier
13+
(varid) @local.definition))))
14+
15+
(puredecl
16+
(funid
17+
(identifier
18+
(varid) @local.definition)))
19+
20+
(puredecl
21+
(binder
22+
(identifier
23+
(varid) @local.definition)))
24+
25+
(decl
26+
(binder
27+
(identifier
28+
(varid) @local.definition)))
29+
30+
(identifier (varid) @local.reference)

0 commit comments

Comments
 (0)