plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
608d862
— Peter John
2026-07-24T12:38:06+05:30
feat(grammar): add subject-less guard-clause match arms
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -238,12 +238,20 @@ module.exports = grammar({
|
|
|
238
238
|
// Match cases
|
|
239
239
|
match: ($) =>
|
|
240
240
|
prec.left(
|
|
241
|
+
choice(
|
|
241
|
-
|
|
242
|
+
seq(
|
|
242
|
-
|
|
243
|
+
"match",
|
|
243
|
-
|
|
244
|
+
commaSep1(field("subject", $.expression)), // remove comma use tuples (a, b) and match against tuples
|
|
244
|
-
|
|
245
|
+
$._indent,
|
|
245
|
-
|
|
246
|
+
repeat(field("case", $.case)),
|
|
246
|
-
|
|
247
|
+
$._dedent,
|
|
248
|
+
),
|
|
249
|
+
seq(
|
|
250
|
+
"match",
|
|
251
|
+
$._indent,
|
|
252
|
+
repeat(field("case", $.guard_case)),
|
|
253
|
+
$._dedent,
|
|
254
|
+
),
|
|
247
255
|
),
|
|
248
256
|
),
|
|
249
257
|
|
|
@@ -263,6 +271,14 @@ module.exports = grammar({
|
|
|
263
271
|
),
|
|
264
272
|
),
|
|
265
273
|
|
|
274
|
+
guard_case: ($) =>
|
|
275
|
+
seq(
|
|
276
|
+
"|",
|
|
277
|
+
field("guard", choice($.expression, "_")),
|
|
278
|
+
"=>",
|
|
279
|
+
field("body", choice($.expression, $.body)),
|
|
280
|
+
),
|
|
281
|
+
|
|
266
282
|
class_pattern: ($) =>
|
|
267
283
|
seq(
|
|
268
284
|
$.type_identifier,
|
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/match.txt
CHANGED
|
@@ -159,3 +159,63 @@ main() =
|
|
|
159
159
|
(expression
|
|
160
160
|
(primary_expression
|
|
161
161
|
(var_identifier))))))))))))
|
|
162
|
+
|
|
163
|
+
================================================================================
|
|
164
|
+
match - guard-clause arms, no subject
|
|
165
|
+
================================================================================
|
|
166
|
+
|
|
167
|
+
compare(x: Int, y: Int) -> Int =
|
|
168
|
+
match
|
|
169
|
+
| x > y =>
|
|
170
|
+
1
|
|
171
|
+
| x == y =>
|
|
172
|
+
0
|
|
173
|
+
| _ =>
|
|
174
|
+
-1
|
|
175
|
+
|
|
176
|
+
--------------------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
(source
|
|
179
|
+
(fn
|
|
180
|
+
(fn_identifier)
|
|
181
|
+
(param
|
|
182
|
+
(var_identifier)
|
|
183
|
+
(type
|
|
184
|
+
(type_identifier)))
|
|
185
|
+
(param
|
|
186
|
+
(var_identifier)
|
|
187
|
+
(type
|
|
188
|
+
(type_identifier)))
|
|
189
|
+
(type
|
|
190
|
+
(type_identifier))
|
|
191
|
+
(body
|
|
192
|
+
(match
|
|
193
|
+
(guard_case
|
|
194
|
+
(expression
|
|
195
|
+
(comparison_operator
|
|
196
|
+
(primary_expression
|
|
197
|
+
(var_identifier))
|
|
198
|
+
(primary_expression
|
|
199
|
+
(var_identifier))))
|
|
200
|
+
(body
|
|
201
|
+
(expression
|
|
202
|
+
(primary_expression
|
|
203
|
+
(integer)))))
|
|
204
|
+
(guard_case
|
|
205
|
+
(expression
|
|
206
|
+
(comparison_operator
|
|
207
|
+
(primary_expression
|
|
208
|
+
(var_identifier))
|
|
209
|
+
(primary_expression
|
|
210
|
+
(var_identifier))))
|
|
211
|
+
(body
|
|
212
|
+
(expression
|
|
213
|
+
(primary_expression
|
|
214
|
+
(integer)))))
|
|
215
|
+
(guard_case
|
|
216
|
+
(body
|
|
217
|
+
(expression
|
|
218
|
+
(primary_expression
|
|
219
|
+
(unary_operator
|
|
220
|
+
(primary_expression
|
|
221
|
+
(integer)))))))))))
|