Skip to content

Commit 2e4653e

Browse files
add koka language support (#8727)
Co-authored-by: Pascal Kuthe <[email protected]>
1 parent 94d210c commit 2e4653e

File tree

6 files changed

+356
-0
lines changed

6 files changed

+356
-0
lines changed

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
| julia |||| `julia` |
9696
| just |||| |
9797
| kdl |||| |
98+
| koka || || |
9899
| kotlin || | | `kotlin-language-server` |
99100
| latex ||| | `texlab` |
100101
| ld || || |

languages.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,18 @@ indent = { tab-width = 2, unit = " " }
32303230
name = "hocon"
32313231
source = { git = "https://github.com/antosha417/tree-sitter-hocon", rev = "c390f10519ae69fdb03b3e5764f5592fb6924bcc" }
32323232

3233+
[[language]]
3234+
name = "koka"
3235+
scope = "source.koka"
3236+
injection-regex = "koka"
3237+
file-types = ["kk"]
3238+
comment-token = "//"
3239+
indent = { tab-width = 8, unit = " " }
3240+
3241+
[[grammar]]
3242+
name = "koka"
3243+
source = { git = "https://github.com/mtoohey31/tree-sitter-koka", rev = "2527e152d4b6a79fd50aebd8d0b4b4336c94a034" }
3244+
32333245
[[language]]
32343246
name = "tact"
32353247
scope = "source.tact"
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) @function
9+
(qidop) @function
10+
(identifier
11+
[(varid) (idop)] @function)
12+
])))
13+
["(" (block) (fnexpr)])
14+
15+
(ntlappexpr
16+
function: (ntlappexpr
17+
(atom
18+
(qidentifier
19+
[
20+
(qvarid) @function
21+
(qidop) @function
22+
(identifier
23+
[(varid) (idop)] @function)
24+
])))
25+
["(" (block) (fnexpr)])
26+
27+
(appexpr
28+
field: (atom
29+
(qidentifier
30+
[
31+
(qvarid) @function
32+
(qidop) @function
33+
(identifier
34+
[(varid) (idop)] @function)
35+
])))
36+
37+
(appexpr
38+
(appexpr
39+
field: (atom
40+
(qidentifier
41+
[
42+
(qvarid) @variable
43+
(qidop) @variable
44+
(identifier
45+
[(varid) (idop)] @variable)
46+
])))
47+
"[")
48+
49+
(ntlappexpr
50+
field: (atom
51+
(qidentifier
52+
[
53+
(qvarid) @function
54+
(qidop) @function
55+
(identifier
56+
[(varid) (idop)] @function)
57+
])))
58+
59+
(ntlappexpr
60+
(ntlappexpr
61+
field: (atom
62+
(qidentifier
63+
[
64+
(qvarid) @variable
65+
(qidop) @variable
66+
(identifier
67+
[(varid) (idop)] @variable)
68+
])))
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[
2+
(appexpr ["[" "("]) ; Applications.
3+
(ntlappexpr ["[" "("])
4+
(atom ["[" "("]) ; Lists and tuples.
5+
(program (moduledecl "{")) ; Braced module declarations.
6+
(funbody)
7+
(block)
8+
(handlerexpr)
9+
(opclausex)
10+
] @indent
11+
12+
[
13+
(typedecl
14+
[(typeid) (opdecls)]) ; Avoid matching single-operation effects.
15+
(externdecl)
16+
(matchexpr)
17+
(matchrule)
18+
19+
; For ifexprs, branches (once they exist) will contain blocks if they're
20+
; indented so we just need to make sure the initial indent happens when we're
21+
; creating them.
22+
"then"
23+
"else"
24+
] @indent @extend
25+
26+
(matchrule "->" @indent @extend)
27+
28+
; Handling for error recovery.
29+
(ERROR "fun") @indent @extend
30+
(ERROR "match") @indent @extend
31+
(ERROR "->" @indent.always @extend)
32+
33+
; Don't outdent on function parameter declarations.
34+
(atom ")" @outdent @extend.prevent-once)
35+
36+
[
37+
"]"
38+
"}"
39+
] @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)