diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -584,8 +584,12 @@ parse_keyword(Parser *parser) { | |||
584 | case TOK_IF: { | 584 | case TOK_IF: { |
585 | node = node_alloc(parser, NODE_IF, prev); | 585 | node = node_alloc(parser, NODE_IF, prev); |
586 | if (!node) return; | 586 | if (!node) return; |
587 | parse_consume(parser, TOK_LPAREN, | ||
588 | cstr("expected '(' on if expression")); | ||
587 | parse_expr(parser, PREC_LOW); | 589 | parse_expr(parser, PREC_LOW); |
588 | node->cond_if = array_pop(parser->nodes); | 590 | node->cond_if = array_pop(parser->nodes); |
591 | parse_consume(parser, TOK_RPAREN, | ||
592 | cstr("expected ')' on if expression")); | ||
589 | parse_expr(parser, PREC_LOW); | 593 | parse_expr(parser, PREC_LOW); |
590 | node->cond_expr = array_pop(parser->nodes); | 594 | node->cond_expr = array_pop(parser->nodes); |
591 | if (parse_match(parser, TOK_ELSE)) { | 595 | if (parse_match(parser, TOK_ELSE)) { |
@@ -596,10 +600,12 @@ parse_keyword(Parser *parser) { | |||
596 | case TOK_MATCH: { | 600 | case TOK_MATCH: { |
597 | node = node_alloc(parser, NODE_MATCH, prev); | 601 | node = node_alloc(parser, NODE_MATCH, prev); |
598 | if (!node) return; | 602 | if (!node) return; |
603 | parse_consume(parser, TOK_LPAREN, | ||
604 | cstr("expected '(' on if expression")); | ||
599 | parse_expr(parser, PREC_LOW); | 605 | parse_expr(parser, PREC_LOW); |
600 | node->match_expr = array_pop(parser->nodes); | 606 | node->match_expr = array_pop(parser->nodes); |
601 | parse_consume(parser, TOK_ASSIGN, | 607 | parse_consume(parser, TOK_RPAREN, |
602 | cstr("malformed match statement")); | 608 | cstr("expected ')' on if expression")); |
603 | parse_consume(parser, TOK_LCURLY, | 609 | parse_consume(parser, TOK_LCURLY, |
604 | cstr("expected block of match cases")); | 610 | cstr("expected block of match cases")); |
605 | while (!parse_match(parser, TOK_RCURLY) && !parser->panic) { | 611 | while (!parse_match(parser, TOK_RCURLY) && !parser->panic) { |
@@ -686,10 +692,12 @@ parse_keyword(Parser *parser) { | |||
686 | case TOK_WHILE: { | 692 | case TOK_WHILE: { |
687 | node = node_alloc(parser, NODE_WHILE, prev); | 693 | node = node_alloc(parser, NODE_WHILE, prev); |
688 | if (!node) return; | 694 | if (!node) return; |
695 | parse_consume(parser, TOK_LPAREN, | ||
696 | cstr("expected '(' on while expression")); | ||
689 | parse_expr(parser, PREC_LOW); | 697 | parse_expr(parser, PREC_LOW); |
690 | node->while_cond = array_pop(parser->nodes); | 698 | node->while_cond = array_pop(parser->nodes); |
691 | parse_consume(parser, TOK_ASSIGN, | 699 | parse_consume(parser, TOK_RPAREN, |
692 | cstr("malformed while expression")); | 700 | cstr("expected ')' on while expression")); |
693 | parse_expr(parser, PREC_LOW); | 701 | parse_expr(parser, PREC_LOW); |
694 | node->while_expr = array_pop(parser->nodes); | 702 | node->while_expr = array_pop(parser->nodes); |
695 | } break; | 703 | } break; |