plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
aeaba6f
— Peter John
2026-07-20T13:13:45+05:30
fix(tree-sitter-plum): allow a full expression as a body's trailing statement
- tooling/tree-sitter-plum/grammar.js +1 -1
- 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/corpus/enum.txt +6 -5
- tooling/tree-sitter-plum/test/corpus/for.txt +11 -10
- tooling/tree-sitter-plum/test/corpus/function.txt +105 -7
- tooling/tree-sitter-plum/test/corpus/if.txt +48 -43
- tooling/tree-sitter-plum/test/corpus/literals.txt +3 -2
- tooling/tree-sitter-plum/test/corpus/match.txt +48 -42
- tooling/tree-sitter-plum/test/corpus/type.txt +61 -57
- tooling/tree-sitter-plum/test/corpus/while.txt +13 -12
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -175,7 +175,7 @@ module.exports = grammar({
|
|
|
175
175
|
$.match,
|
|
176
176
|
$.return,
|
|
177
177
|
$.todo,
|
|
178
|
-
$.
|
|
178
|
+
$.expression
|
|
179
179
|
),
|
|
180
180
|
|
|
181
181
|
const: ($) =>
|
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/enum.txt
CHANGED
|
@@ -25,8 +25,9 @@ toStr<Bool>() -> Str =
|
|
|
25
25
|
(return_type
|
|
26
26
|
(type_identifier))
|
|
27
27
|
(body
|
|
28
|
+
(expression
|
|
28
|
-
|
|
29
|
+
(primary_expression
|
|
29
|
-
|
|
30
|
+
(string
|
|
30
|
-
|
|
31
|
+
(string_start)
|
|
31
|
-
|
|
32
|
+
(string_content)
|
|
32
|
-
|
|
33
|
+
(string_end)))))))
|
tooling/tree-sitter-plum/test/corpus/for.txt
CHANGED
|
@@ -23,15 +23,16 @@ main() =
|
|
|
23
23
|
(primary_expression
|
|
24
24
|
(integer))))
|
|
25
25
|
(body
|
|
26
|
+
(expression
|
|
26
|
-
|
|
27
|
+
(primary_expression
|
|
27
|
-
|
|
28
|
+
(fn_call
|
|
28
|
-
|
|
29
|
+
(var_identifier)
|
|
29
|
-
|
|
30
|
+
(fn_argument_list
|
|
30
|
-
|
|
31
|
+
(expression
|
|
31
|
-
|
|
32
|
+
(primary_expression
|
|
32
|
-
|
|
33
|
+
(string
|
|
33
|
-
|
|
34
|
+
(string_start)
|
|
34
|
-
|
|
35
|
+
(string_content)
|
|
35
|
-
|
|
36
|
+
(string_end))))))))
|
|
36
37
|
(break)
|
|
37
38
|
(continue))))))
|
tooling/tree-sitter-plum/test/corpus/function.txt
CHANGED
|
@@ -135,10 +135,108 @@ makeSome(v: Int) -> Option =
|
|
|
135
135
|
(return_type
|
|
136
136
|
(type_identifier))
|
|
137
137
|
(body
|
|
138
|
+
(expression
|
|
138
|
-
|
|
139
|
+
(primary_expression
|
|
139
|
-
|
|
140
|
+
(fn_call
|
|
140
|
-
|
|
141
|
+
(type_identifier)
|
|
141
|
-
|
|
142
|
+
(fn_argument_list
|
|
142
|
-
|
|
143
|
+
(expression
|
|
143
|
-
|
|
144
|
+
(primary_expression
|
|
144
|
-
|
|
145
|
+
(var_identifier))))))))))
|
|
146
|
+
|
|
147
|
+
================================================================================
|
|
148
|
+
function - bare comparison as body's trailing statement
|
|
149
|
+
================================================================================
|
|
150
|
+
|
|
151
|
+
isNone(o: Option) -> Bool =
|
|
152
|
+
o == None
|
|
153
|
+
|
|
154
|
+
--------------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
(source
|
|
157
|
+
(fn
|
|
158
|
+
(fn_identifier)
|
|
159
|
+
(param
|
|
160
|
+
(var_identifier)
|
|
161
|
+
(type
|
|
162
|
+
(type_identifier)))
|
|
163
|
+
(return_type
|
|
164
|
+
(type_identifier))
|
|
165
|
+
(body
|
|
166
|
+
(expression
|
|
167
|
+
(comparison_operator
|
|
168
|
+
(primary_expression
|
|
169
|
+
(var_identifier))
|
|
170
|
+
(primary_expression
|
|
171
|
+
(type_identifier)))))))
|
|
172
|
+
|
|
173
|
+
================================================================================
|
|
174
|
+
function - bare boolean-operator as body's trailing statement
|
|
175
|
+
================================================================================
|
|
176
|
+
|
|
177
|
+
bothTrue(a: Bool, b: Bool) -> Bool =
|
|
178
|
+
a && b
|
|
179
|
+
|
|
180
|
+
--------------------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
(source
|
|
183
|
+
(fn
|
|
184
|
+
(fn_identifier)
|
|
185
|
+
(param
|
|
186
|
+
(var_identifier)
|
|
187
|
+
(type
|
|
188
|
+
(type_identifier)))
|
|
189
|
+
(param
|
|
190
|
+
(var_identifier)
|
|
191
|
+
(type
|
|
192
|
+
(type_identifier)))
|
|
193
|
+
(return_type
|
|
194
|
+
(type_identifier))
|
|
195
|
+
(body
|
|
196
|
+
(expression
|
|
197
|
+
(boolean_operator
|
|
198
|
+
(expression
|
|
199
|
+
(primary_expression
|
|
200
|
+
(var_identifier)))
|
|
201
|
+
(expression
|
|
202
|
+
(primary_expression
|
|
203
|
+
(var_identifier))))))))
|
|
204
|
+
|
|
205
|
+
================================================================================
|
|
206
|
+
function - bare ternary as body's trailing statement
|
|
207
|
+
================================================================================
|
|
208
|
+
|
|
209
|
+
pick(cond: Bool, a: Int, b: Int) -> Int =
|
|
210
|
+
cond ? a : b
|
|
211
|
+
|
|
212
|
+
--------------------------------------------------------------------------------
|
|
213
|
+
|
|
214
|
+
(source
|
|
215
|
+
(fn
|
|
216
|
+
(fn_identifier)
|
|
217
|
+
(param
|
|
218
|
+
(var_identifier)
|
|
219
|
+
(type
|
|
220
|
+
(type_identifier)))
|
|
221
|
+
(param
|
|
222
|
+
(var_identifier)
|
|
223
|
+
(type
|
|
224
|
+
(type_identifier)))
|
|
225
|
+
(param
|
|
226
|
+
(var_identifier)
|
|
227
|
+
(type
|
|
228
|
+
(type_identifier)))
|
|
229
|
+
(return_type
|
|
230
|
+
(type_identifier))
|
|
231
|
+
(body
|
|
232
|
+
(expression
|
|
233
|
+
(ternary_expression
|
|
234
|
+
(expression
|
|
235
|
+
(primary_expression
|
|
236
|
+
(var_identifier)))
|
|
237
|
+
(expression
|
|
238
|
+
(primary_expression
|
|
239
|
+
(var_identifier)))
|
|
240
|
+
(expression
|
|
241
|
+
(primary_expression
|
|
242
|
+
(var_identifier))))))))
|
tooling/tree-sitter-plum/test/corpus/if.txt
CHANGED
|
@@ -29,16 +29,17 @@ main() =
|
|
|
29
29
|
(primary_expression
|
|
30
30
|
(var_identifier))))
|
|
31
31
|
(body
|
|
32
|
+
(expression
|
|
32
|
-
|
|
33
|
+
(primary_expression
|
|
33
|
-
|
|
34
|
+
(fn_call
|
|
34
|
-
|
|
35
|
+
(var_identifier)
|
|
35
|
-
|
|
36
|
+
(fn_argument_list
|
|
36
|
-
|
|
37
|
+
(expression
|
|
37
|
-
|
|
38
|
+
(primary_expression
|
|
38
|
-
|
|
39
|
+
(string
|
|
39
|
-
|
|
40
|
+
(string_start)
|
|
40
|
-
|
|
41
|
+
(string_content)
|
|
41
|
-
|
|
42
|
+
(string_end)))))))))
|
|
42
43
|
(else_if
|
|
43
44
|
(expression
|
|
44
45
|
(comparison_operator
|
|
@@ -47,16 +48,17 @@ main() =
|
|
|
47
48
|
(primary_expression
|
|
48
49
|
(integer))))
|
|
49
50
|
(body
|
|
51
|
+
(expression
|
|
50
|
-
|
|
52
|
+
(primary_expression
|
|
51
|
-
|
|
53
|
+
(fn_call
|
|
52
|
-
|
|
54
|
+
(var_identifier)
|
|
53
|
-
|
|
55
|
+
(fn_argument_list
|
|
54
|
-
|
|
56
|
+
(expression
|
|
55
|
-
|
|
57
|
+
(comparison_operator
|
|
56
|
-
|
|
58
|
+
(primary_expression
|
|
57
|
-
|
|
59
|
+
(var_identifier))
|
|
58
|
-
|
|
60
|
+
(primary_expression
|
|
59
|
-
|
|
61
|
+
(integer))))))))))
|
|
60
62
|
(else_if
|
|
61
63
|
(expression
|
|
62
64
|
(comparison_operator
|
|
@@ -65,16 +67,17 @@ main() =
|
|
|
65
67
|
(primary_expression
|
|
66
68
|
(integer))))
|
|
67
69
|
(body
|
|
70
|
+
(expression
|
|
68
|
-
|
|
71
|
+
(primary_expression
|
|
69
|
-
|
|
72
|
+
(fn_call
|
|
70
|
-
|
|
73
|
+
(var_identifier)
|
|
71
|
-
|
|
74
|
+
(fn_argument_list
|
|
72
|
-
|
|
75
|
+
(expression
|
|
73
|
-
|
|
76
|
+
(comparison_operator
|
|
74
|
-
|
|
77
|
+
(primary_expression
|
|
75
|
-
|
|
78
|
+
(var_identifier))
|
|
76
|
-
|
|
79
|
+
(primary_expression
|
|
77
|
-
|
|
80
|
+
(integer))))))))))
|
|
78
81
|
(else
|
|
79
82
|
(body
|
|
80
83
|
(if
|
|
@@ -85,22 +88,24 @@ main() =
|
|
|
85
88
|
(primary_expression
|
|
86
89
|
(integer))))
|
|
87
90
|
(body
|
|
88
|
-
(primary_expression
|
|
89
|
-
(fn_call
|
|
90
|
-
(var_identifier)
|
|
91
|
-
(fn_argument_list
|
|
92
|
-
|
|
91
|
+
(expression
|
|
93
|
-
(primary_expression
|
|
94
|
-
(var_identifier)))))))
|
|
95
|
-
(else
|
|
96
|
-
(body
|
|
97
92
|
(primary_expression
|
|
98
93
|
(fn_call
|
|
99
94
|
(var_identifier)
|
|
100
95
|
(fn_argument_list
|
|
101
96
|
(expression
|
|
102
97
|
(primary_expression
|
|
98
|
+
(var_identifier))))))))
|
|
99
|
+
(else
|
|
100
|
+
(body
|
|
101
|
+
(expression
|
|
102
|
+
(primary_expression
|
|
103
|
+
(fn_call
|
|
104
|
+
(var_identifier)
|
|
105
|
+
(fn_argument_list
|
|
106
|
+
(expression
|
|
107
|
+
(primary_expression
|
|
103
|
-
|
|
108
|
+
(string
|
|
104
|
-
|
|
109
|
+
(string_start)
|
|
105
|
-
|
|
110
|
+
(string_content)
|
|
106
|
-
|
|
111
|
+
(string_end)))))))))))))))))
|
tooling/tree-sitter-plum/test/corpus/literals.txt
CHANGED
|
@@ -61,8 +61,9 @@ main() =
|
|
|
61
61
|
(expression
|
|
62
62
|
(primary_expression
|
|
63
63
|
(integer))))
|
|
64
|
+
(expression
|
|
64
|
-
|
|
65
|
+
(primary_expression
|
|
65
|
-
|
|
66
|
+
(integer)))
|
|
66
67
|
(assign
|
|
67
68
|
(var_identifier)
|
|
68
69
|
(expression
|
tooling/tree-sitter-plum/test/corpus/match.txt
CHANGED
|
@@ -31,13 +31,14 @@ main() =
|
|
|
31
31
|
(case_pattern
|
|
32
32
|
(integer))
|
|
33
33
|
(body
|
|
34
|
+
(expression
|
|
34
|
-
|
|
35
|
+
(primary_expression
|
|
35
|
-
|
|
36
|
+
(fn_call
|
|
36
|
-
|
|
37
|
+
(var_identifier)
|
|
37
|
-
|
|
38
|
+
(fn_argument_list
|
|
38
|
-
|
|
39
|
+
(expression
|
|
39
|
-
|
|
40
|
+
(primary_expression
|
|
40
|
-
|
|
41
|
+
(var_identifier)))))))))
|
|
41
42
|
(case
|
|
42
43
|
(case_pattern
|
|
43
44
|
(string
|
|
@@ -45,24 +46,26 @@ main() =
|
|
|
45
46
|
(string_content)
|
|
46
47
|
(string_end)))
|
|
47
48
|
(body
|
|
49
|
+
(expression
|
|
48
|
-
|
|
50
|
+
(primary_expression
|
|
49
|
-
|
|
51
|
+
(fn_call
|
|
50
|
-
|
|
52
|
+
(var_identifier)
|
|
51
|
-
|
|
53
|
+
(fn_argument_list
|
|
52
|
-
|
|
54
|
+
(expression
|
|
53
|
-
|
|
55
|
+
(primary_expression
|
|
54
|
-
|
|
56
|
+
(var_identifier)))))))))
|
|
55
57
|
(case
|
|
56
58
|
(case_pattern
|
|
57
59
|
(type_identifier))
|
|
58
60
|
(body
|
|
61
|
+
(expression
|
|
59
|
-
|
|
62
|
+
(primary_expression
|
|
60
|
-
|
|
63
|
+
(fn_call
|
|
61
|
-
|
|
64
|
+
(var_identifier)
|
|
62
|
-
|
|
65
|
+
(fn_argument_list
|
|
63
|
-
|
|
66
|
+
(expression
|
|
64
|
-
|
|
67
|
+
(primary_expression
|
|
65
|
-
|
|
68
|
+
(var_identifier)))))))))
|
|
66
69
|
(case
|
|
67
70
|
(case_pattern
|
|
68
71
|
(class_pattern
|
|
@@ -71,35 +74,38 @@ main() =
|
|
|
71
74
|
(dotted_name
|
|
72
75
|
(var_identifier)))))
|
|
73
76
|
(body
|
|
77
|
+
(expression
|
|
74
|
-
|
|
78
|
+
(primary_expression
|
|
75
|
-
|
|
79
|
+
(fn_call
|
|
76
|
-
|
|
80
|
+
(var_identifier)
|
|
77
|
-
|
|
81
|
+
(fn_argument_list
|
|
78
|
-
|
|
82
|
+
(expression
|
|
79
|
-
|
|
83
|
+
(primary_expression
|
|
80
|
-
|
|
84
|
+
(var_identifier)))))))))
|
|
81
85
|
(case
|
|
82
86
|
(case_pattern
|
|
83
87
|
(dotted_name
|
|
84
88
|
(var_identifier)))
|
|
85
89
|
(body
|
|
90
|
+
(expression
|
|
86
|
-
|
|
91
|
+
(primary_expression
|
|
87
|
-
|
|
92
|
+
(fn_call
|
|
88
|
-
|
|
93
|
+
(var_identifier)
|
|
89
|
-
|
|
94
|
+
(fn_argument_list
|
|
90
|
-
|
|
95
|
+
(expression
|
|
91
|
-
|
|
96
|
+
(primary_expression
|
|
92
|
-
|
|
97
|
+
(var_identifier)))))))))
|
|
93
98
|
(case
|
|
94
99
|
(case_pattern)
|
|
95
100
|
(body
|
|
101
|
+
(expression
|
|
96
|
-
|
|
102
|
+
(primary_expression
|
|
97
|
-
|
|
103
|
+
(fn_call
|
|
98
|
-
|
|
104
|
+
(var_identifier)
|
|
99
|
-
|
|
105
|
+
(fn_argument_list
|
|
100
|
-
|
|
106
|
+
(expression
|
|
101
|
-
|
|
107
|
+
(primary_expression
|
|
102
|
-
|
|
108
|
+
(var_identifier)))))))))))))
|
|
103
109
|
|
|
104
110
|
================================================================================
|
|
105
111
|
match - inline case bodies
|
tooling/tree-sitter-plum/test/corpus/type.txt
CHANGED
|
@@ -57,18 +57,19 @@ toStr<Cat>() -> Str =
|
|
|
57
57
|
(return_type
|
|
58
58
|
(type_identifier))
|
|
59
59
|
(body
|
|
60
|
+
(expression
|
|
60
|
-
|
|
61
|
+
(primary_expression
|
|
61
|
-
|
|
62
|
+
(class_call
|
|
62
|
-
|
|
63
|
+
(type_identifier)
|
|
63
|
-
|
|
64
|
+
(class_argument_list
|
|
64
|
-
|
|
65
|
+
(var_identifier)
|
|
65
|
-
|
|
66
|
+
(expression
|
|
66
|
-
|
|
67
|
+
(primary_expression
|
|
67
|
-
|
|
68
|
+
(var_identifier)))
|
|
68
|
-
|
|
69
|
+
(var_identifier)
|
|
69
|
-
|
|
70
|
+
(expression
|
|
70
|
-
|
|
71
|
+
(primary_expression
|
|
71
|
-
|
|
72
|
+
(integer)))))))))
|
|
72
73
|
(fn
|
|
73
74
|
(fn_identifier)
|
|
74
75
|
(type
|
|
@@ -80,18 +81,19 @@ toStr<Cat>() -> Str =
|
|
|
80
81
|
(return_type
|
|
81
82
|
(type_identifier))
|
|
82
83
|
(body
|
|
84
|
+
(expression
|
|
83
|
-
|
|
85
|
+
(primary_expression
|
|
84
|
-
|
|
86
|
+
(class_call
|
|
85
|
-
|
|
87
|
+
(type_identifier)
|
|
86
|
-
|
|
88
|
+
(class_argument_list
|
|
87
|
-
|
|
89
|
+
(var_identifier)
|
|
88
|
-
|
|
90
|
+
(expression
|
|
89
|
-
|
|
91
|
+
(primary_expression
|
|
90
|
-
|
|
92
|
+
(var_identifier)))
|
|
91
|
-
|
|
93
|
+
(var_identifier)
|
|
92
|
-
|
|
94
|
+
(expression
|
|
93
|
-
|
|
95
|
+
(primary_expression
|
|
94
|
-
|
|
96
|
+
(integer)))))))))
|
|
95
97
|
(fn
|
|
96
98
|
(fn_identifier)
|
|
97
99
|
(type
|
|
@@ -103,20 +105,21 @@ toStr<Cat>() -> Str =
|
|
|
103
105
|
(return_type
|
|
104
106
|
(type_identifier))
|
|
105
107
|
(body
|
|
108
|
+
(expression
|
|
106
|
-
|
|
109
|
+
(primary_expression
|
|
107
|
-
|
|
110
|
+
(class_call
|
|
108
|
-
|
|
111
|
+
(type_identifier)
|
|
109
|
-
|
|
112
|
+
(class_argument_list
|
|
110
|
-
|
|
113
|
+
(var_identifier)
|
|
111
|
-
|
|
114
|
+
(expression
|
|
112
|
-
|
|
115
|
+
(primary_expression
|
|
113
|
-
|
|
116
|
+
(string
|
|
114
|
-
|
|
117
|
+
(string_start)
|
|
115
|
-
|
|
118
|
+
(string_end))))
|
|
116
|
-
|
|
119
|
+
(var_identifier)
|
|
117
|
-
|
|
120
|
+
(expression
|
|
118
|
-
|
|
121
|
+
(primary_expression
|
|
119
|
-
|
|
122
|
+
(var_identifier)))))))))
|
|
120
123
|
(fn
|
|
121
124
|
(fn_identifier)
|
|
122
125
|
(type
|
|
@@ -124,22 +127,23 @@ toStr<Cat>() -> Str =
|
|
|
124
127
|
(return_type
|
|
125
128
|
(type_identifier))
|
|
126
129
|
(body
|
|
130
|
+
(expression
|
|
127
|
-
|
|
131
|
+
(primary_expression
|
|
128
|
-
|
|
132
|
+
(string
|
|
129
|
-
|
|
133
|
+
(string_start)
|
|
130
|
-
|
|
134
|
+
(string_content)
|
|
131
|
-
|
|
135
|
+
(interpolation
|
|
132
|
-
|
|
136
|
+
(primary_expression
|
|
133
|
-
|
|
137
|
+
(attribute
|
|
134
|
-
|
|
138
|
+
(primary_expression
|
|
135
|
-
|
|
139
|
+
(self))
|
|
136
|
-
|
|
140
|
+
(fn_identifier))))
|
|
137
|
-
|
|
141
|
+
(string_content)
|
|
138
|
-
|
|
142
|
+
(interpolation
|
|
139
|
-
|
|
143
|
+
(primary_expression
|
|
140
|
-
|
|
144
|
+
(attribute
|
|
141
|
-
|
|
145
|
+
(primary_expression
|
|
142
|
-
|
|
146
|
+
(self))
|
|
143
|
-
|
|
147
|
+
(fn_identifier))))
|
|
144
|
-
|
|
148
|
+
(string_content)
|
|
145
|
-
|
|
149
|
+
(string_end)))))))
|
tooling/tree-sitter-plum/test/corpus/while.txt
CHANGED
|
@@ -36,15 +36,16 @@ main() =
|
|
|
36
36
|
(var_identifier))
|
|
37
37
|
(primary_expression
|
|
38
38
|
(integer))))))
|
|
39
|
+
(expression
|
|
39
|
-
|
|
40
|
+
(primary_expression
|
|
40
|
-
|
|
41
|
+
(fn_call
|
|
41
|
-
|
|
42
|
+
(var_identifier)
|
|
42
|
-
|
|
43
|
+
(fn_argument_list
|
|
43
|
-
|
|
44
|
+
(expression
|
|
44
|
-
|
|
45
|
+
(primary_expression
|
|
45
|
-
|
|
46
|
+
(string
|
|
46
|
-
|
|
47
|
+
(string_start)
|
|
47
|
-
|
|
48
|
+
(interpolation
|
|
48
|
-
|
|
49
|
+
(primary_expression
|
|
49
|
-
|
|
50
|
+
(var_identifier)))
|
|
50
|
-
|
|
51
|
+
(string_end)))))))))))))
|