| ... | @@ -1245,7 +1245,7 @@ fn parseLabeledStatement(p: *Parse) !Node.Index { | ... | @@ -1245,7 +1245,7 @@ fn parseLabeledStatement(p: *Parse) !Node.Index { |
| 1245 | const loop_stmt = try p.parseLoopStatement(); | 1245 | const loop_stmt = try p.parseLoopStatement(); |
| 1246 | if (loop_stmt != 0) return loop_stmt; | 1246 | if (loop_stmt != 0) return loop_stmt; |
| 1247 | | 1247 | |
| 1248 | const switch_expr = try p.parseSwitchExpr(); | 1248 | const switch_expr = try p.parseSwitchExpr(label_token != 0); |
| 1249 | if (switch_expr != 0) return switch_expr; | 1249 | if (switch_expr != 0) return switch_expr; |
| 1250 | | 1250 | |
| 1251 | if (label_token != 0) { | 1251 | if (label_token != 0) { |
| ... | @@ -2699,7 +2699,7 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index { | ... | @@ -2699,7 +2699,7 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index { |
| 2699 | .builtin => return p.parseBuiltinCall(), | 2699 | .builtin => return p.parseBuiltinCall(), |
| 2700 | .keyword_fn => return p.parseFnProto(), | 2700 | .keyword_fn => return p.parseFnProto(), |
| 2701 | .keyword_if => return p.parseIf(expectTypeExpr), | 2701 | .keyword_if => return p.parseIf(expectTypeExpr), |
| 2702 | .keyword_switch => return p.expectSwitchExpr(), | 2702 | .keyword_switch => return p.expectSwitchExpr(false), |
| 2703 | | 2703 | |
| 2704 | .keyword_extern, | 2704 | .keyword_extern, |
| 2705 | .keyword_packed, | 2705 | .keyword_packed, |
| ... | @@ -2756,7 +2756,7 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index { | ... | @@ -2756,7 +2756,7 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index { |
| 2756 | }, | 2756 | }, |
| 2757 | .keyword_switch => { | 2757 | .keyword_switch => { |
| 2758 | p.tok_i += 2; | 2758 | p.tok_i += 2; |
| 2759 | return p.expectSwitchExpr(); | 2759 | return p.expectSwitchExpr(true); |
| 2760 | }, | 2760 | }, |
| 2761 | .l_brace => { | 2761 | .l_brace => { |
| 2762 | p.tok_i += 2; | 2762 | p.tok_i += 2; |
| ... | @@ -3034,17 +3034,17 @@ fn parseWhileTypeExpr(p: *Parse) !Node.Index { | ... | @@ -3034,17 +3034,17 @@ fn parseWhileTypeExpr(p: *Parse) !Node.Index { |
| 3034 | } | 3034 | } |
| 3035 | | 3035 | |
| 3036 | /// SwitchExpr <- KEYWORD_switch LPAREN Expr RPAREN LBRACE SwitchProngList RBRACE | 3036 | /// SwitchExpr <- KEYWORD_switch LPAREN Expr RPAREN LBRACE SwitchProngList RBRACE |
| 3037 | fn parseSwitchExpr(p: *Parse) !Node.Index { | 3037 | fn parseSwitchExpr(p: *Parse, is_labeled: bool) !Node.Index { |
| 3038 | const switch_token = p.eatToken(.keyword_switch) orelse return null_node; | 3038 | const switch_token = p.eatToken(.keyword_switch) orelse return null_node; |
| 3039 | return p.expectSwitchSuffix(switch_token); | 3039 | return p.expectSwitchSuffix(if (is_labeled) switch_token - 2 else switch_token); |
| 3040 | } | 3040 | } |
| 3041 | | 3041 | |
| 3042 | fn expectSwitchExpr(p: *Parse) !Node.Index { | 3042 | fn expectSwitchExpr(p: *Parse, is_labeled: bool) !Node.Index { |
| 3043 | const switch_token = p.assertToken(.keyword_switch); | 3043 | const switch_token = p.assertToken(.keyword_switch); |
| 3044 | return p.expectSwitchSuffix(switch_token); | 3044 | return p.expectSwitchSuffix(if (is_labeled) switch_token - 2 else switch_token); |
| 3045 | } | 3045 | } |
| 3046 | | 3046 | |
| 3047 | fn expectSwitchSuffix(p: *Parse, switch_token: TokenIndex) !Node.Index { | 3047 | fn expectSwitchSuffix(p: *Parse, main_token: TokenIndex) !Node.Index { |
| 3048 | _ = try p.expectToken(.l_paren); | 3048 | _ = try p.expectToken(.l_paren); |
| 3049 | const expr_node = try p.expectExpr(); | 3049 | const expr_node = try p.expectExpr(); |
| 3050 | _ = try p.expectToken(.r_paren); | 3050 | _ = try p.expectToken(.r_paren); |
| ... | @@ -3055,7 +3055,7 @@ fn expectSwitchSuffix(p: *Parse, switch_token: TokenIndex) !Node.Index { | ... | @@ -3055,7 +3055,7 @@ fn expectSwitchSuffix(p: *Parse, switch_token: TokenIndex) !Node.Index { |
| 3055 | | 3055 | |
| 3056 | return p.addNode(.{ | 3056 | return p.addNode(.{ |
| 3057 | .tag = if (trailing_comma) .switch_comma else .@"switch", | 3057 | .tag = if (trailing_comma) .switch_comma else .@"switch", |
| 3058 | .main_token = switch_token, | 3058 | .main_token = main_token, |
| 3059 | .data = .{ | 3059 | .data = .{ |
| 3060 | .lhs = expr_node, | 3060 | .lhs = expr_node, |
| 3061 | .rhs = try p.addExtra(Node.SubRange{ | 3061 | .rhs = try p.addExtra(Node.SubRange{ |