breaking syntax change: orelse keyword instead of ?? (#1096)
use the `zig-fmt-optional-default` branch to have zig fmt automatically do the changes. closes #1023
This commit is contained in:
@@ -1151,9 +1151,8 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,
|
||||
} else if (token->id == TokenIdQuestion) {
|
||||
*token_index += 1;
|
||||
|
||||
AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, first_token);
|
||||
node->data.prefix_op_expr.prefix_op = PrefixOpUnwrapOptional;
|
||||
node->data.prefix_op_expr.primary_expr = primary_expr;
|
||||
AstNode *node = ast_create_node(pc, NodeTypeUnwrapOptional, first_token);
|
||||
node->data.unwrap_optional.expr = primary_expr;
|
||||
|
||||
primary_expr = node;
|
||||
} else {
|
||||
@@ -1173,7 +1172,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {
|
||||
case TokenIdMinusPercent: return PrefixOpNegationWrap;
|
||||
case TokenIdTilde: return PrefixOpBinNot;
|
||||
case TokenIdQuestion: return PrefixOpOptional;
|
||||
case TokenIdDoubleQuestion: return PrefixOpUnwrapOptional;
|
||||
case TokenIdAmpersand: return PrefixOpAddrOf;
|
||||
default: return PrefixOpInvalid;
|
||||
}
|
||||
@@ -2312,7 +2310,7 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma
|
||||
|
||||
/*
|
||||
UnwrapExpression : BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
|
||||
UnwrapOptional : "??" BoolOrExpression
|
||||
UnwrapOptional = "orelse" Expression
|
||||
UnwrapError = "catch" option("|" Symbol "|") Expression
|
||||
*/
|
||||
static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
|
||||
@@ -2322,7 +2320,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo
|
||||
|
||||
Token *token = &pc->tokens->at(*token_index);
|
||||
|
||||
if (token->id == TokenIdDoubleQuestion) {
|
||||
if (token->id == TokenIdKeywordOrElse) {
|
||||
*token_index += 1;
|
||||
|
||||
AstNode *rhs = ast_parse_expression(pc, token_index, true);
|
||||
@@ -3035,6 +3033,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
|
||||
case NodeTypePtrDeref:
|
||||
visit_field(&node->data.ptr_deref_expr.target, visit, context);
|
||||
break;
|
||||
case NodeTypeUnwrapOptional:
|
||||
visit_field(&node->data.unwrap_optional.expr, visit, context);
|
||||
break;
|
||||
case NodeTypeUse:
|
||||
visit_field(&node->data.use.expr, visit, context);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user