@@ -61,7 +61,6 @@ static AstNode *ast_parse_multiply_expr(ParseContext *pc);
61
61
static AstNode *ast_parse_prefix_expr (ParseContext *pc);
62
62
static AstNode *ast_parse_primary_expr (ParseContext *pc);
63
63
static AstNode *ast_parse_if_expr (ParseContext *pc);
64
- static AstNode *ast_parse_labeled_expr (ParseContext *pc);
65
64
static AstNode *ast_parse_block (ParseContext *pc);
66
65
static AstNode *ast_parse_loop_expr (ParseContext *pc);
67
66
static AstNode *ast_parse_for_expr (ParseContext *pc);
@@ -1263,7 +1262,8 @@ static AstNode *ast_parse_prefix_expr(ParseContext *pc) {
1263
1262
// / KEYWORD_continue BreakLabel?
1264
1263
// / KEYWORD_resume Expr
1265
1264
// / KEYWORD_return Expr?
1266
- // / LabeledExpr
1265
+ // / BlockLabel? LoopExpr
1266
+ // / Block
1267
1267
// / CurlySuffixExpr
1268
1268
static AstNode *ast_parse_primary_expr (ParseContext *pc) {
1269
1269
AstNode *asm_expr = ast_parse_asm_expr (pc);
@@ -1325,32 +1325,7 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc) {
1325
1325
return res;
1326
1326
}
1327
1327
1328
- AstNode *labeled_expr = ast_parse_labeled_expr (pc);
1329
- if (labeled_expr != nullptr )
1330
- return labeled_expr;
1331
-
1332
- AstNode *curly_suffix = ast_parse_curly_suffix_expr (pc);
1333
- if (curly_suffix != nullptr )
1334
- return curly_suffix;
1335
-
1336
- return nullptr ;
1337
- }
1338
-
1339
- // IfExpr <- IfPrefix Expr (KEYWORD_else Payload? Expr)?
1340
- static AstNode *ast_parse_if_expr (ParseContext *pc) {
1341
- return ast_parse_if_expr_helper (pc, ast_parse_expr);
1342
- }
1343
-
1344
- // LabeledExpr <- BlockLabel? (Block / LoopExpr)
1345
- static AstNode *ast_parse_labeled_expr (ParseContext *pc) {
1346
1328
Token *label = ast_parse_block_label (pc);
1347
- AstNode *block = ast_parse_block (pc);
1348
- if (block != nullptr ) {
1349
- assert (block->type == NodeTypeBlock);
1350
- block->data .block .name = token_buf (label);
1351
- return block;
1352
- }
1353
-
1354
1329
AstNode *loop = ast_parse_loop_expr (pc);
1355
1330
if (loop != nullptr ) {
1356
1331
switch (loop->type ) {
@@ -1364,13 +1339,31 @@ static AstNode *ast_parse_labeled_expr(ParseContext *pc) {
1364
1339
zig_unreachable ();
1365
1340
}
1366
1341
return loop;
1342
+ } else if (label != nullptr ) {
1343
+ // Restore the tokens that we eaten by ast_parse_block_label.
1344
+ put_back_token (pc);
1345
+ put_back_token (pc);
1367
1346
}
1368
1347
1369
- if (label != nullptr )
1370
- ast_invalid_token_error (pc, peek_token (pc));
1348
+ AstNode *block = ast_parse_block (pc);
1349
+ if (block != nullptr ) {
1350
+ assert (block->type == NodeTypeBlock);
1351
+ block->data .block .name = token_buf (label);
1352
+ return block;
1353
+ }
1354
+
1355
+ AstNode *curly_suffix = ast_parse_curly_suffix_expr (pc);
1356
+ if (curly_suffix != nullptr )
1357
+ return curly_suffix;
1358
+
1371
1359
return nullptr ;
1372
1360
}
1373
1361
1362
+ // IfExpr <- IfPrefix Expr (KEYWORD_else Payload? Expr)?
1363
+ static AstNode *ast_parse_if_expr (ParseContext *pc) {
1364
+ return ast_parse_if_expr_helper (pc, ast_parse_expr);
1365
+ }
1366
+
1374
1367
// Block <- LBRACE Statement* RBRACE
1375
1368
static AstNode *ast_parse_block (ParseContext *pc) {
1376
1369
Token *lbrace = eat_token_if (pc, TokenIdLBrace);
0 commit comments