authorgravatar for fncontroloption@noreply.codeberg.orgFnControlOption <fncontroloption@noreply.codeberg.org> 2023-12-29 07:58:19-08:00
committergravatar for fncontroloption@noreply.codeberg.orgFnControlOption <fncontroloption@noreply.codeberg.org> 2023-12-29 07:58:19-08:00
log2091ee2e61676b87c5735ecd503af93f3b8a108d
treece8d6f5ad28ab660d94f9851da1efcc4b31d4209
parent04dad64dbe487e5f22a85c7a0fe3f8c9be8e8b93

std.zig.Parse: Miscellaneous cleanup


1 files changed, 18 insertions(+), 28 deletions(-)

lib/std/zig/Parse.zig+18-28
......@@ -210,7 +210,7 @@ pub fn parseZon(p: *Parse) !void {
210210/// ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl
211211///
212212/// ComptimeDecl <- KEYWORD_comptime Block
213fn parseContainerMembers(p: *Parse) !Members {
213fn parseContainerMembers(p: *Parse) Allocator.Error!Members {
214214 const scratch_top = p.scratch.items.len;
215215 defer p.scratch.shrinkRetainingCapacity(scratch_top);
216216
......@@ -565,12 +565,9 @@ fn findNextStmt(p: *Parse) void {
565565/// TestDecl <- KEYWORD_test (STRINGLITERALSINGLE / IDENTIFIER)? Block
566566fn expectTestDecl(p: *Parse) !Node.Index {
567567 const test_token = p.assertToken(.keyword_test);
568 const name_token = switch (p.token_tags[p.nextToken()]) {
569 .string_literal, .identifier => p.tok_i - 1,
570 else => blk: {
571 p.tok_i -= 1;
572 break :blk null;
573 },
568 const name_token = switch (p.token_tags[p.tok_i]) {
569 .string_literal, .identifier => p.nextToken(),
570 else => null,
574571 };
575572 const block_node = try p.parseBlock();
576573 if (block_node == 0) return p.fail(.expected_block);
......@@ -2051,7 +2048,7 @@ fn parseTypeExpr(p: *Parse) Error!Node.Index {
20512048 .main_token = lbracket,
20522049 .data = .{
20532050 .lhs = len_expr,
2054 .rhs = try p.addExtra(.{
2051 .rhs = try p.addExtra(Node.ArrayTypeSentinel{
20552052 .elem_type = elem_type,
20562053 .sentinel = sentinel,
20572054 }),
......@@ -2090,10 +2087,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index {
20902087 .keyword_asm => return p.expectAsmExpr(),
20912088 .keyword_if => return p.parseIfExpr(),
20922089 .keyword_break => {
2093 p.tok_i += 1;
20942090 return p.addNode(.{
20952091 .tag = .@"break",
2096 .main_token = p.tok_i - 1,
2092 .main_token = p.nextToken(),
20972093 .data = .{
20982094 .lhs = try p.parseBreakLabel(),
20992095 .rhs = try p.parseExpr(),
......@@ -2101,10 +2097,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index {
21012097 });
21022098 },
21032099 .keyword_continue => {
2104 p.tok_i += 1;
21052100 return p.addNode(.{
21062101 .tag = .@"continue",
2107 .main_token = p.tok_i - 1,
2102 .main_token = p.nextToken(),
21082103 .data = .{
21092104 .lhs = try p.parseBreakLabel(),
21102105 .rhs = undefined,
......@@ -2112,10 +2107,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index {
21122107 });
21132108 },
21142109 .keyword_comptime => {
2115 p.tok_i += 1;
21162110 return p.addNode(.{
21172111 .tag = .@"comptime",
2118 .main_token = p.tok_i - 1,
2112 .main_token = p.nextToken(),
21192113 .data = .{
21202114 .lhs = try p.expectExpr(),
21212115 .rhs = undefined,
......@@ -2123,10 +2117,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index {
21232117 });
21242118 },
21252119 .keyword_nosuspend => {
2126 p.tok_i += 1;
21272120 return p.addNode(.{
21282121 .tag = .@"nosuspend",
2129 .main_token = p.tok_i - 1,
2122 .main_token = p.nextToken(),
21302123 .data = .{
21312124 .lhs = try p.expectExpr(),
21322125 .rhs = undefined,
......@@ -2134,10 +2127,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index {
21342127 });
21352128 },
21362129 .keyword_resume => {
2137 p.tok_i += 1;
21382130 return p.addNode(.{
21392131 .tag = .@"resume",
2140 .main_token = p.tok_i - 1,
2132 .main_token = p.nextToken(),
21412133 .data = .{
21422134 .lhs = try p.expectExpr(),
21432135 .rhs = undefined,
......@@ -2145,10 +2137,9 @@ fn parsePrimaryExpr(p: *Parse) !Node.Index {
21452137 });
21462138 },
21472139 .keyword_return => {
2148 p.tok_i += 1;
21492140 return p.addNode(.{
21502141 .tag = .@"return",
2151 .main_token = p.tok_i - 1,
2142 .main_token = p.nextToken(),
21522143 .data = .{
21532144 .lhs = try p.parseExpr(),
21542145 .rhs = undefined,
......@@ -3279,7 +3270,7 @@ fn parseAsmInputItem(p: *Parse) !Node.Index {
32793270
32803271/// BreakLabel <- COLON IDENTIFIER
32813272fn parseBreakLabel(p: *Parse) !TokenIndex {
3282 _ = p.eatToken(.colon) orelse return @as(TokenIndex, 0);
3273 _ = p.eatToken(.colon) orelse return null_node;
32833274 return p.expectToken(.identifier);
32843275}
32853276
......@@ -3397,7 +3388,7 @@ fn expectParamDecl(p: *Parse) !Node.Index {
33973388
33983389/// Payload <- PIPE IDENTIFIER PIPE
33993390fn parsePayload(p: *Parse) !TokenIndex {
3400 _ = p.eatToken(.pipe) orelse return @as(TokenIndex, 0);
3391 _ = p.eatToken(.pipe) orelse return null_node;
34013392 const identifier = try p.expectToken(.identifier);
34023393 _ = try p.expectToken(.pipe);
34033394 return identifier;
......@@ -3405,7 +3396,7 @@ fn parsePayload(p: *Parse) !TokenIndex {
34053396
34063397/// PtrPayload <- PIPE ASTERISK? IDENTIFIER PIPE
34073398fn parsePtrPayload(p: *Parse) !TokenIndex {
3408 _ = p.eatToken(.pipe) orelse return @as(TokenIndex, 0);
3399 _ = p.eatToken(.pipe) orelse return null_node;
34093400 _ = p.eatToken(.asterisk);
34103401 const identifier = try p.expectToken(.identifier);
34113402 _ = try p.expectToken(.pipe);
......@@ -3416,7 +3407,7 @@ fn parsePtrPayload(p: *Parse) !TokenIndex {
34163407///
34173408/// PtrIndexPayload <- PIPE ASTERISK? IDENTIFIER (COMMA IDENTIFIER)? PIPE
34183409fn parsePtrIndexPayload(p: *Parse) !TokenIndex {
3419 _ = p.eatToken(.pipe) orelse return @as(TokenIndex, 0);
3410 _ = p.eatToken(.pipe) orelse return null_node;
34203411 _ = p.eatToken(.asterisk);
34213412 const identifier = try p.expectToken(.identifier);
34223413 if (p.eatToken(.comma) != null) {
......@@ -3925,8 +3916,7 @@ fn parseParamDeclList(p: *Parse) !SmallSpan {
39253916/// ExprList <- (Expr COMMA)* Expr?
39263917fn parseBuiltinCall(p: *Parse) !Node.Index {
39273918 const builtin_token = p.assertToken(.builtin);
3928 if (p.token_tags[p.nextToken()] != .l_paren) {
3929 p.tok_i -= 1;
3919 _ = p.eatToken(.l_paren) orelse {
39303920 try p.warn(.expected_param_list);
39313921 // Pretend this was an identifier so we can continue parsing.
39323922 return p.addNode(.{
......@@ -3937,7 +3927,7 @@ fn parseBuiltinCall(p: *Parse) !Node.Index {
39373927 .rhs = undefined,
39383928 },
39393929 });
3940 }
3930 };
39413931 const scratch_top = p.scratch.items.len;
39423932 defer p.scratch.shrinkRetainingCapacity(scratch_top);
39433933 while (true) {
......@@ -4032,7 +4022,7 @@ fn parseIf(p: *Parse, comptime bodyParseFn: fn (p: *Parse) Error!Node.Index) !No
40324022}
40334023
40344024/// Skips over doc comment tokens. Returns the first one, if any.
4035fn eatDocComments(p: *Parse) !?TokenIndex {
4025fn eatDocComments(p: *Parse) Allocator.Error!?TokenIndex {
40364026 if (p.eatToken(.doc_comment)) |tok| {
40374027 var first_line = tok;
40384028 if (tok > 0 and tokensOnSameLine(p, tok - 1, tok)) {