aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-18 19:29:14 +0200
committerBad Diode <bd@badd10de.dev>2024-06-18 19:29:14 +0200
commitc9db27abbbfa80a79515e26efaae9012d3275404 (patch)
treeff0dc2888b9e3f6e98cb76bfd07a5e3fafdd82dc /src
parenta0068318895ff8dea6d3c3f0db381fbca83e3f40 (diff)
downloadbdl-c9db27abbbfa80a79515e26efaae9012d3275404.tar.gz
bdl-c9db27abbbfa80a79515e26efaae9012d3275404.zip
Fix some syntax issues with match cases
Diffstat (limited to 'src')
-rw-r--r--src/main.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 1bb5ff6..ccd4877 100644
--- a/src/main.c
+++ b/src/main.c
@@ -579,20 +579,22 @@ parse_keyword(Parser *parser) {
579 if (!node) return; 579 if (!node) return;
580 parse_expr(parser, PREC_LOW); 580 parse_expr(parser, PREC_LOW);
581 node->match_expr = array_pop(parser->nodes); 581 node->match_expr = array_pop(parser->nodes);
582 parse_consume(parser, TOK_ASSIGN,
583 cstr("malformed match statement"));
582 parse_consume(parser, TOK_LCURLY, 584 parse_consume(parser, TOK_LCURLY,
583 cstr("expected block of match cases")); 585 cstr("expected block of match cases"));
584 while (!parse_match(parser, TOK_RCURLY) && !parser->panic) { 586 while (!parse_match(parser, TOK_RCURLY) && !parser->panic) {
585 parse_consume(parser, TOK_CASE,
586 cstr("expected case statement"));
587 Node *tmp = node_alloc(parser, NODE_CASE, parser->previous); 587 Node *tmp = node_alloc(parser, NODE_CASE, parser->previous);
588 if (!tmp) return; 588 if (!tmp) return;
589 // Are we on the default case. 589 // Are we on the default case.
590 if (!parse_match(parser, TOK_ASSIGN)) { 590 if (!parse_match(parser, TOK_ELSE)) {
591 parse_consume(parser, TOK_CASE,
592 cstr("expected case statement"));
591 parse_expr(parser, PREC_LOW); 593 parse_expr(parser, PREC_LOW);
592 tmp->case_value = array_pop(parser->nodes); 594 tmp->case_value = array_pop(parser->nodes);
593 parse_consume(parser, TOK_ASSIGN,
594 cstr("malformed case statement"));
595 } 595 }
596 parse_consume(parser, TOK_ASSIGN,
597 cstr("malformed case statement"));
596 parse_expr(parser, PREC_LOW); 598 parse_expr(parser, PREC_LOW);
597 tmp->case_expr = array_pop(parser->nodes); 599 tmp->case_expr = array_pop(parser->nodes);
598 array_push(node->match_cases, tmp, parser->storage); 600 array_push(node->match_cases, tmp, parser->storage);