aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 15:09:44 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 15:09:44 -0400
commit448e805293989b06e07878a4a87fdd378f7c6e02 (patch)
treed0364efbeaad0eeb863593c26745d64deaf4a212 /src
parent4043a99e0df9fab6791c485721c0046971754175 (diff)
Re-implement multiple patterns for `when` blocks
Diffstat (limited to 'src')
-rw-r--r--src/parse.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/parse.c b/src/parse.c
index a11fc971..0f76243d 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -996,11 +996,17 @@ PARSER(parse_when) {
spaces(&pos);
ast_t *pattern = expect(ctx, start, &pos, parse_expr, "I expected a pattern to match here");
spaces(&pos);
- tmp = pos;
- if (!match(&tmp, ":"))
- parser_err(ctx, tmp, tmp, "I expected a colon ':' after this clause");
+ when_clause_t *new_clauses = new(when_clause_t, .pattern=pattern, .next=clauses);
+ while (match(&pos, ",")) {
+ pattern = expect(ctx, start, &pos, parse_expr, "I expected a pattern to match here");
+ new_clauses = new(when_clause_t, .pattern=pattern, .next=new_clauses);
+ spaces(&pos);
+ }
ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'when' clause");
- clauses = new(when_clause_t, .pattern=pattern, .body=body, .next=clauses);
+ for (when_clause_t *c = new_clauses; c && c != clauses; c = c->next) {
+ c->body = body;
+ }
+ clauses = new_clauses;
tmp = pos;
whitespace(&tmp);
}