aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 04434f82e6..2c25526ec6 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1755,7 +1755,7 @@ static AstNode *ast_parse_else(ParseContext *pc, int *token_index, bool mandator
/*
IfExpression : IfVarExpression | IfBoolExpression
IfBoolExpression : token(If) token(LParen) Expression token(RParen) Expression option(Else)
-IfVarExpression : token(If) token(LParen) (token(Const) | token(Var)) token(Symbol) option(Expression) Token(MaybeAssign) Expression token(RParen) Expression Option(Else)
+IfVarExpression = "if" "(" ("const" | "var") option("*") "Symbol" option(":" TypeExpr) "?=" Expression ")" Expression Option(Else)
*/
static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory) {
Token *if_tok = &pc->tokens->at(*token_index);
@@ -1776,8 +1776,19 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda
node->data.if_var_expr.var_decl.is_const = (token->id == TokenIdKeywordConst);
*token_index += 1;
- Token *name_token = ast_eat_token(pc, token_index, TokenIdSymbol);
- ast_buf_from_token(pc, name_token, &node->data.if_var_expr.var_decl.symbol);
+ Token *star_or_symbol = &pc->tokens->at(*token_index);
+ if (star_or_symbol->id == TokenIdStar) {
+ *token_index += 1;
+ node->data.if_var_expr.var_is_ptr = true;
+ Token *name_token = ast_eat_token(pc, token_index, TokenIdSymbol);
+ ast_buf_from_token(pc, name_token, &node->data.if_var_expr.var_decl.symbol);
+ } else if (star_or_symbol->id == TokenIdSymbol) {
+ *token_index += 1;
+ ast_buf_from_token(pc, star_or_symbol, &node->data.if_var_expr.var_decl.symbol);
+ } else {
+ ast_invalid_token_error(pc, star_or_symbol);
+ }
+
Token *eq_or_colon = &pc->tokens->at(*token_index);
if (eq_or_colon->id == TokenIdMaybeAssign) {