| ... | @@ -210,7 +210,7 @@ pub fn parseZon(p: *Parse) !void { | ... | @@ -210,7 +210,7 @@ pub fn parseZon(p: *Parse) !void { |
| 210 | /// ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl | 210 | /// ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl |
| 211 | /// | 211 | /// |
| 212 | /// ComptimeDecl <- KEYWORD_comptime Block | 212 | /// ComptimeDecl <- KEYWORD_comptime Block |
| 213 | fn parseContainerMembers(p: *Parse) !Members { | 213 | fn parseContainerMembers(p: *Parse) Allocator.Error!Members { |
| 214 | const scratch_top = p.scratch.items.len; | 214 | const scratch_top = p.scratch.items.len; |
| 215 | defer p.scratch.shrinkRetainingCapacity(scratch_top); | 215 | defer p.scratch.shrinkRetainingCapacity(scratch_top); |
| 216 | | 216 | |
| ... | @@ -565,12 +565,9 @@ fn findNextStmt(p: *Parse) void { | ... | @@ -565,12 +565,9 @@ fn findNextStmt(p: *Parse) void { |
| 565 | /// TestDecl <- KEYWORD_test (STRINGLITERALSINGLE / IDENTIFIER)? Block | 565 | /// TestDecl <- KEYWORD_test (STRINGLITERALSINGLE / IDENTIFIER)? Block |
| 566 | fn expectTestDecl(p: *Parse) !Node.Index { | 566 | fn expectTestDecl(p: *Parse) !Node.Index { |
| 567 | const test_token = p.assertToken(.keyword_test); | 567 | const test_token = p.assertToken(.keyword_test); |
| 568 | const name_token = switch (p.token_tags[p.nextToken()]) { | 568 | const name_token = switch (p.token_tags[p.tok_i]) { |
| 569 | .string_literal, .identifier => p.tok_i - 1, | 569 | .string_literal, .identifier => p.nextToken(), |
| 570 | else => blk: { | 570 | else => null, |
| 571 | p.tok_i -= 1; | | |
| 572 | break :blk null; | | |
| 573 | }, | | |
| 574 | }; | 571 | }; |
| 575 | const block_node = try p.parseBlock(); | 572 | const block_node = try p.parseBlock(); |
| 576 | if (block_node == 0) return p.fail(.expected_block); | 573 | if (block_node == 0) return p.fail(.expected_block); |
| ... | @@ -2051,7 +2048,7 @@ fn parseTypeExpr(p: *Parse) Error!Node.Index { | ... | @@ -2051,7 +2048,7 @@ fn parseTypeExpr(p: *Parse) Error!Node.Index { |
| 2051 | .main_token = lbracket, | 2048 | .main_token = lbracket, |
| 2052 | .data = .{ | 2049 | .data = .{ |
| 2053 | .lhs = len_expr, | 2050 | .lhs = len_expr, |
| 2054 | .rhs = try p.addExtra(.{ | 2051 | .rhs = try p.addExtra(Node.ArrayTypeSentinel{ |
| 2055 | .elem_type = elem_type, | 2052 | .elem_type = elem_type, |
| 2056 | .sentinel = sentinel, | 2053 | .sentinel = sentinel, |
| 2057 | }), | 2054 | }), |
| ... | @@ -2090,10 +2087,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { | ... | @@ -2090,10 +2087,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { |
| 2090 | .keyword_asm => return p.expectAsmExpr(), | 2087 | .keyword_asm => return p.expectAsmExpr(), |
| 2091 | .keyword_if => return p.parseIfExpr(), | 2088 | .keyword_if => return p.parseIfExpr(), |
| 2092 | .keyword_break => { | 2089 | .keyword_break => { |
| 2093 | p.tok_i += 1; | | |
| 2094 | return p.addNode(.{ | 2090 | return p.addNode(.{ |
| 2095 | .tag = .@"break", | 2091 | .tag = .@"break", |
| 2096 | .main_token = p.tok_i - 1, | 2092 | .main_token = p.nextToken(), |
| 2097 | .data = .{ | 2093 | .data = .{ |
| 2098 | .lhs = try p.parseBreakLabel(), | 2094 | .lhs = try p.parseBreakLabel(), |
| 2099 | .rhs = try p.parseExpr(), | 2095 | .rhs = try p.parseExpr(), |
| ... | @@ -2101,10 +2097,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { | ... | @@ -2101,10 +2097,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { |
| 2101 | }); | 2097 | }); |
| 2102 | }, | 2098 | }, |
| 2103 | .keyword_continue => { | 2099 | .keyword_continue => { |
| 2104 | p.tok_i += 1; | | |
| 2105 | return p.addNode(.{ | 2100 | return p.addNode(.{ |
| 2106 | .tag = .@"continue", | 2101 | .tag = .@"continue", |
| 2107 | .main_token = p.tok_i - 1, | 2102 | .main_token = p.nextToken(), |
| 2108 | .data = .{ | 2103 | .data = .{ |
| 2109 | .lhs = try p.parseBreakLabel(), | 2104 | .lhs = try p.parseBreakLabel(), |
| 2110 | .rhs = undefined, | 2105 | .rhs = undefined, |
| ... | @@ -2112,10 +2107,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { | ... | @@ -2112,10 +2107,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { |
| 2112 | }); | 2107 | }); |
| 2113 | }, | 2108 | }, |
| 2114 | .keyword_comptime => { | 2109 | .keyword_comptime => { |
| 2115 | p.tok_i += 1; | | |
| 2116 | return p.addNode(.{ | 2110 | return p.addNode(.{ |
| 2117 | .tag = .@"comptime", | 2111 | .tag = .@"comptime", |
| 2118 | .main_token = p.tok_i - 1, | 2112 | .main_token = p.nextToken(), |
| 2119 | .data = .{ | 2113 | .data = .{ |
| 2120 | .lhs = try p.expectExpr(), | 2114 | .lhs = try p.expectExpr(), |
| 2121 | .rhs = undefined, | 2115 | .rhs = undefined, |
| ... | @@ -2123,10 +2117,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { | ... | @@ -2123,10 +2117,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { |
| 2123 | }); | 2117 | }); |
| 2124 | }, | 2118 | }, |
| 2125 | .keyword_nosuspend => { | 2119 | .keyword_nosuspend => { |
| 2126 | p.tok_i += 1; | | |
| 2127 | return p.addNode(.{ | 2120 | return p.addNode(.{ |
| 2128 | .tag = .@"nosuspend", | 2121 | .tag = .@"nosuspend", |
| 2129 | .main_token = p.tok_i - 1, | 2122 | .main_token = p.nextToken(), |
| 2130 | .data = .{ | 2123 | .data = .{ |
| 2131 | .lhs = try p.expectExpr(), | 2124 | .lhs = try p.expectExpr(), |
| 2132 | .rhs = undefined, | 2125 | .rhs = undefined, |
| ... | @@ -2134,10 +2127,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { | ... | @@ -2134,10 +2127,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { |
| 2134 | }); | 2127 | }); |
| 2135 | }, | 2128 | }, |
| 2136 | .keyword_resume => { | 2129 | .keyword_resume => { |
| 2137 | p.tok_i += 1; | | |
| 2138 | return p.addNode(.{ | 2130 | return p.addNode(.{ |
| 2139 | .tag = .@"resume", | 2131 | .tag = .@"resume", |
| 2140 | .main_token = p.tok_i - 1, | 2132 | .main_token = p.nextToken(), |
| 2141 | .data = .{ | 2133 | .data = .{ |
| 2142 | .lhs = try p.expectExpr(), | 2134 | .lhs = try p.expectExpr(), |
| 2143 | .rhs = undefined, | 2135 | .rhs = undefined, |
| ... | @@ -2145,10 +2137,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { | ... | @@ -2145,10 +2137,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index { |
| 2145 | }); | 2137 | }); |
| 2146 | }, | 2138 | }, |
| 2147 | .keyword_return => { | 2139 | .keyword_return => { |
| 2148 | p.tok_i += 1; | | |
| 2149 | return p.addNode(.{ | 2140 | return p.addNode(.{ |
| 2150 | .tag = .@"return", | 2141 | .tag = .@"return", |
| 2151 | .main_token = p.tok_i - 1, | 2142 | .main_token = p.nextToken(), |
| 2152 | .data = .{ | 2143 | .data = .{ |
| 2153 | .lhs = try p.parseExpr(), | 2144 | .lhs = try p.parseExpr(), |
| 2154 | .rhs = undefined, | 2145 | .rhs = undefined, |
| ... | @@ -3279,7 +3270,7 @@ fn parseAsmInputItem(p: *Parse) !Node.Index { | ... | @@ -3279,7 +3270,7 @@ fn parseAsmInputItem(p: *Parse) !Node.Index { |
| 3279 | | 3270 | |
| 3280 | /// BreakLabel <- COLON IDENTIFIER | 3271 | /// BreakLabel <- COLON IDENTIFIER |
| 3281 | fn parseBreakLabel(p: *Parse) !TokenIndex { | 3272 | fn parseBreakLabel(p: *Parse) !TokenIndex { |
| 3282 | _ = p.eatToken(.colon) orelse return @as(TokenIndex, 0); | 3273 | _ = p.eatToken(.colon) orelse return null_node; |
| 3283 | return p.expectToken(.identifier); | 3274 | return p.expectToken(.identifier); |
| 3284 | } | 3275 | } |
| 3285 | | 3276 | |
| ... | @@ -3397,7 +3388,7 @@ fn expectParamDecl(p: *Parse) !Node.Index { | ... | @@ -3397,7 +3388,7 @@ fn expectParamDecl(p: *Parse) !Node.Index { |
| 3397 | | 3388 | |
| 3398 | /// Payload <- PIPE IDENTIFIER PIPE | 3389 | /// Payload <- PIPE IDENTIFIER PIPE |
| 3399 | fn parsePayload(p: *Parse) !TokenIndex { | 3390 | fn parsePayload(p: *Parse) !TokenIndex { |
| 3400 | _ = p.eatToken(.pipe) orelse return @as(TokenIndex, 0); | 3391 | _ = p.eatToken(.pipe) orelse return null_node; |
| 3401 | const identifier = try p.expectToken(.identifier); | 3392 | const identifier = try p.expectToken(.identifier); |
| 3402 | _ = try p.expectToken(.pipe); | 3393 | _ = try p.expectToken(.pipe); |
| 3403 | return identifier; | 3394 | return identifier; |
| ... | @@ -3405,7 +3396,7 @@ fn parsePayload(p: *Parse) !TokenIndex { | ... | @@ -3405,7 +3396,7 @@ fn parsePayload(p: *Parse) !TokenIndex { |
| 3405 | | 3396 | |
| 3406 | /// PtrPayload <- PIPE ASTERISK? IDENTIFIER PIPE | 3397 | /// PtrPayload <- PIPE ASTERISK? IDENTIFIER PIPE |
| 3407 | fn parsePtrPayload(p: *Parse) !TokenIndex { | 3398 | fn parsePtrPayload(p: *Parse) !TokenIndex { |
| 3408 | _ = p.eatToken(.pipe) orelse return @as(TokenIndex, 0); | 3399 | _ = p.eatToken(.pipe) orelse return null_node; |
| 3409 | _ = p.eatToken(.asterisk); | 3400 | _ = p.eatToken(.asterisk); |
| 3410 | const identifier = try p.expectToken(.identifier); | 3401 | const identifier = try p.expectToken(.identifier); |
| 3411 | _ = try p.expectToken(.pipe); | 3402 | _ = try p.expectToken(.pipe); |
| ... | @@ -3416,7 +3407,7 @@ fn parsePtrPayload(p: *Parse) !TokenIndex { | ... | @@ -3416,7 +3407,7 @@ fn parsePtrPayload(p: *Parse) !TokenIndex { |
| 3416 | /// | 3407 | /// |
| 3417 | /// PtrIndexPayload <- PIPE ASTERISK? IDENTIFIER (COMMA IDENTIFIER)? PIPE | 3408 | /// PtrIndexPayload <- PIPE ASTERISK? IDENTIFIER (COMMA IDENTIFIER)? PIPE |
| 3418 | fn parsePtrIndexPayload(p: *Parse) !TokenIndex { | 3409 | fn parsePtrIndexPayload(p: *Parse) !TokenIndex { |
| 3419 | _ = p.eatToken(.pipe) orelse return @as(TokenIndex, 0); | 3410 | _ = p.eatToken(.pipe) orelse return null_node; |
| 3420 | _ = p.eatToken(.asterisk); | 3411 | _ = p.eatToken(.asterisk); |
| 3421 | const identifier = try p.expectToken(.identifier); | 3412 | const identifier = try p.expectToken(.identifier); |
| 3422 | if (p.eatToken(.comma) != null) { | 3413 | if (p.eatToken(.comma) != null) { |
| ... | @@ -3925,8 +3916,7 @@ fn parseParamDeclList(p: *Parse) !SmallSpan { | ... | @@ -3925,8 +3916,7 @@ fn parseParamDeclList(p: *Parse) !SmallSpan { |
| 3925 | /// ExprList <- (Expr COMMA)* Expr? | 3916 | /// ExprList <- (Expr COMMA)* Expr? |
| 3926 | fn parseBuiltinCall(p: *Parse) !Node.Index { | 3917 | fn parseBuiltinCall(p: *Parse) !Node.Index { |
| 3927 | const builtin_token = p.assertToken(.builtin); | 3918 | const builtin_token = p.assertToken(.builtin); |
| 3928 | if (p.token_tags[p.nextToken()] != .l_paren) { | 3919 | _ = p.eatToken(.l_paren) orelse { |
| 3929 | p.tok_i -= 1; | | |
| 3930 | try p.warn(.expected_param_list); | 3920 | try p.warn(.expected_param_list); |
| 3931 | // Pretend this was an identifier so we can continue parsing. | 3921 | // Pretend this was an identifier so we can continue parsing. |
| 3932 | return p.addNode(.{ | 3922 | return p.addNode(.{ |
| ... | @@ -3937,7 +3927,7 @@ fn parseBuiltinCall(p: *Parse) !Node.Index { | ... | @@ -3937,7 +3927,7 @@ fn parseBuiltinCall(p: *Parse) !Node.Index { |
| 3937 | .rhs = undefined, | 3927 | .rhs = undefined, |
| 3938 | }, | 3928 | }, |
| 3939 | }); | 3929 | }); |
| 3940 | } | 3930 | }; |
| 3941 | const scratch_top = p.scratch.items.len; | 3931 | const scratch_top = p.scratch.items.len; |
| 3942 | defer p.scratch.shrinkRetainingCapacity(scratch_top); | 3932 | defer p.scratch.shrinkRetainingCapacity(scratch_top); |
| 3943 | while (true) { | 3933 | while (true) { |
| ... | @@ -4032,7 +4022,7 @@ fn parseIf(p: *Parse, comptime bodyParseFn: fn (p: *Parse) Error!Node.Index) !No | ... | @@ -4032,7 +4022,7 @@ fn parseIf(p: *Parse, comptime bodyParseFn: fn (p: *Parse) Error!Node.Index) !No |
| 4032 | } | 4022 | } |
| 4033 | | 4023 | |
| 4034 | /// Skips over doc comment tokens. Returns the first one, if any. | 4024 | /// Skips over doc comment tokens. Returns the first one, if any. |
| 4035 | fn eatDocComments(p: *Parse) !?TokenIndex { | 4025 | fn eatDocComments(p: *Parse) Allocator.Error!?TokenIndex { |
| 4036 | if (p.eatToken(.doc_comment)) |tok| { | 4026 | if (p.eatToken(.doc_comment)) |tok| { |
| 4037 | var first_line = tok; | 4027 | var first_line = tok; |
| 4038 | if (tok > 0 and tokensOnSameLine(p, tok - 1, tok)) { | 4028 | if (tok > 0 and tokensOnSameLine(p, tok - 1, tok)) { |