| ... | @@ -628,7 +628,7 @@ static AstNode *ast_parse_comptime_expr(ParseContext *pc, size_t *token_index, b | ... | @@ -628,7 +628,7 @@ static AstNode *ast_parse_comptime_expr(ParseContext *pc, size_t *token_index, b |
| 628 | } | 628 | } |
| 629 | | 629 | |
| 630 | /* | 630 | /* |
| 631 | TryExpression = "try" "(" ("const" | "var") option("*") Symbol "=" Expression ")" Expression option("else" option("|" Symbol "|") Expression) | 631 | TryExpression = "try" "(" option(("const" | "var") option("*") Symbol "=") Expression ")" Expression option("else" option("|" Symbol "|") Expression) |
| 632 | */ | 632 | */ |
| 633 | static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool mandatory) { | 633 | static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 634 | Token *try_token = &pc->tokens->at(*token_index); | 634 | Token *try_token = &pc->tokens->at(*token_index); |
| ... | @@ -646,26 +646,31 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m | ... | @@ -646,26 +646,31 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m |
| 646 | ast_eat_token(pc, token_index, TokenIdLParen); | 646 | ast_eat_token(pc, token_index, TokenIdLParen); |
| 647 | | 647 | |
| 648 | Token *var_token = &pc->tokens->at(*token_index); | 648 | Token *var_token = &pc->tokens->at(*token_index); |
| | 649 | bool have_vars; |
| 649 | if (var_token->id == TokenIdKeywordVar) { | 650 | if (var_token->id == TokenIdKeywordVar) { |
| 650 | node->data.try_expr.var_is_const = false; | 651 | node->data.try_expr.var_is_const = false; |
| 651 | *token_index += 1; | 652 | *token_index += 1; |
| | 653 | have_vars = true; |
| 652 | } else if (var_token->id == TokenIdKeywordConst) { | 654 | } else if (var_token->id == TokenIdKeywordConst) { |
| 653 | node->data.try_expr.var_is_const = true; | 655 | node->data.try_expr.var_is_const = true; |
| 654 | *token_index += 1; | 656 | *token_index += 1; |
| | 657 | have_vars = true; |
| 655 | } else { | 658 | } else { |
| 656 | ast_invalid_token_error(pc, var_token); | 659 | have_vars = false; |
| 657 | } | 660 | } |
| 658 | | 661 | |
| 659 | Token *star_token = &pc->tokens->at(*token_index); | 662 | if (have_vars) { |
| 660 | if (star_token->id == TokenIdStar) { | 663 | Token *star_token = &pc->tokens->at(*token_index); |
| 661 | node->data.try_expr.var_is_ptr = true; | 664 | if (star_token->id == TokenIdStar) { |
| 662 | *token_index += 1; | 665 | node->data.try_expr.var_is_ptr = true; |
| 663 | } | 666 | *token_index += 1; |
| | 667 | } |
| 664 | | 668 | |
| 665 | Token *var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | 669 | Token *var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); |
| 666 | node->data.try_expr.var_symbol = token_buf(var_name_tok); | 670 | node->data.try_expr.var_symbol = token_buf(var_name_tok); |
| 667 | | 671 | |
| 668 | ast_eat_token(pc, token_index, TokenIdEq); | 672 | ast_eat_token(pc, token_index, TokenIdEq); |
| | 673 | } |
| 669 | | 674 | |
| 670 | node->data.try_expr.target_node = ast_parse_expression(pc, token_index, true); | 675 | node->data.try_expr.target_node = ast_parse_expression(pc, token_index, true); |
| 671 | | 676 | |