plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
c06ddba
— Peter John
2026-08-09T18:35:20+05:30
feat(grammar): add `fun` keyword to function/method declarations
- tooling/tree-sitter-plum/grammar.js +1 -0
- tooling/tree-sitter-plum/queries/plum/highlights.scm +1 -0
- tooling/tree-sitter-plum/src/grammar.json +0 -0
- tooling/tree-sitter-plum/src/node-types.json +0 -0
- tooling/tree-sitter-plum/src/parser.c +0 -0
- tooling/tree-sitter-plum/test/aa.plum +5 -5
- tooling/tree-sitter-plum/test/corpus/assert.txt +1 -1
- tooling/tree-sitter-plum/test/corpus/assign.txt +2 -2
- tooling/tree-sitter-plum/test/corpus/enum.txt +1 -1
- tooling/tree-sitter-plum/test/corpus/for.txt +1 -1
- tooling/tree-sitter-plum/test/corpus/function.txt +16 -16
- tooling/tree-sitter-plum/test/corpus/if.txt +1 -1
- tooling/tree-sitter-plum/test/corpus/literals.txt +1 -1
- tooling/tree-sitter-plum/test/corpus/match.txt +3 -3
- tooling/tree-sitter-plum/test/corpus/type.txt +4 -4
- tooling/tree-sitter-plum/test/corpus/while.txt +1 -1
- tooling/tree-sitter-plum/test/highlight/sample.plum +4 -4
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -162,6 +162,7 @@ module.exports = grammar({
|
|
|
162
162
|
fn: ($) =>
|
|
163
163
|
prec.left(
|
|
164
164
|
seq(
|
|
165
|
+
"fun",
|
|
165
166
|
field("name", $.fn_identifier),
|
|
166
167
|
field("type", optional(alias($.fn_type, $.type))),
|
|
167
168
|
// A method's implicit receiver may be spelled out explicitly as a bare
|
tooling/tree-sitter-plum/queries/plum/highlights.scm
CHANGED
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"type"
|
|
75
75
|
"enum"
|
|
76
76
|
"trait"
|
|
77
|
+
"fun"
|
|
77
78
|
] @keyword
|
|
78
79
|
|
|
79
80
|
[
|
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/aa.plum
CHANGED
|
@@ -17,16 +17,16 @@ type Cat(IAnimal, IToStr) =
|
|
|
17
17
|
name: Str
|
|
18
18
|
age: Int
|
|
19
19
|
|
|
20
|
-
withName<Cat>(name: Str) -> Cat =
|
|
20
|
+
fun withName<Cat>(name: Str) -> Cat =
|
|
21
21
|
Cat(name: name, age: self.age)
|
|
22
22
|
|
|
23
|
-
withAge<Cat>(age: Int) -> Cat =
|
|
23
|
+
fun withAge<Cat>(age: Int) -> Cat =
|
|
24
24
|
Cat(name: self.name, age: age)
|
|
25
25
|
|
|
26
|
-
speak<Cat>() -> Str =
|
|
26
|
+
fun speak<Cat>() -> Str =
|
|
27
27
|
"meow"
|
|
28
28
|
|
|
29
|
-
toStr<Cat>() -> Str =
|
|
29
|
+
fun toStr<Cat>() -> Str =
|
|
30
30
|
for i in 0..10
|
|
31
31
|
printLn("delta")
|
|
32
32
|
if dog > 1
|
|
@@ -35,5 +35,5 @@ toStr<Cat>() -> Str =
|
|
|
35
35
|
printLn("New")
|
|
36
36
|
"Cat({self.name}, {self.age})"
|
|
37
37
|
|
|
38
|
-
main() =
|
|
38
|
+
fun main() =
|
|
39
39
|
printLn("Hello world")
|
tooling/tree-sitter-plum/test/corpus/assert.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
assert
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
main() =
|
|
5
|
+
fun main() =
|
|
6
6
|
assert 1 != 2
|
|
7
7
|
assert 5 > 4
|
|
8
8
|
assert 7 != 9
|
tooling/tree-sitter-plum/test/corpus/assign.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
assign
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
main() =
|
|
5
|
+
fun main() =
|
|
6
6
|
sum = 1 + {{2 * 3} / 4}
|
|
7
7
|
enabled = !False
|
|
8
8
|
open = {count > 10} && {enabled == True} || {debug == False}
|
|
@@ -267,7 +267,7 @@ main() =
|
|
|
267
267
|
field assignment target
|
|
268
268
|
================================================================================
|
|
269
269
|
|
|
270
|
-
main() =
|
|
270
|
+
fun main() =
|
|
271
271
|
self.head = value
|
|
272
272
|
self.head.value = x
|
|
273
273
|
a, self.field = 1, 2
|
tooling/tree-sitter-plum/test/corpus/enum.txt
CHANGED
|
@@ -6,7 +6,7 @@ enum Bool =
|
|
|
6
6
|
| True
|
|
7
7
|
| False
|
|
8
8
|
|
|
9
|
-
toStr<Bool>() -> Str =
|
|
9
|
+
fun toStr<Bool>() -> Str =
|
|
10
10
|
"Bool"
|
|
11
11
|
|
|
12
12
|
--------------------------------------------------------------------------------
|
tooling/tree-sitter-plum/test/corpus/for.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
for
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
main() =
|
|
5
|
+
fun main() =
|
|
6
6
|
for i in 0..10
|
|
7
7
|
printLn("for")
|
|
8
8
|
break
|
tooling/tree-sitter-plum/test/corpus/function.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
function - no return
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
sum(a: Int, b: Int) =
|
|
5
|
+
fun sum(a: Int, b: Int) =
|
|
6
6
|
todo
|
|
7
7
|
|
|
8
8
|
--------------------------------------------------------------------------------
|
|
@@ -25,7 +25,7 @@ sum(a: Int, b: Int) =
|
|
|
25
25
|
function - return
|
|
26
26
|
================================================================================
|
|
27
27
|
|
|
28
|
-
sum(a: Int, b: Int) -> Int =
|
|
28
|
+
fun sum(a: Int, b: Int) -> Int =
|
|
29
29
|
todo
|
|
30
30
|
|
|
31
31
|
--------------------------------------------------------------------------------
|
|
@@ -50,7 +50,7 @@ sum(a: Int, b: Int) -> Int =
|
|
|
50
50
|
function - default value
|
|
51
51
|
================================================================================
|
|
52
52
|
|
|
53
|
-
random(a: Int = 10) =
|
|
53
|
+
fun random(a: Int = 10) =
|
|
54
54
|
todo
|
|
55
55
|
|
|
56
56
|
--------------------------------------------------------------------------------
|
|
@@ -72,7 +72,7 @@ random(a: Int = 10) =
|
|
|
72
72
|
function - generics
|
|
73
73
|
================================================================================
|
|
74
74
|
|
|
75
|
-
add(param: T, param2: List[U]) -> List[U] =
|
|
75
|
+
fun add(param: T, param2: List[U]) -> List[U] =
|
|
76
76
|
todo
|
|
77
77
|
|
|
78
78
|
--------------------------------------------------------------------------------
|
|
@@ -101,7 +101,7 @@ add(param: T, param2: List[U]) -> List[U] =
|
|
|
101
101
|
function - method
|
|
102
102
|
================================================================================
|
|
103
103
|
|
|
104
|
-
fullname<User>() -> String =
|
|
104
|
+
fun fullname<User>() -> String =
|
|
105
105
|
todo
|
|
106
106
|
|
|
107
107
|
--------------------------------------------------------------------------------
|
|
@@ -120,7 +120,7 @@ fullname<User>() -> String =
|
|
|
120
120
|
function - method with explicit self param
|
|
121
121
|
================================================================================
|
|
122
122
|
|
|
123
|
-
remove<List>(self, v: T) =
|
|
123
|
+
fun remove<List>(self, v: T) =
|
|
124
124
|
todo
|
|
125
125
|
|
|
126
126
|
--------------------------------------------------------------------------------
|
|
@@ -142,7 +142,7 @@ remove<List>(self, v: T) =
|
|
|
142
142
|
function - variant construction call (positional args on a capitalized name)
|
|
143
143
|
================================================================================
|
|
144
144
|
|
|
145
|
-
makeSome(v: Int) -> Option =
|
|
145
|
+
fun makeSome(v: Int) -> Option =
|
|
146
146
|
Some(v)
|
|
147
147
|
|
|
148
148
|
--------------------------------------------------------------------------------
|
|
@@ -170,7 +170,7 @@ makeSome(v: Int) -> Option =
|
|
|
170
170
|
function - bare comparison as body's trailing statement
|
|
171
171
|
================================================================================
|
|
172
172
|
|
|
173
|
-
isNone(o: Option) -> Bool =
|
|
173
|
+
fun isNone(o: Option) -> Bool =
|
|
174
174
|
o == None
|
|
175
175
|
|
|
176
176
|
--------------------------------------------------------------------------------
|
|
@@ -196,7 +196,7 @@ isNone(o: Option) -> Bool =
|
|
|
196
196
|
function - bare boolean-operator as body's trailing statement
|
|
197
197
|
================================================================================
|
|
198
198
|
|
|
199
|
-
bothTrue(a: Bool, b: Bool) -> Bool =
|
|
199
|
+
fun bothTrue(a: Bool, b: Bool) -> Bool =
|
|
200
200
|
a && b
|
|
201
201
|
|
|
202
202
|
--------------------------------------------------------------------------------
|
|
@@ -228,7 +228,7 @@ bothTrue(a: Bool, b: Bool) -> Bool =
|
|
|
228
228
|
function - bare ternary as body's trailing statement
|
|
229
229
|
================================================================================
|
|
230
230
|
|
|
231
|
-
pick(cond: Bool, a: Int, b: Int) -> Int =
|
|
231
|
+
fun pick(cond: Bool, a: Int, b: Int) -> Int =
|
|
232
232
|
cond ? a : b
|
|
233
233
|
|
|
234
234
|
--------------------------------------------------------------------------------
|
|
@@ -267,7 +267,7 @@ pick(cond: Bool, a: Int, b: Int) -> Int =
|
|
|
267
267
|
function - closure literal in expression position
|
|
268
268
|
================================================================================
|
|
269
269
|
|
|
270
|
-
useClosure() -> Bool =
|
|
270
|
+
fun useClosure() -> Bool =
|
|
271
271
|
cb = |v|
|
|
272
272
|
True
|
|
273
273
|
cb(5)
|
|
@@ -302,7 +302,7 @@ useClosure() -> Bool =
|
|
|
302
302
|
function - closure literal with no params
|
|
303
303
|
================================================================================
|
|
304
304
|
|
|
305
|
-
useClosure() -> Bool =
|
|
305
|
+
fun useClosure() -> Bool =
|
|
306
306
|
cb = ||
|
|
307
307
|
True
|
|
308
308
|
cb()
|
|
@@ -333,7 +333,7 @@ useClosure() -> Bool =
|
|
|
333
333
|
function - function-value type param annotation
|
|
334
334
|
================================================================================
|
|
335
335
|
|
|
336
|
-
each(cb: fn(Int)) -> Bool =
|
|
336
|
+
fun each(cb: fn(Int)) -> Bool =
|
|
337
337
|
True
|
|
338
338
|
|
|
339
339
|
--------------------------------------------------------------------------------
|
|
@@ -357,7 +357,7 @@ each(cb: fn(Int)) -> Bool =
|
|
|
357
357
|
function - function-value type param annotation with generic types and return
|
|
358
358
|
================================================================================
|
|
359
359
|
|
|
360
|
-
each(cb: fn(T) -> U) -> Bool =
|
|
360
|
+
fun each(cb: fn(T) -> U) -> Bool =
|
|
361
361
|
True
|
|
362
362
|
|
|
363
363
|
--------------------------------------------------------------------------------
|
|
@@ -383,7 +383,7 @@ each(cb: fn(T) -> U) -> Bool =
|
|
|
383
383
|
function - inline closure literal as a call argument
|
|
384
384
|
================================================================================
|
|
385
385
|
|
|
386
|
-
main() -> Int =
|
|
386
|
+
fun main() -> Int =
|
|
387
387
|
each(|v| v)
|
|
388
388
|
|
|
389
389
|
--------------------------------------------------------------------------------
|
|
@@ -410,7 +410,7 @@ main() -> Int =
|
|
|
410
410
|
function - multi-line closure literal call argument, closing paren on same line as body
|
|
411
411
|
================================================================================
|
|
412
412
|
|
|
413
|
-
main() -> Int =
|
|
413
|
+
fun main() -> Int =
|
|
414
414
|
each(|v|
|
|
415
415
|
v)
|
|
416
416
|
|
tooling/tree-sitter-plum/test/corpus/if.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
if
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
main() =
|
|
5
|
+
fun main() =
|
|
6
6
|
if a < b
|
|
7
7
|
printLn("a is less than b")
|
|
8
8
|
else if a > 9
|
tooling/tree-sitter-plum/test/corpus/literals.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
literals
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
main() =
|
|
5
|
+
fun main() =
|
|
6
6
|
start_year = 2101
|
|
7
7
|
a = +123
|
|
8
8
|
b = -111
|
tooling/tree-sitter-plum/test/corpus/match.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
match
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
main() =
|
|
5
|
+
fun main() =
|
|
6
6
|
match a
|
|
7
7
|
1 =>
|
|
8
8
|
printLn(a)
|
|
@@ -111,7 +111,7 @@ main() =
|
|
|
111
111
|
match - inline case bodies
|
|
112
112
|
================================================================================
|
|
113
113
|
|
|
114
|
-
main() =
|
|
114
|
+
fun main() =
|
|
115
115
|
match a
|
|
116
116
|
1 => printLn(a)
|
|
117
117
|
2 => printLn(b)
|
|
@@ -164,7 +164,7 @@ main() =
|
|
|
164
164
|
match - guard-clause arms, no subject
|
|
165
165
|
================================================================================
|
|
166
166
|
|
|
167
|
-
compare(x: Int, y: Int) -> Int =
|
|
167
|
+
fun compare(x: Int, y: Int) -> Int =
|
|
168
168
|
match
|
|
169
169
|
| x > y =>
|
|
170
170
|
1
|
tooling/tree-sitter-plum/test/corpus/type.txt
CHANGED
|
@@ -10,16 +10,16 @@ type Cat(Stringable) =
|
|
|
10
10
|
name: Str
|
|
11
11
|
age: Int
|
|
12
12
|
|
|
13
|
-
init<Cat>(name: Str) -> Cat =
|
|
13
|
+
fun init<Cat>(name: Str) -> Cat =
|
|
14
14
|
Cat(name: name, age: 0)
|
|
15
15
|
|
|
16
|
-
withName<Cat>(name: Str) -> Cat =
|
|
16
|
+
fun withName<Cat>(name: Str) -> Cat =
|
|
17
17
|
Cat(name: name, age: 0)
|
|
18
18
|
|
|
19
|
-
withAge<Cat>(age: Int) -> Cat =
|
|
19
|
+
fun withAge<Cat>(age: Int) -> Cat =
|
|
20
20
|
Cat(name: "", age: age)
|
|
21
21
|
|
|
22
|
-
toStr<Cat>() -> Str =
|
|
22
|
+
fun toStr<Cat>() -> Str =
|
|
23
23
|
"Cat({self.name}, {self.age})"
|
|
24
24
|
|
|
25
25
|
--------------------------------------------------------------------------------
|
tooling/tree-sitter-plum/test/corpus/while.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
while
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
main() =
|
|
5
|
+
fun main() =
|
|
6
6
|
i = 0
|
|
7
7
|
while i < 10
|
|
8
8
|
i = i + 1
|
tooling/tree-sitter-plum/test/highlight/sample.plum
CHANGED
|
@@ -4,14 +4,14 @@ type Cat(ToStr) =
|
|
|
4
4
|
name: Str
|
|
5
5
|
age: Int
|
|
6
6
|
|
|
7
|
-
withName<Cat>(name: Str) -> Cat =
|
|
7
|
+
fun withName<Cat>(name: Str) -> Cat =
|
|
8
8
|
Cat(name: name, age: self.age)
|
|
9
9
|
|
|
10
|
-
withAge<Cat>(age: Int) -> Cat =
|
|
10
|
+
fun withAge<Cat>(age: Int) -> Cat =
|
|
11
11
|
Cat(name: self.name, age: age)
|
|
12
12
|
|
|
13
|
-
toStr<Cat>() -> Str =
|
|
13
|
+
fun toStr<Cat>() -> Str =
|
|
14
14
|
"Cat({self.name}, {self.age})"
|
|
15
15
|
|
|
16
|
-
main() =
|
|
16
|
+
fun main() =
|
|
17
17
|
printLn("Hello world")
|