diff options
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | tests/conditionals.bad | 7 |
2 files changed, 11 insertions, 8 deletions
@@ -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); |
diff --git a/tests/conditionals.bad b/tests/conditionals.bad index 71d49c3..b1c6a89 100644 --- a/tests/conditionals.bad +++ b/tests/conditionals.bad | |||
@@ -19,9 +19,10 @@ if true != false { | |||
19 | } | 19 | } |
20 | 20 | ||
21 | ; Match cases should only apply to literal values, for example `case 1 + 2` | 21 | ; Match cases should only apply to literal values, for example `case 1 + 2` |
22 | ; isn't allowed. | 22 | ; isn't allowed. They should generally convert to a lookup table. |
23 | match 4 * 2 { | 23 | match a = { |
24 | case 8 = "hello" | 24 | case 8 = "hello" |
25 | case 9 = "world" | 25 | case 9 = "world" |
26 | case = "what" | 26 | else = "what" |
27 | } | 27 | } |
28 | |||