plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
906b92e
— Peter John
2026-07-20T21:29:37+05:30
feat(tree-sitter-plum): wire closure literals into expression position; add fn(...) type syntax
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -125,10 +125,19 @@ module.exports = grammar({
|
|
|
125
125
|
seq(
|
|
126
126
|
field("name", $.var_identifier),
|
|
127
127
|
":",
|
|
128
|
-
field("type", choice($.type, $.variadic_type)),
|
|
128
|
+
field("type", choice($.type, $.variadic_type, $.fn_value_type)),
|
|
129
129
|
optional(seq("=", field("value", $.expression))),
|
|
130
130
|
),
|
|
131
131
|
|
|
132
|
+
fn_value_type: ($) =>
|
|
133
|
+
seq(
|
|
134
|
+
"fn",
|
|
135
|
+
"(",
|
|
136
|
+
field("params", optional(commaSep1($.type))),
|
|
137
|
+
")",
|
|
138
|
+
optional(seq("->", field("returns", $.type))),
|
|
139
|
+
),
|
|
140
|
+
|
|
132
141
|
return_type: ($) =>
|
|
133
142
|
seq($.type_identifier, field("generics", optional($.generics))),
|
|
134
143
|
|
|
@@ -263,7 +272,7 @@ module.exports = grammar({
|
|
|
263
272
|
$.comparison_operator,
|
|
264
273
|
$.not_operator,
|
|
265
274
|
$.boolean_operator,
|
|
266
|
-
|
|
275
|
+
$.closure,
|
|
267
276
|
$.primary_expression,
|
|
268
277
|
$.ternary_expression,
|
|
269
278
|
),
|
tooling/tree-sitter-plum/src/grammar.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/node-types.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/parser.c
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/test/corpus/function.txt
CHANGED
|
@@ -240,3 +240,119 @@ pick(cond: Bool, a: Int, b: Int) -> Int =
|
|
|
240
240
|
(expression
|
|
241
241
|
(primary_expression
|
|
242
242
|
(var_identifier))))))))
|
|
243
|
+
|
|
244
|
+
================================================================================
|
|
245
|
+
function - closure literal in expression position
|
|
246
|
+
================================================================================
|
|
247
|
+
|
|
248
|
+
useClosure() -> Bool =
|
|
249
|
+
cb = |v|
|
|
250
|
+
True
|
|
251
|
+
cb(5)
|
|
252
|
+
|
|
253
|
+
--------------------------------------------------------------------------------
|
|
254
|
+
|
|
255
|
+
(source
|
|
256
|
+
(fn
|
|
257
|
+
(fn_identifier)
|
|
258
|
+
(return_type
|
|
259
|
+
(type_identifier))
|
|
260
|
+
(body
|
|
261
|
+
(assign
|
|
262
|
+
(var_identifier)
|
|
263
|
+
(expression
|
|
264
|
+
(closure
|
|
265
|
+
(var_identifier)
|
|
266
|
+
(body
|
|
267
|
+
(expression
|
|
268
|
+
(primary_expression
|
|
269
|
+
(type_identifier)))))))
|
|
270
|
+
(expression
|
|
271
|
+
(primary_expression
|
|
272
|
+
(fn_call
|
|
273
|
+
(var_identifier)
|
|
274
|
+
(fn_argument_list
|
|
275
|
+
(expression
|
|
276
|
+
(primary_expression
|
|
277
|
+
(integer))))))))))
|
|
278
|
+
|
|
279
|
+
================================================================================
|
|
280
|
+
function - closure literal with no params
|
|
281
|
+
================================================================================
|
|
282
|
+
|
|
283
|
+
useClosure() -> Bool =
|
|
284
|
+
cb = ||
|
|
285
|
+
True
|
|
286
|
+
cb()
|
|
287
|
+
|
|
288
|
+
--------------------------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
(source
|
|
291
|
+
(fn
|
|
292
|
+
(fn_identifier)
|
|
293
|
+
(return_type
|
|
294
|
+
(type_identifier))
|
|
295
|
+
(body
|
|
296
|
+
(assign
|
|
297
|
+
(var_identifier)
|
|
298
|
+
(expression
|
|
299
|
+
(closure
|
|
300
|
+
(body
|
|
301
|
+
(expression
|
|
302
|
+
(primary_expression
|
|
303
|
+
(type_identifier)))))))
|
|
304
|
+
(expression
|
|
305
|
+
(primary_expression
|
|
306
|
+
(fn_call
|
|
307
|
+
(var_identifier)
|
|
308
|
+
(fn_argument_list)))))))
|
|
309
|
+
|
|
310
|
+
================================================================================
|
|
311
|
+
function - function-value type param annotation
|
|
312
|
+
================================================================================
|
|
313
|
+
|
|
314
|
+
each(cb: fn(Int)) -> Bool =
|
|
315
|
+
True
|
|
316
|
+
|
|
317
|
+
--------------------------------------------------------------------------------
|
|
318
|
+
|
|
319
|
+
(source
|
|
320
|
+
(fn
|
|
321
|
+
(fn_identifier)
|
|
322
|
+
(param
|
|
323
|
+
(var_identifier)
|
|
324
|
+
(fn_value_type
|
|
325
|
+
(type
|
|
326
|
+
(type_identifier))))
|
|
327
|
+
(return_type
|
|
328
|
+
(type_identifier))
|
|
329
|
+
(body
|
|
330
|
+
(expression
|
|
331
|
+
(primary_expression
|
|
332
|
+
(type_identifier))))))
|
|
333
|
+
|
|
334
|
+
================================================================================
|
|
335
|
+
function - function-value type param annotation with generic types and return
|
|
336
|
+
================================================================================
|
|
337
|
+
|
|
338
|
+
each(cb: fn(a) -> b) -> Bool =
|
|
339
|
+
True
|
|
340
|
+
|
|
341
|
+
--------------------------------------------------------------------------------
|
|
342
|
+
|
|
343
|
+
(source
|
|
344
|
+
(fn
|
|
345
|
+
(fn_identifier)
|
|
346
|
+
(param
|
|
347
|
+
(var_identifier)
|
|
348
|
+
(fn_value_type
|
|
349
|
+
(type
|
|
350
|
+
(a))
|
|
351
|
+
(type
|
|
352
|
+
(b))))
|
|
353
|
+
(return_type
|
|
354
|
+
(type_identifier))
|
|
355
|
+
(body
|
|
356
|
+
(expression
|
|
357
|
+
(primary_expression
|
|
358
|
+
(type_identifier))))))
|