Skip to content

Commit 674c252

Browse files
committed
languages: add koka
1 parent a98ad13 commit 674c252

File tree

6 files changed

+316
-0
lines changed

6 files changed

+316
-0
lines changed

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
| julia |||| `julia` |
8383
| just |||| |
8484
| kdl |||| |
85+
| koka || || |
8586
| kotlin || | | `kotlin-language-server` |
8687
| latex ||| | `texlab` |
8788
| lean || | | `lean` |

languages.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,3 +3055,16 @@ language-servers = [ "templ" ]
30553055
[[grammar]]
30563056
name = "templ"
30573057
source = { git = "https://github.com/vrischmann/tree-sitter-templ", rev = "ea56ac0655243490a4929a988f4eaa91dfccc995" }
3058+
3059+
[[language]]
3060+
name = "koka"
3061+
scope = "source.koka"
3062+
injection-regex = "koka"
3063+
file-types = ["kk"]
3064+
roots = []
3065+
comment-token = "//"
3066+
indent = { tab-width = 8, unit = " " }
3067+
3068+
[[grammar]]
3069+
name = "koka"
3070+
source = { git = "https://github.com/mtoohey31/tree-sitter-koka", rev = "535f5204f08b2f8f37ef21bca7d0486f2ca70394" }
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
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+
14+
(ntlappexpr
15+
function: (ntlappexpr
16+
(atom
17+
(qidentifier
18+
[
19+
(qvarid)
20+
(qidop)
21+
(identifier
22+
[(varid) (idop)] @function)
23+
] @function))))
24+
25+
(appexpr
26+
field: (atom
27+
(qidentifier
28+
[
29+
(qvarid)
30+
(qidop)
31+
(identifier
32+
[(varid) (idop)] @function)
33+
] @function)))
34+
35+
(ntlappexpr
36+
field: (atom
37+
(qidentifier
38+
[
39+
(qvarid)
40+
(qidop)
41+
(identifier
42+
[(varid) (idop)] @function)
43+
] @function)))
44+
45+
[
46+
"initially"
47+
"finally"
48+
] @function.special
49+
50+
; Function definitions
51+
52+
(puredecl
53+
(funid
54+
(identifier
55+
[(varid) (idop)] @function)))
56+
57+
(fundecl
58+
(funid
59+
(identifier
60+
[(varid) (idop)] @function)))
61+
62+
(operation
63+
(identifier
64+
[(varid) (idop)] @function))
65+
66+
; Identifiers
67+
68+
(puredecl
69+
(binder
70+
(identifier
71+
[(varid) (idop)] @constant)))
72+
73+
; TODO: Highlight vars differently once helix has an appropriate highlight query
74+
; for that purpose.
75+
76+
(pparameter
77+
(pattern
78+
(identifier
79+
(varid) @variable.parameter)))
80+
81+
(paramid
82+
(identifier
83+
(varid) @variable.parameter))
84+
85+
(typeid
86+
(varid) @type)
87+
88+
(tbinder
89+
(varid) @type)
90+
91+
(typecon
92+
(varid) @type)
93+
94+
(qvarid
95+
(qid) @namespace)
96+
97+
(modulepath (varid) @namespace)
98+
99+
(qconid) @namespace
100+
101+
(qidop) @namespace
102+
103+
(varid) @variable
104+
105+
(conid) @constructor
106+
107+
; Operators
108+
109+
[
110+
"!"
111+
"~"
112+
"="
113+
":="
114+
(idop)
115+
(op)
116+
(qidop)
117+
] @operator
118+
119+
; Keywords
120+
121+
[
122+
"as"
123+
"behind"
124+
(externtarget)
125+
"forall"
126+
"handle"
127+
"handler"
128+
"in"
129+
"infix"
130+
"infixl"
131+
"infixr"
132+
"mask"
133+
"pub"
134+
"some"
135+
] @keyword
136+
137+
[
138+
"con"
139+
"ctl"
140+
"fn"
141+
"fun"
142+
] @keyword.function
143+
144+
"with" @keyword.control
145+
146+
[
147+
"elif"
148+
"else"
149+
"if"
150+
"match"
151+
"then"
152+
] @keyword.control.conditional
153+
154+
[
155+
"import"
156+
"module"
157+
] @keyword.control.import
158+
159+
[
160+
"alias"
161+
"effect"
162+
"struct"
163+
"type"
164+
"val"
165+
"var"
166+
] @keyword.storage.type
167+
168+
[
169+
"abstract"
170+
"co"
171+
"extend"
172+
"extern"
173+
"fbip"
174+
"final"
175+
"fip"
176+
"inline"
177+
"linear"
178+
"named"
179+
"noinline"
180+
"open"
181+
"override"
182+
"raw"
183+
"rec"
184+
"reference"
185+
"scoped"
186+
"tail"
187+
"value"
188+
] @keyword.storage.modifier
189+
190+
"return" @keyword.control.return
191+
192+
; Delimiters
193+
194+
(matchrule "|" @punctuation.delimiter)
195+
196+
[
197+
","
198+
"->"
199+
"."
200+
":"
201+
"::"
202+
"<-"
203+
";"
204+
] @punctuation.delimiter
205+
206+
[
207+
"<"
208+
">"
209+
"("
210+
")"
211+
"["
212+
"]"
213+
"{"
214+
"}"
215+
] @punctuation.bracket
216+
217+
; Literals
218+
219+
[
220+
(string)
221+
(char)
222+
] @string
223+
224+
(escape) @constant.character.escape
225+
226+
(float) @constant.numeric.float
227+
(int) @constant.numeric.integer
228+
229+
; Comment
230+
231+
[
232+
(linecomment)
233+
(blockcomment)
234+
] @comment

runtime/queries/koka/indents.scm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[
2+
(appexpr ["[" "("]) ; Applications.
3+
(ntlappexpr ["[" "("])
4+
(atom ["[" "("]) ; Lists and tuples.
5+
(program (moduledecl "{")) ; Braced module declarations.
6+
] @indent
7+
8+
[
9+
(funbody)
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 "match") @indent @extend
28+
(ERROR "->" @indent.always @extend)
29+
30+
; Don't outdent on function parameter declarations.
31+
(atom ")" @outdent @extend.prevent-once)
32+
33+
[
34+
"]"
35+
"}"
36+
] @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+
(varid) @local.reference

0 commit comments

Comments
 (0)