| ... | ... | @@ -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 | 633 | static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 634 | 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 | 646 | ast_eat_token(pc, token_index, TokenIdLParen); |
| 647 | 647 | |
| 648 | 648 | Token *var_token = &pc->tokens->at(*token_index); |
| 649 | bool have_vars; |
| 649 | 650 | if (var_token->id == TokenIdKeywordVar) { |
| 650 | 651 | node->data.try_expr.var_is_const = false; |
| 651 | 652 | *token_index += 1; |
| 653 | have_vars = true; |
| 652 | 654 | } else if (var_token->id == TokenIdKeywordConst) { |
| 653 | 655 | node->data.try_expr.var_is_const = true; |
| 654 | 656 | *token_index += 1; |
| 657 | have_vars = true; |
| 655 | 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); |
| 660 | | if (star_token->id == TokenIdStar) { |
| 661 | | node->data.try_expr.var_is_ptr = true; |
| 662 | | *token_index += 1; |
| 663 | | } |
| 662 | if (have_vars) { |
| 663 | Token *star_token = &pc->tokens->at(*token_index); |
| 664 | if (star_token->id == TokenIdStar) { |
| 665 | node->data.try_expr.var_is_ptr = true; |
| 666 | *token_index += 1; |
| 667 | } |
| 664 | 668 | |
| 665 | | Token *var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); |
| 666 | | node->data.try_expr.var_symbol = token_buf(var_name_tok); |
| 669 | Token *var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); |
| 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 | 675 | node->data.try_expr.target_node = ast_parse_expression(pc, token_index, true); |
| 671 | 676 | |