authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-26 15:40:29-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-26 15:43:36-04:00
log28071ac637a73fea7db89cf9c041ca349554a437
tree61c4e48014809508763864f0805d0c1091f84f96
parentc82acdbb9ed65f3443544fe2be9bd12c9a7686d9
signaturelock-open Commit is signed but in an unrecognized format.

self-hosted translate-c emits a hello world AST

Also breaking std lib API change: the return value of std.zig.parse returns `*ast.Tree` rather than `ast.Tree`. See #1964

9 files changed, 230 insertions(+), 181 deletions(-)

src-self-hosted/compilation.zig+4-6
......@@ -569,9 +569,9 @@ pub const Compilation = struct {
569569 'i', 'u' => blk: {
570570 for (name[1..]) |byte|
571571 switch (byte) {
572 '0'...'9' => {},
573 else => break :blk,
574 };
572 '0'...'9' => {},
573 else => break :blk,
574 };
575575 const is_signed = name[0] == 'i';
576576 const bit_count = std.fmt.parseUnsigned(u32, name[1..], 10) catch |err| switch (err) {
577577 error.Overflow => return error.Overflow,
......@@ -841,11 +841,9 @@ pub const Compilation = struct {
841841 };
842842 errdefer self.gpa().free(source_code);
843843
844 const tree = try self.gpa().create(ast.Tree);
845 tree.* = try std.zig.parse(self.gpa(), source_code);
844 const tree = try std.zig.parse(self.gpa(), source_code);
846845 errdefer {
847846 tree.deinit();
848 self.gpa().destroy(tree);
849847 }
850848
851849 break :blk try Scope.AstTree.create(self, tree, root_scope);
src-self-hosted/main.zig+8-8
......@@ -625,7 +625,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
625625 const source_code = try stdin.stream.readAllAlloc(allocator, max_src_size);
626626 defer allocator.free(source_code);
627627
628 var tree = std.zig.parse(allocator, source_code) catch |err| {
628 const tree = std.zig.parse(allocator, source_code) catch |err| {
629629 try stderr.print("error parsing stdin: {}\n", err);
630630 os.exit(1);
631631 };
......@@ -633,7 +633,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
633633
634634 var error_it = tree.errors.iterator(0);
635635 while (error_it.next()) |parse_error| {
636 const msg = try errmsg.Msg.createFromParseError(allocator, parse_error, &tree, "<stdin>");
636 const msg = try errmsg.Msg.createFromParseError(allocator, parse_error, tree, "<stdin>");
637637 defer msg.destroy();
638638
639639 try msg.printToFile(stderr_file, color);
......@@ -642,12 +642,12 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
642642 os.exit(1);
643643 }
644644 if (flags.present("check")) {
645 const anything_changed = try std.zig.render(allocator, io.null_out_stream, &tree);
645 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
646646 const code = if (anything_changed) u8(1) else u8(0);
647647 os.exit(code);
648648 }
649649
650 _ = try std.zig.render(allocator, stdout, &tree);
650 _ = try std.zig.render(allocator, stdout, tree);
651651 return;
652652 }
653653
......@@ -768,7 +768,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
768768 };
769769 defer fmt.loop.allocator.free(source_code);
770770
771 var tree = std.zig.parse(fmt.loop.allocator, source_code) catch |err| {
771 const tree = std.zig.parse(fmt.loop.allocator, source_code) catch |err| {
772772 try stderr.print("error parsing file '{}': {}\n", file_path, err);
773773 fmt.any_error = true;
774774 return;
......@@ -777,7 +777,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
777777
778778 var error_it = tree.errors.iterator(0);
779779 while (error_it.next()) |parse_error| {
780 const msg = try errmsg.Msg.createFromParseError(fmt.loop.allocator, parse_error, &tree, file_path);
780 const msg = try errmsg.Msg.createFromParseError(fmt.loop.allocator, parse_error, tree, file_path);
781781 defer fmt.loop.allocator.destroy(msg);
782782
783783 try msg.printToFile(stderr_file, fmt.color);
......@@ -788,7 +788,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
788788 }
789789
790790 if (check_mode) {
791 const anything_changed = try std.zig.render(fmt.loop.allocator, io.null_out_stream, &tree);
791 const anything_changed = try std.zig.render(fmt.loop.allocator, io.null_out_stream, tree);
792792 if (anything_changed) {
793793 try stderr.print("{}\n", file_path);
794794 fmt.any_error = true;
......@@ -798,7 +798,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
798798 const baf = try io.BufferedAtomicFile.create(fmt.loop.allocator, file_path);
799799 defer baf.destroy();
800800
801 const anything_changed = try std.zig.render(fmt.loop.allocator, baf.stream(), &tree);
801 const anything_changed = try std.zig.render(fmt.loop.allocator, baf.stream(), tree);
802802 if (anything_changed) {
803803 try stderr.print("{}\n", file_path);
804804 try baf.finish();
src-self-hosted/scope.zig-1
......@@ -163,7 +163,6 @@ pub const Scope = struct {
163163 pub fn destroy(self: *AstTree, comp: *Compilation) void {
164164 comp.gpa().free(self.tree.source);
165165 self.tree.deinit();
166 comp.gpa().destroy(self.tree);
167166 comp.gpa().destroy(self);
168167 }
169168
src-self-hosted/stage1.zig+1-2
......@@ -85,11 +85,10 @@ export fn stage2_translate_c(
8585 resources_path: [*]const u8,
8686) Error {
8787 var errors: []translate_c.ClangErrMsg = undefined;
88 out_ast.* = translate_c.translate(args_begin, args_end, switch (mode) {
88 out_ast.* = translate_c.translate(std.heap.c_allocator, args_begin, args_end, switch (mode) {
8989 .import => translate_c.Mode.import,
9090 .translate => translate_c.Mode.translate,
9191 }, &errors, resources_path) catch |err| switch (err) {
92 error.Unimplemented => return Error.Unimplemented,
9392 error.SemanticAnalyzeFail => {
9493 out_errors_ptr.* = errors.ptr;
9594 out_errors_len.* = errors.len;
src-self-hosted/translate_c.zig+44-1
......@@ -3,6 +3,7 @@
33
44const std = @import("std");
55const ast = std.zig.ast;
6const Token = std.zig.Token;
67use @import("clang.zig");
78
89pub const Mode = enum {
......@@ -13,6 +14,7 @@ pub const Mode = enum {
1314pub const ClangErrMsg = Stage2ErrorMsg;
1415
1516pub fn translate(
17 backing_allocator: *std.mem.Allocator,
1618 args_begin: [*]?[*]const u8,
1719 args_end: [*]?[*]const u8,
1820 mode: Mode,
......@@ -29,8 +31,49 @@ pub fn translate(
2931 if (errors.len == 0) return error.OutOfMemory;
3032 return error.SemanticAnalyzeFail;
3133 };
34 defer ZigClangASTUnit_delete(ast_unit);
3235
33 return error.Unimplemented;
36 var tree_arena = std.heap.ArenaAllocator.init(backing_allocator);
37 errdefer tree_arena.deinit();
38 const arena = &tree_arena.allocator;
39
40 const root_node = try arena.create(ast.Node.Root);
41 root_node.* = ast.Node.Root{
42 .base = ast.Node{ .id = ast.Node.Id.Root },
43 .decls = ast.Node.Root.DeclList.init(arena),
44 .doc_comments = null,
45 // initialized with the eof token at the end
46 .eof_token = undefined,
47 };
48
49 const tree = try arena.create(ast.Tree);
50 tree.* = ast.Tree{
51 .source = undefined, // need to use Buffer.toOwnedSlice later
52 .root_node = root_node,
53 .arena_allocator = tree_arena,
54 .tokens = ast.Tree.TokenList.init(arena),
55 .errors = ast.Tree.ErrorList.init(arena),
56 };
57
58 var source_buffer = try std.Buffer.initSize(arena, 0);
59
60 try appendToken(tree, &source_buffer, "// TODO: implement more than just an empty source file", .LineComment);
61
62 try appendToken(tree, &source_buffer, "", .Eof);
63 tree.source = source_buffer.toOwnedSlice();
64 return tree;
65}
66
67fn appendToken(tree: *ast.Tree, source_buffer: *std.Buffer, src_text: []const u8, token_id: Token.Id) !void {
68 const start_index = source_buffer.len();
69 try source_buffer.append(src_text);
70 const end_index = source_buffer.len();
71 const new_token = try tree.tokens.addOne();
72 new_token.* = Token{
73 .id = token_id,
74 .start = start_index,
75 .end = end_index,
76 };
3477}
3578
3679pub fn freeErrors(errors: []ClangErrMsg) void {
std/special/fmt_runner.zig+16-11
......@@ -71,7 +71,7 @@ pub fn main() !void {
7171 const source_code = try stdin.stream.readAllAlloc(allocator, self_hosted_main.max_src_size);
7272 defer allocator.free(source_code);
7373
74 var tree = std.zig.parse(allocator, source_code) catch |err| {
74 const tree = std.zig.parse(allocator, source_code) catch |err| {
7575 try stderr.print("error parsing stdin: {}\n", err);
7676 os.exit(1);
7777 };
......@@ -79,18 +79,18 @@ pub fn main() !void {
7979
8080 var error_it = tree.errors.iterator(0);
8181 while (error_it.next()) |parse_error| {
82 try printErrMsgToFile(allocator, parse_error, &tree, "<stdin>", stderr_file, color);
82 try printErrMsgToFile(allocator, parse_error, tree, "<stdin>", stderr_file, color);
8383 }
8484 if (tree.errors.len != 0) {
8585 os.exit(1);
8686 }
8787 if (flags.present("check")) {
88 const anything_changed = try std.zig.render(allocator, io.null_out_stream, &tree);
88 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
8989 const code = if (anything_changed) u8(1) else u8(0);
9090 os.exit(code);
9191 }
9292
93 _ = try std.zig.render(allocator, stdout, &tree);
93 _ = try std.zig.render(allocator, stdout, tree);
9494 return;
9595 }
9696
......@@ -166,7 +166,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
166166 };
167167 defer fmt.allocator.free(source_code);
168168
169 var tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
169 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
170170 try stderr.print("error parsing file '{}': {}\n", file_path, err);
171171 fmt.any_error = true;
172172 return;
......@@ -175,7 +175,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
175175
176176 var error_it = tree.errors.iterator(0);
177177 while (error_it.next()) |parse_error| {
178 try printErrMsgToFile(fmt.allocator, parse_error, &tree, file_path, stderr_file, fmt.color);
178 try printErrMsgToFile(fmt.allocator, parse_error, tree, file_path, stderr_file, fmt.color);
179179 }
180180 if (tree.errors.len != 0) {
181181 fmt.any_error = true;
......@@ -183,7 +183,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
183183 }
184184
185185 if (check_mode) {
186 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, &tree);
186 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
187187 if (anything_changed) {
188188 try stderr.print("{}\n", file_path);
189189 fmt.any_error = true;
......@@ -193,7 +193,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
193193 const baf = try io.BufferedAtomicFile.create(fmt.allocator, file_path);
194194 defer baf.destroy();
195195
196 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), &tree);
196 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
197197 if (anything_changed) {
198198 try stderr.print("{}\n", file_path);
199199 try baf.finish();
......@@ -210,9 +210,14 @@ const Fmt = struct {
210210 const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
211211};
212212
213fn printErrMsgToFile(allocator: *mem.Allocator, parse_error: *const ast.Error, tree: *ast.Tree,
214 path: []const u8, file: os.File, color: errmsg.Color,) !void
215{
213fn printErrMsgToFile(
214 allocator: *mem.Allocator,
215 parse_error: *const ast.Error,
216 tree: *ast.Tree,
217 path: []const u8,
218 file: os.File,
219 color: errmsg.Color,
220) !void {
216221 const color_on = switch (color) {
217222 errmsg.Color.Auto => file.isTty(),
218223 errmsg.Color.On => true,
std/zig/ast.zig+5-1
......@@ -18,7 +18,11 @@ pub const Tree = struct {
1818 pub const ErrorList = SegmentedList(Error, 0);
1919
2020 pub fn deinit(self: *Tree) void {
21 self.arena_allocator.deinit();
21 // Here we copy the arena allocator into stack memory, because
22 // otherwise it would destroy itself while it was still working.
23 var arena_allocator = self.arena_allocator;
24 arena_allocator.deinit();
25 // self is destroyed
2226 }
2327
2428 pub fn renderError(self: *Tree, parse_error: *Error, stream: var) !void {
std/zig/parse.zig+150-149
......@@ -9,7 +9,7 @@ const Error = ast.Error;
99
1010/// Result should be freed with tree.deinit() when there are
1111/// no more references to any of the tokens or nodes.
12pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
12pub fn parse(allocator: *mem.Allocator, source: []const u8) !*ast.Tree {
1313 var tree_arena = std.heap.ArenaAllocator.init(allocator);
1414 errdefer tree_arena.deinit();
1515
......@@ -26,7 +26,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2626 .eof_token = undefined,
2727 };
2828
29 var tree = ast.Tree{
29 const tree = try arena.create(ast.Tree);
30 tree.* = ast.Tree{
3031 .source = source,
3132 .root_node = root_node,
3233 .arena_allocator = tree_arena,
......@@ -57,9 +58,9 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
5758
5859 switch (state) {
5960 State.TopLevel => {
60 const comments = try eatDocComments(arena, &tok_it, &tree);
61 const comments = try eatDocComments(arena, &tok_it, tree);
6162
62 const token = nextToken(&tok_it, &tree);
63 const token = nextToken(&tok_it, tree);
6364 const token_index = token.index;
6465 const token_ptr = token.ptr;
6566 switch (token_ptr.id) {
......@@ -140,7 +141,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
140141 continue;
141142 },
142143 else => {
143 prevToken(&tok_it, &tree);
144 prevToken(&tok_it, tree);
144145 stack.append(State.TopLevel) catch unreachable;
145146 try stack.append(State{
146147 .TopLevelExtern = TopLevelDeclCtx{
......@@ -156,7 +157,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
156157 }
157158 },
158159 State.TopLevelExtern => |ctx| {
159 const token = nextToken(&tok_it, &tree);
160 const token = nextToken(&tok_it, tree);
160161 const token_index = token.index;
161162 const token_ptr = token.ptr;
162163 switch (token_ptr.id) {
......@@ -191,7 +192,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
191192 continue;
192193 },
193194 else => {
194 prevToken(&tok_it, &tree);
195 prevToken(&tok_it, tree);
195196 stack.append(State{ .TopLevelDecl = ctx }) catch unreachable;
196197 continue;
197198 },
......@@ -199,11 +200,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
199200 },
200201 State.TopLevelLibname => |ctx| {
201202 const lib_name = blk: {
202 const lib_name_token = nextToken(&tok_it, &tree);
203 const lib_name_token = nextToken(&tok_it, tree);
203204 const lib_name_token_index = lib_name_token.index;
204205 const lib_name_token_ptr = lib_name_token.ptr;
205 break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, &tree)) orelse {
206 prevToken(&tok_it, &tree);
206 break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, tree)) orelse {
207 prevToken(&tok_it, tree);
207208 break :blk null;
208209 };
209210 };
......@@ -220,7 +221,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
220221 continue;
221222 },
222223 State.ThreadLocal => |ctx| {
223 const token = nextToken(&tok_it, &tree);
224 const token = nextToken(&tok_it, tree);
224225 const token_index = token.index;
225226 const token_ptr = token.ptr;
226227 switch (token_ptr.id) {
......@@ -246,7 +247,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
246247 }
247248 },
248249 State.TopLevelDecl => |ctx| {
249 const token = nextToken(&tok_it, &tree);
250 const token = nextToken(&tok_it, tree);
250251 const token_index = token.index;
251252 const token_ptr = token.ptr;
252253 switch (token_ptr.id) {
......@@ -387,7 +388,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
387388 }
388389 },
389390 State.TopLevelExternOrField => |ctx| {
390 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| {
391 if (eatToken(&tok_it, tree, Token.Id.Identifier)) |identifier| {
391392 const node = try arena.create(ast.Node.StructField);
392393 node.* = ast.Node.StructField{
393394 .base = ast.Node{ .id = ast.Node.Id.StructField },
......@@ -424,11 +425,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
424425 },
425426
426427 State.FieldInitValue => |ctx| {
427 const eq_tok = nextToken(&tok_it, &tree);
428 const eq_tok = nextToken(&tok_it, tree);
428429 const eq_tok_index = eq_tok.index;
429430 const eq_tok_ptr = eq_tok.ptr;
430431 if (eq_tok_ptr.id != Token.Id.Equal) {
431 prevToken(&tok_it, &tree);
432 prevToken(&tok_it, tree);
432433 continue;
433434 }
434435 stack.append(State{ .Expression = ctx }) catch unreachable;
......@@ -436,7 +437,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
436437 },
437438
438439 State.ContainerKind => |ctx| {
439 const token = nextToken(&tok_it, &tree);
440 const token = nextToken(&tok_it, tree);
440441 const token_index = token.index;
441442 const token_ptr = token.ptr;
442443 const node = try arena.create(ast.Node.ContainerDecl);
......@@ -469,7 +470,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
469470 },
470471
471472 State.ContainerInitArgStart => |container_decl| {
472 if (eatToken(&tok_it, &tree, Token.Id.LParen) == null) {
473 if (eatToken(&tok_it, tree, Token.Id.LParen) == null) {
473474 continue;
474475 }
475476
......@@ -479,24 +480,24 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
479480 },
480481
481482 State.ContainerInitArg => |container_decl| {
482 const init_arg_token = nextToken(&tok_it, &tree);
483 const init_arg_token = nextToken(&tok_it, tree);
483484 const init_arg_token_index = init_arg_token.index;
484485 const init_arg_token_ptr = init_arg_token.ptr;
485486 switch (init_arg_token_ptr.id) {
486487 Token.Id.Keyword_enum => {
487488 container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Enum = null };
488 const lparen_tok = nextToken(&tok_it, &tree);
489 const lparen_tok = nextToken(&tok_it, tree);
489490 const lparen_tok_index = lparen_tok.index;
490491 const lparen_tok_ptr = lparen_tok.ptr;
491492 if (lparen_tok_ptr.id == Token.Id.LParen) {
492493 try stack.append(State{ .ExpectToken = Token.Id.RParen });
493494 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &container_decl.init_arg_expr.Enum } });
494495 } else {
495 prevToken(&tok_it, &tree);
496 prevToken(&tok_it, tree);
496497 }
497498 },
498499 else => {
499 prevToken(&tok_it, &tree);
500 prevToken(&tok_it, tree);
500501 container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Type = undefined };
501502 stack.append(State{ .Expression = OptionalCtx{ .Required = &container_decl.init_arg_expr.Type } }) catch unreachable;
502503 },
......@@ -505,8 +506,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
505506 },
506507
507508 State.ContainerDecl => |container_decl| {
508 const comments = try eatDocComments(arena, &tok_it, &tree);
509 const token = nextToken(&tok_it, &tree);
509 const comments = try eatDocComments(arena, &tok_it, tree);
510 const token = nextToken(&tok_it, tree);
510511 const token_index = token.index;
511512 const token_ptr = token.ptr;
512513 switch (token_ptr.id) {
......@@ -657,7 +658,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
657658 continue;
658659 },
659660 else => {
660 prevToken(&tok_it, &tree);
661 prevToken(&tok_it, tree);
661662 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
662663 try stack.append(State{
663664 .TopLevelExtern = TopLevelDeclCtx{
......@@ -709,7 +710,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
709710 State.VarDeclAlign => |var_decl| {
710711 try stack.append(State{ .VarDeclSection = var_decl });
711712
712 const next_token = nextToken(&tok_it, &tree);
713 const next_token = nextToken(&tok_it, tree);
713714 const next_token_index = next_token.index;
714715 const next_token_ptr = next_token.ptr;
715716 if (next_token_ptr.id == Token.Id.Keyword_align) {
......@@ -719,13 +720,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
719720 continue;
720721 }
721722
722 prevToken(&tok_it, &tree);
723 prevToken(&tok_it, tree);
723724 continue;
724725 },
725726 State.VarDeclSection => |var_decl| {
726727 try stack.append(State{ .VarDeclEq = var_decl });
727728
728 const next_token = nextToken(&tok_it, &tree);
729 const next_token = nextToken(&tok_it, tree);
729730 const next_token_index = next_token.index;
730731 const next_token_ptr = next_token.ptr;
731732 if (next_token_ptr.id == Token.Id.Keyword_linksection) {
......@@ -735,11 +736,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
735736 continue;
736737 }
737738
738 prevToken(&tok_it, &tree);
739 prevToken(&tok_it, tree);
739740 continue;
740741 },
741742 State.VarDeclEq => |var_decl| {
742 const token = nextToken(&tok_it, &tree);
743 const token = nextToken(&tok_it, tree);
743744 const token_index = token.index;
744745 const token_ptr = token.ptr;
745746 switch (token_ptr.id) {
......@@ -761,7 +762,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
761762 },
762763
763764 State.VarDeclSemiColon => |var_decl| {
764 const semicolon_token = nextToken(&tok_it, &tree);
765 const semicolon_token = nextToken(&tok_it, tree);
765766
766767 if (semicolon_token.ptr.id != Token.Id.Semicolon) {
767768 ((try tree.errors.addOne())).* = Error{
......@@ -775,18 +776,18 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
775776
776777 var_decl.semicolon_token = semicolon_token.index;
777778
778 if (eatToken(&tok_it, &tree, Token.Id.DocComment)) |doc_comment_token| {
779 if (eatToken(&tok_it, tree, Token.Id.DocComment)) |doc_comment_token| {
779780 const loc = tree.tokenLocation(semicolon_token.ptr.end, doc_comment_token);
780781 if (loc.line == 0) {
781782 try pushDocComment(arena, doc_comment_token, &var_decl.doc_comments);
782783 } else {
783 prevToken(&tok_it, &tree);
784 prevToken(&tok_it, tree);
784785 }
785786 }
786787 },
787788
788789 State.FnDef => |fn_proto| {
789 const token = nextToken(&tok_it, &tree);
790 const token = nextToken(&tok_it, tree);
790791 const token_index = token.index;
791792 const token_ptr = token.ptr;
792793 switch (token_ptr.id) {
......@@ -815,7 +816,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
815816 try stack.append(State{ .ParamDecl = fn_proto });
816817 try stack.append(State{ .ExpectToken = Token.Id.LParen });
817818
818 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |name_token| {
819 if (eatToken(&tok_it, tree, Token.Id.Identifier)) |name_token| {
819820 fn_proto.name_token = name_token;
820821 }
821822 continue;
......@@ -823,7 +824,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
823824 State.FnProtoAlign => |fn_proto| {
824825 stack.append(State{ .FnProtoSection = fn_proto }) catch unreachable;
825826
826 if (eatToken(&tok_it, &tree, Token.Id.Keyword_align)) |align_token| {
827 if (eatToken(&tok_it, tree, Token.Id.Keyword_align)) |align_token| {
827828 try stack.append(State{ .ExpectToken = Token.Id.RParen });
828829 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &fn_proto.align_expr } });
829830 try stack.append(State{ .ExpectToken = Token.Id.LParen });
......@@ -833,7 +834,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
833834 State.FnProtoSection => |fn_proto| {
834835 stack.append(State{ .FnProtoReturnType = fn_proto }) catch unreachable;
835836
836 if (eatToken(&tok_it, &tree, Token.Id.Keyword_linksection)) |align_token| {
837 if (eatToken(&tok_it, tree, Token.Id.Keyword_linksection)) |align_token| {
837838 try stack.append(State{ .ExpectToken = Token.Id.RParen });
838839 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &fn_proto.section_expr } });
839840 try stack.append(State{ .ExpectToken = Token.Id.LParen });
......@@ -841,7 +842,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
841842 continue;
842843 },
843844 State.FnProtoReturnType => |fn_proto| {
844 const token = nextToken(&tok_it, &tree);
845 const token = nextToken(&tok_it, tree);
845846 const token_index = token.index;
846847 const token_ptr = token.ptr;
847848 switch (token_ptr.id) {
......@@ -864,7 +865,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
864865 }
865866 }
866867
867 prevToken(&tok_it, &tree);
868 prevToken(&tok_it, tree);
868869 fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = undefined };
869870 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &fn_proto.return_type.Explicit } }) catch unreachable;
870871 continue;
......@@ -873,8 +874,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
873874 },
874875
875876 State.ParamDecl => |fn_proto| {
876 const comments = try eatDocComments(arena, &tok_it, &tree);
877 if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
877 const comments = try eatDocComments(arena, &tok_it, tree);
878 if (eatToken(&tok_it, tree, Token.Id.RParen)) |_| {
878879 continue;
879880 }
880881 const param_decl = try arena.create(ast.Node.ParamDecl);
......@@ -900,9 +901,9 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
900901 continue;
901902 },
902903 State.ParamDeclAliasOrComptime => |param_decl| {
903 if (eatToken(&tok_it, &tree, Token.Id.Keyword_comptime)) |comptime_token| {
904 if (eatToken(&tok_it, tree, Token.Id.Keyword_comptime)) |comptime_token| {
904905 param_decl.comptime_token = comptime_token;
905 } else if (eatToken(&tok_it, &tree, Token.Id.Keyword_noalias)) |noalias_token| {
906 } else if (eatToken(&tok_it, tree, Token.Id.Keyword_noalias)) |noalias_token| {
906907 param_decl.noalias_token = noalias_token;
907908 }
908909 continue;
......@@ -910,20 +911,20 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
910911 State.ParamDeclName => |param_decl| {
911912 // TODO: Here, we eat two tokens in one state. This means that we can't have
912913 // comments between these two tokens.
913 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |ident_token| {
914 if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| {
914 if (eatToken(&tok_it, tree, Token.Id.Identifier)) |ident_token| {
915 if (eatToken(&tok_it, tree, Token.Id.Colon)) |_| {
915916 param_decl.name_token = ident_token;
916917 } else {
917 prevToken(&tok_it, &tree);
918 prevToken(&tok_it, tree);
918919 }
919920 }
920921 continue;
921922 },
922923 State.ParamDeclEnd => |ctx| {
923 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
924 if (eatToken(&tok_it, tree, Token.Id.Ellipsis3)) |ellipsis3| {
924925 ctx.param_decl.var_args_token = ellipsis3;
925926
926 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) {
927 switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RParen)) {
927928 ExpectCommaOrEndResult.end_token => |t| {
928929 if (t == null) {
929930 stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
......@@ -943,7 +944,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
943944 continue;
944945 },
945946 State.ParamDeclComma => |fn_proto| {
946 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) {
947 switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RParen)) {
947948 ExpectCommaOrEndResult.end_token => |t| {
948949 if (t == null) {
949950 stack.append(State{ .ParamDecl = fn_proto }) catch unreachable;
......@@ -958,7 +959,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
958959 },
959960
960961 State.MaybeLabeledExpression => |ctx| {
961 if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| {
962 if (eatToken(&tok_it, tree, Token.Id.Colon)) |_| {
962963 stack.append(State{
963964 .LabeledExpression = LabelCtx{
964965 .label = ctx.label,
......@@ -972,7 +973,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
972973 continue;
973974 },
974975 State.LabeledExpression => |ctx| {
975 const token = nextToken(&tok_it, &tree);
976 const token = nextToken(&tok_it, tree);
976977 const token_index = token.index;
977978 const token_ptr = token.ptr;
978979 switch (token_ptr.id) {
......@@ -1027,13 +1028,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
10271028 return tree;
10281029 }
10291030
1030 prevToken(&tok_it, &tree);
1031 prevToken(&tok_it, tree);
10311032 continue;
10321033 },
10331034 }
10341035 },
10351036 State.Inline => |ctx| {
1036 const token = nextToken(&tok_it, &tree);
1037 const token = nextToken(&tok_it, tree);
10371038 const token_index = token.index;
10381039 const token_ptr = token.ptr;
10391040 switch (token_ptr.id) {
......@@ -1065,7 +1066,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
10651066 return tree;
10661067 }
10671068
1068 prevToken(&tok_it, &tree);
1069 prevToken(&tok_it, tree);
10691070 continue;
10701071 },
10711072 }
......@@ -1122,7 +1123,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
11221123 continue;
11231124 },
11241125 State.Else => |dest| {
1125 if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {
1126 if (eatToken(&tok_it, tree, Token.Id.Keyword_else)) |else_token| {
11261127 const node = try arena.create(ast.Node.Else);
11271128 node.* = ast.Node.Else{
11281129 .base = ast.Node{ .id = ast.Node.Id.Else },
......@@ -1141,7 +1142,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
11411142 },
11421143
11431144 State.Block => |block| {
1144 const token = nextToken(&tok_it, &tree);
1145 const token = nextToken(&tok_it, tree);
11451146 const token_index = token.index;
11461147 const token_ptr = token.ptr;
11471148 switch (token_ptr.id) {
......@@ -1150,7 +1151,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
11501151 continue;
11511152 },
11521153 else => {
1153 prevToken(&tok_it, &tree);
1154 prevToken(&tok_it, tree);
11541155 stack.append(State{ .Block = block }) catch unreachable;
11551156
11561157 try stack.append(State{ .Statement = block });
......@@ -1159,7 +1160,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
11591160 }
11601161 },
11611162 State.Statement => |block| {
1162 const token = nextToken(&tok_it, &tree);
1163 const token = nextToken(&tok_it, tree);
11631164 const token_index = token.index;
11641165 const token_ptr = token.ptr;
11651166 switch (token_ptr.id) {
......@@ -1216,7 +1217,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
12161217 continue;
12171218 },
12181219 else => {
1219 prevToken(&tok_it, &tree);
1220 prevToken(&tok_it, tree);
12201221 const statement = try block.statements.addOne();
12211222 try stack.append(State{ .Semicolon = statement });
12221223 try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } });
......@@ -1225,7 +1226,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
12251226 }
12261227 },
12271228 State.ComptimeStatement => |ctx| {
1228 const token = nextToken(&tok_it, &tree);
1229 const token = nextToken(&tok_it, tree);
12291230 const token_index = token.index;
12301231 const token_ptr = token.ptr;
12311232 switch (token_ptr.id) {
......@@ -1245,8 +1246,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
12451246 continue;
12461247 },
12471248 else => {
1248 prevToken(&tok_it, &tree);
1249 prevToken(&tok_it, &tree);
1249 prevToken(&tok_it, tree);
1250 prevToken(&tok_it, tree);
12501251 const statement = try ctx.block.statements.addOne();
12511252 try stack.append(State{ .Semicolon = statement });
12521253 try stack.append(State{ .Expression = OptionalCtx{ .Required = statement } });
......@@ -1264,11 +1265,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
12641265 },
12651266
12661267 State.AsmOutputItems => |items| {
1267 const lbracket = nextToken(&tok_it, &tree);
1268 const lbracket = nextToken(&tok_it, tree);
12681269 const lbracket_index = lbracket.index;
12691270 const lbracket_ptr = lbracket.ptr;
12701271 if (lbracket_ptr.id != Token.Id.LBracket) {
1271 prevToken(&tok_it, &tree);
1272 prevToken(&tok_it, tree);
12721273 continue;
12731274 }
12741275
......@@ -1299,7 +1300,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
12991300 continue;
13001301 },
13011302 State.AsmOutputReturnOrType => |node| {
1302 const token = nextToken(&tok_it, &tree);
1303 const token = nextToken(&tok_it, tree);
13031304 const token_index = token.index;
13041305 const token_ptr = token.ptr;
13051306 switch (token_ptr.id) {
......@@ -1319,11 +1320,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
13191320 }
13201321 },
13211322 State.AsmInputItems => |items| {
1322 const lbracket = nextToken(&tok_it, &tree);
1323 const lbracket = nextToken(&tok_it, tree);
13231324 const lbracket_index = lbracket.index;
13241325 const lbracket_ptr = lbracket.ptr;
13251326 if (lbracket_ptr.id != Token.Id.LBracket) {
1326 prevToken(&tok_it, &tree);
1327 prevToken(&tok_it, tree);
13271328 continue;
13281329 }
13291330
......@@ -1354,16 +1355,16 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
13541355 continue;
13551356 },
13561357 State.AsmClobberItems => |items| {
1357 while (eatToken(&tok_it, &tree, Token.Id.StringLiteral)) |strlit| {
1358 while (eatToken(&tok_it, tree, Token.Id.StringLiteral)) |strlit| {
13581359 try items.push(strlit);
1359 if (eatToken(&tok_it, &tree, Token.Id.Comma) == null)
1360 if (eatToken(&tok_it, tree, Token.Id.Comma) == null)
13601361 break;
13611362 }
13621363 continue;
13631364 },
13641365
13651366 State.ExprListItemOrEnd => |list_state| {
1366 if (eatToken(&tok_it, &tree, list_state.end)) |token_index| {
1367 if (eatToken(&tok_it, tree, list_state.end)) |token_index| {
13671368 (list_state.ptr).* = token_index;
13681369 continue;
13691370 }
......@@ -1373,7 +1374,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
13731374 continue;
13741375 },
13751376 State.ExprListCommaOrEnd => |list_state| {
1376 switch (expectCommaOrEnd(&tok_it, &tree, list_state.end)) {
1377 switch (expectCommaOrEnd(&tok_it, tree, list_state.end)) {
13771378 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
13781379 (list_state.ptr).* = end;
13791380 continue;
......@@ -1388,7 +1389,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
13881389 }
13891390 },
13901391 State.FieldInitListItemOrEnd => |list_state| {
1391 if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| {
1392 if (eatToken(&tok_it, tree, Token.Id.RBrace)) |rbrace| {
13921393 (list_state.ptr).* = rbrace;
13931394 continue;
13941395 }
......@@ -1420,7 +1421,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14201421 continue;
14211422 },
14221423 State.FieldInitListCommaOrEnd => |list_state| {
1423 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) {
1424 switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RBrace)) {
14241425 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
14251426 (list_state.ptr).* = end;
14261427 continue;
......@@ -1435,17 +1436,17 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14351436 }
14361437 },
14371438 State.FieldListCommaOrEnd => |field_ctx| {
1438 const end_token = nextToken(&tok_it, &tree);
1439 const end_token = nextToken(&tok_it, tree);
14391440 const end_token_index = end_token.index;
14401441 const end_token_ptr = end_token.ptr;
14411442 switch (end_token_ptr.id) {
14421443 Token.Id.Comma => {
1443 if (eatToken(&tok_it, &tree, Token.Id.DocComment)) |doc_comment_token| {
1444 if (eatToken(&tok_it, tree, Token.Id.DocComment)) |doc_comment_token| {
14441445 const loc = tree.tokenLocation(end_token_ptr.end, doc_comment_token);
14451446 if (loc.line == 0) {
14461447 try pushDocComment(arena, doc_comment_token, field_ctx.doc_comments);
14471448 } else {
1448 prevToken(&tok_it, &tree);
1449 prevToken(&tok_it, tree);
14491450 }
14501451 }
14511452
......@@ -1468,7 +1469,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14681469 }
14691470 },
14701471 State.ErrorTagListItemOrEnd => |list_state| {
1471 if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| {
1472 if (eatToken(&tok_it, tree, Token.Id.RBrace)) |rbrace| {
14721473 (list_state.ptr).* = rbrace;
14731474 continue;
14741475 }
......@@ -1480,7 +1481,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14801481 continue;
14811482 },
14821483 State.ErrorTagListCommaOrEnd => |list_state| {
1483 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) {
1484 switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RBrace)) {
14841485 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
14851486 (list_state.ptr).* = end;
14861487 continue;
......@@ -1495,12 +1496,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14951496 }
14961497 },
14971498 State.SwitchCaseOrEnd => |list_state| {
1498 if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| {
1499 if (eatToken(&tok_it, tree, Token.Id.RBrace)) |rbrace| {
14991500 (list_state.ptr).* = rbrace;
15001501 continue;
15011502 }
15021503
1503 const comments = try eatDocComments(arena, &tok_it, &tree);
1504 const comments = try eatDocComments(arena, &tok_it, tree);
15041505 const node = try arena.create(ast.Node.SwitchCase);
15051506 node.* = ast.Node.SwitchCase{
15061507 .base = ast.Node{ .id = ast.Node.Id.SwitchCase },
......@@ -1519,7 +1520,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
15191520 },
15201521
15211522 State.SwitchCaseCommaOrEnd => |list_state| {
1522 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) {
1523 switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RBrace)) {
15231524 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
15241525 (list_state.ptr).* = end;
15251526 continue;
......@@ -1535,7 +1536,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
15351536 },
15361537
15371538 State.SwitchCaseFirstItem => |switch_case| {
1538 const token = nextToken(&tok_it, &tree);
1539 const token = nextToken(&tok_it, tree);
15391540 const token_index = token.index;
15401541 const token_ptr = token.ptr;
15411542 if (token_ptr.id == Token.Id.Keyword_else) {
......@@ -1554,26 +1555,26 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
15541555 });
15551556 continue;
15561557 } else {
1557 prevToken(&tok_it, &tree);
1558 prevToken(&tok_it, tree);
15581559 stack.append(State{ .SwitchCaseItemCommaOrEnd = switch_case }) catch unreachable;
15591560 try stack.append(State{ .RangeExpressionBegin = OptionalCtx{ .Required = try switch_case.items.addOne() } });
15601561 continue;
15611562 }
15621563 },
15631564 State.SwitchCaseItemOrEnd => |switch_case| {
1564 const token = nextToken(&tok_it, &tree);
1565 const token = nextToken(&tok_it, tree);
15651566 if (token.ptr.id == Token.Id.EqualAngleBracketRight) {
15661567 switch_case.arrow_token = token.index;
15671568 continue;
15681569 } else {
1569 prevToken(&tok_it, &tree);
1570 prevToken(&tok_it, tree);
15701571 stack.append(State{ .SwitchCaseItemCommaOrEnd = switch_case }) catch unreachable;
15711572 try stack.append(State{ .RangeExpressionBegin = OptionalCtx{ .Required = try switch_case.items.addOne() } });
15721573 continue;
15731574 }
15741575 },
15751576 State.SwitchCaseItemCommaOrEnd => |switch_case| {
1576 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.EqualAngleBracketRight)) {
1577 switch (expectCommaOrEnd(&tok_it, tree, Token.Id.EqualAngleBracketRight)) {
15771578 ExpectCommaOrEndResult.end_token => |end_token| {
15781579 if (end_token) |t| {
15791580 switch_case.arrow_token = t;
......@@ -1591,14 +1592,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
15911592 },
15921593
15931594 State.SuspendBody => |suspend_node| {
1594 const token = nextToken(&tok_it, &tree);
1595 const token = nextToken(&tok_it, tree);
15951596 switch (token.ptr.id) {
15961597 Token.Id.Semicolon => {
1597 prevToken(&tok_it, &tree);
1598 prevToken(&tok_it, tree);
15981599 continue;
15991600 },
16001601 Token.Id.LBrace => {
1601 prevToken(&tok_it, &tree);
1602 prevToken(&tok_it, tree);
16021603 try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .RequiredNull = &suspend_node.body } });
16031604 continue;
16041605 },
......@@ -1608,7 +1609,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
16081609 }
16091610 },
16101611 State.AsyncAllocator => |async_node| {
1611 if (eatToken(&tok_it, &tree, Token.Id.AngleBracketLeft) == null) {
1612 if (eatToken(&tok_it, tree, Token.Id.AngleBracketLeft) == null) {
16121613 continue;
16131614 }
16141615
......@@ -1649,7 +1650,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
16491650 },
16501651
16511652 State.ExternType => |ctx| {
1652 if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| {
1653 if (eatToken(&tok_it, tree, Token.Id.Keyword_fn)) |fn_token| {
16531654 const fn_proto = try arena.create(ast.Node.FnProto);
16541655 fn_proto.* = ast.Node.FnProto{
16551656 .base = ast.Node{ .id = ast.Node.Id.FnProto },
......@@ -1682,7 +1683,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
16821683 continue;
16831684 },
16841685 State.SliceOrArrayAccess => |node| {
1685 const token = nextToken(&tok_it, &tree);
1686 const token = nextToken(&tok_it, tree);
16861687 const token_index = token.index;
16871688 const token_ptr = token.ptr;
16881689 switch (token_ptr.id) {
......@@ -1715,7 +1716,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
17151716 }
17161717 },
17171718 State.SliceOrArrayType => |node| {
1718 if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| {
1719 if (eatToken(&tok_it, tree, Token.Id.RBracket)) |_| {
17191720 node.op = ast.Node.PrefixOp.Op{
17201721 .SliceType = ast.Node.PrefixOp.PtrInfo{
17211722 .align_info = null,
......@@ -1737,7 +1738,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
17371738 },
17381739
17391740 State.PtrTypeModifiers => |addr_of_info| {
1740 const token = nextToken(&tok_it, &tree);
1741 const token = nextToken(&tok_it, tree);
17411742 const token_index = token.index;
17421743 const token_ptr = token.ptr;
17431744 switch (token_ptr.id) {
......@@ -1787,14 +1788,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
17871788 continue;
17881789 },
17891790 else => {
1790 prevToken(&tok_it, &tree);
1791 prevToken(&tok_it, tree);
17911792 continue;
17921793 },
17931794 }
17941795 },
17951796
17961797 State.AlignBitRange => |align_info| {
1797 const token = nextToken(&tok_it, &tree);
1798 const token = nextToken(&tok_it, tree);
17981799 switch (token.ptr.id) {
17991800 Token.Id.Colon => {
18001801 align_info.bit_range = ast.Node.PrefixOp.PtrInfo.Align.BitRange(undefined);
......@@ -1817,7 +1818,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18171818 },
18181819
18191820 State.Payload => |opt_ctx| {
1820 const token = nextToken(&tok_it, &tree);
1821 const token = nextToken(&tok_it, tree);
18211822 const token_index = token.index;
18221823 const token_ptr = token.ptr;
18231824 if (token_ptr.id != Token.Id.Pipe) {
......@@ -1831,7 +1832,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18311832 return tree;
18321833 }
18331834
1834 prevToken(&tok_it, &tree);
1835 prevToken(&tok_it, tree);
18351836 continue;
18361837 }
18371838
......@@ -1854,7 +1855,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18541855 continue;
18551856 },
18561857 State.PointerPayload => |opt_ctx| {
1857 const token = nextToken(&tok_it, &tree);
1858 const token = nextToken(&tok_it, tree);
18581859 const token_index = token.index;
18591860 const token_ptr = token.ptr;
18601861 if (token_ptr.id != Token.Id.Pipe) {
......@@ -1868,7 +1869,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18681869 return tree;
18691870 }
18701871
1871 prevToken(&tok_it, &tree);
1872 prevToken(&tok_it, tree);
18721873 continue;
18731874 }
18741875
......@@ -1898,7 +1899,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18981899 continue;
18991900 },
19001901 State.PointerIndexPayload => |opt_ctx| {
1901 const token = nextToken(&tok_it, &tree);
1902 const token = nextToken(&tok_it, tree);
19021903 const token_index = token.index;
19031904 const token_ptr = token.ptr;
19041905 if (token_ptr.id != Token.Id.Pipe) {
......@@ -1912,7 +1913,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
19121913 return tree;
19131914 }
19141915
1915 prevToken(&tok_it, &tree);
1916 prevToken(&tok_it, tree);
19161917 continue;
19171918 }
19181919
......@@ -1946,7 +1947,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
19461947 },
19471948
19481949 State.Expression => |opt_ctx| {
1949 const token = nextToken(&tok_it, &tree);
1950 const token = nextToken(&tok_it, tree);
19501951 const token_index = token.index;
19511952 const token_ptr = token.ptr;
19521953 switch (token_ptr.id) {
......@@ -2000,7 +2001,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20002001 },
20012002 else => {
20022003 if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr.*, token_index)) {
2003 prevToken(&tok_it, &tree);
2004 prevToken(&tok_it, tree);
20042005 stack.append(State{ .UnwrapExpressionBegin = opt_ctx }) catch unreachable;
20052006 }
20062007 continue;
......@@ -2015,7 +2016,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20152016 State.RangeExpressionEnd => |opt_ctx| {
20162017 const lhs = opt_ctx.get() orelse continue;
20172018
2018 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
2019 if (eatToken(&tok_it, tree, Token.Id.Ellipsis3)) |ellipsis3| {
20192020 const node = try arena.create(ast.Node.InfixOp);
20202021 node.* = ast.Node.InfixOp{
20212022 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2038,7 +2039,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20382039 State.AssignmentExpressionEnd => |opt_ctx| {
20392040 const lhs = opt_ctx.get() orelse continue;
20402041
2041 const token = nextToken(&tok_it, &tree);
2042 const token = nextToken(&tok_it, tree);
20422043 const token_index = token.index;
20432044 const token_ptr = token.ptr;
20442045 if (tokenIdToAssignment(token_ptr.id)) |ass_id| {
......@@ -2055,7 +2056,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20552056 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } });
20562057 continue;
20572058 } else {
2058 prevToken(&tok_it, &tree);
2059 prevToken(&tok_it, tree);
20592060 continue;
20602061 }
20612062 },
......@@ -2069,7 +2070,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20692070 State.UnwrapExpressionEnd => |opt_ctx| {
20702071 const lhs = opt_ctx.get() orelse continue;
20712072
2072 const token = nextToken(&tok_it, &tree);
2073 const token = nextToken(&tok_it, tree);
20732074 const token_index = token.index;
20742075 const token_ptr = token.ptr;
20752076 if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| {
......@@ -2091,7 +2092,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20912092 }
20922093 continue;
20932094 } else {
2094 prevToken(&tok_it, &tree);
2095 prevToken(&tok_it, tree);
20952096 continue;
20962097 }
20972098 },
......@@ -2105,7 +2106,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21052106 State.BoolOrExpressionEnd => |opt_ctx| {
21062107 const lhs = opt_ctx.get() orelse continue;
21072108
2108 if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {
2109 if (eatToken(&tok_it, tree, Token.Id.Keyword_or)) |or_token| {
21092110 const node = try arena.create(ast.Node.InfixOp);
21102111 node.* = ast.Node.InfixOp{
21112112 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2130,7 +2131,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21302131 State.BoolAndExpressionEnd => |opt_ctx| {
21312132 const lhs = opt_ctx.get() orelse continue;
21322133
2133 if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {
2134 if (eatToken(&tok_it, tree, Token.Id.Keyword_and)) |and_token| {
21342135 const node = try arena.create(ast.Node.InfixOp);
21352136 node.* = ast.Node.InfixOp{
21362137 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2155,7 +2156,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21552156 State.ComparisonExpressionEnd => |opt_ctx| {
21562157 const lhs = opt_ctx.get() orelse continue;
21572158
2158 const token = nextToken(&tok_it, &tree);
2159 const token = nextToken(&tok_it, tree);
21592160 const token_index = token.index;
21602161 const token_ptr = token.ptr;
21612162 if (tokenIdToComparison(token_ptr.id)) |comp_id| {
......@@ -2172,7 +2173,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21722173 try stack.append(State{ .BinaryOrExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
21732174 continue;
21742175 } else {
2175 prevToken(&tok_it, &tree);
2176 prevToken(&tok_it, tree);
21762177 continue;
21772178 }
21782179 },
......@@ -2186,7 +2187,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21862187 State.BinaryOrExpressionEnd => |opt_ctx| {
21872188 const lhs = opt_ctx.get() orelse continue;
21882189
2189 if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {
2190 if (eatToken(&tok_it, tree, Token.Id.Pipe)) |pipe| {
21902191 const node = try arena.create(ast.Node.InfixOp);
21912192 node.* = ast.Node.InfixOp{
21922193 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2211,7 +2212,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22112212 State.BinaryXorExpressionEnd => |opt_ctx| {
22122213 const lhs = opt_ctx.get() orelse continue;
22132214
2214 if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {
2215 if (eatToken(&tok_it, tree, Token.Id.Caret)) |caret| {
22152216 const node = try arena.create(ast.Node.InfixOp);
22162217 node.* = ast.Node.InfixOp{
22172218 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2236,7 +2237,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22362237 State.BinaryAndExpressionEnd => |opt_ctx| {
22372238 const lhs = opt_ctx.get() orelse continue;
22382239
2239 if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {
2240 if (eatToken(&tok_it, tree, Token.Id.Ampersand)) |ampersand| {
22402241 const node = try arena.create(ast.Node.InfixOp);
22412242 node.* = ast.Node.InfixOp{
22422243 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2261,7 +2262,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22612262 State.BitShiftExpressionEnd => |opt_ctx| {
22622263 const lhs = opt_ctx.get() orelse continue;
22632264
2264 const token = nextToken(&tok_it, &tree);
2265 const token = nextToken(&tok_it, tree);
22652266 const token_index = token.index;
22662267 const token_ptr = token.ptr;
22672268 if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| {
......@@ -2278,7 +2279,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22782279 try stack.append(State{ .AdditionExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
22792280 continue;
22802281 } else {
2281 prevToken(&tok_it, &tree);
2282 prevToken(&tok_it, tree);
22822283 continue;
22832284 }
22842285 },
......@@ -2292,7 +2293,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22922293 State.AdditionExpressionEnd => |opt_ctx| {
22932294 const lhs = opt_ctx.get() orelse continue;
22942295
2295 const token = nextToken(&tok_it, &tree);
2296 const token = nextToken(&tok_it, tree);
22962297 const token_index = token.index;
22972298 const token_ptr = token.ptr;
22982299 if (tokenIdToAddition(token_ptr.id)) |add_id| {
......@@ -2309,7 +2310,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23092310 try stack.append(State{ .MultiplyExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
23102311 continue;
23112312 } else {
2312 prevToken(&tok_it, &tree);
2313 prevToken(&tok_it, tree);
23132314 continue;
23142315 }
23152316 },
......@@ -2323,7 +2324,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23232324 State.MultiplyExpressionEnd => |opt_ctx| {
23242325 const lhs = opt_ctx.get() orelse continue;
23252326
2326 const token = nextToken(&tok_it, &tree);
2327 const token = nextToken(&tok_it, tree);
23272328 const token_index = token.index;
23282329 const token_ptr = token.ptr;
23292330 if (tokenIdToMultiply(token_ptr.id)) |mult_id| {
......@@ -2340,7 +2341,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23402341 try stack.append(State{ .CurlySuffixExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
23412342 continue;
23422343 } else {
2343 prevToken(&tok_it, &tree);
2344 prevToken(&tok_it, tree);
23442345 continue;
23452346 }
23462347 },
......@@ -2405,7 +2406,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24052406 State.TypeExprEnd => |opt_ctx| {
24062407 const lhs = opt_ctx.get() orelse continue;
24072408
2408 if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {
2409 if (eatToken(&tok_it, tree, Token.Id.Bang)) |bang| {
24092410 const node = try arena.create(ast.Node.InfixOp);
24102411 node.* = ast.Node.InfixOp{
24112412 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2422,7 +2423,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24222423 },
24232424
24242425 State.PrefixOpExpression => |opt_ctx| {
2425 const token = nextToken(&tok_it, &tree);
2426 const token = nextToken(&tok_it, tree);
24262427 const token_index = token.index;
24272428 const token_ptr = token.ptr;
24282429 if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| {
......@@ -2454,14 +2455,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24542455 }
24552456 continue;
24562457 } else {
2457 prevToken(&tok_it, &tree);
2458 prevToken(&tok_it, tree);
24582459 stack.append(State{ .SuffixOpExpressionBegin = opt_ctx }) catch unreachable;
24592460 continue;
24602461 }
24612462 },
24622463
24632464 State.SuffixOpExpressionBegin => |opt_ctx| {
2464 if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| {
2465 if (eatToken(&tok_it, tree, Token.Id.Keyword_async)) |async_token| {
24652466 const async_node = try arena.create(ast.Node.AsyncAttribute);
24662467 async_node.* = ast.Node.AsyncAttribute{
24672468 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
......@@ -2489,7 +2490,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24892490 State.SuffixOpExpressionEnd => |opt_ctx| {
24902491 const lhs = opt_ctx.get() orelse continue;
24912492
2492 const token = nextToken(&tok_it, &tree);
2493 const token = nextToken(&tok_it, tree);
24932494 const token_index = token.index;
24942495 const token_ptr = token.ptr;
24952496 switch (token_ptr.id) {
......@@ -2534,7 +2535,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
25342535 continue;
25352536 },
25362537 Token.Id.Period => {
2537 if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| {
2538 if (eatToken(&tok_it, tree, Token.Id.Asterisk)) |asterisk_token| {
25382539 const node = try arena.create(ast.Node.SuffixOp);
25392540 node.* = ast.Node.SuffixOp{
25402541 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
......@@ -2546,7 +2547,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
25462547 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
25472548 continue;
25482549 }
2549 if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| {
2550 if (eatToken(&tok_it, tree, Token.Id.QuestionMark)) |question_token| {
25502551 const node = try arena.create(ast.Node.SuffixOp);
25512552 node.* = ast.Node.SuffixOp{
25522553 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
......@@ -2573,21 +2574,21 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
25732574 continue;
25742575 },
25752576 else => {
2576 prevToken(&tok_it, &tree);
2577 prevToken(&tok_it, tree);
25772578 continue;
25782579 },
25792580 }
25802581 },
25812582
25822583 State.PrimaryExpression => |opt_ctx| {
2583 const token = nextToken(&tok_it, &tree);
2584 const token = nextToken(&tok_it, tree);
25842585 switch (token.ptr.id) {
25852586 Token.Id.IntegerLiteral => {
25862587 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.IntegerLiteral, token.index);
25872588 continue;
25882589 },
25892590 Token.Id.Period => {
2590 const name_token = nextToken(&tok_it, &tree);
2591 const name_token = nextToken(&tok_it, tree);
25912592 if (name_token.ptr.id != Token.Id.Identifier) {
25922593 ((try tree.errors.addOne())).* = Error{
25932594 .ExpectedToken = Error.ExpectedToken{
......@@ -2643,11 +2644,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
26432644 .result = null,
26442645 };
26452646 opt_ctx.store(&node.base);
2646 const next_token = nextToken(&tok_it, &tree);
2647 const next_token = nextToken(&tok_it, tree);
26472648 const next_token_index = next_token.index;
26482649 const next_token_ptr = next_token.ptr;
26492650 if (next_token_ptr.id != Token.Id.Arrow) {
2650 prevToken(&tok_it, &tree);
2651 prevToken(&tok_it, tree);
26512652 continue;
26522653 }
26532654 node.result = ast.Node.PromiseType.Result{
......@@ -2659,7 +2660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
26592660 continue;
26602661 },
26612662 Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => {
2662 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) orelse unreachable);
2663 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, tree)) orelse unreachable);
26632664 continue;
26642665 },
26652666 Token.Id.LParen => {
......@@ -2747,7 +2748,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
27472748 continue;
27482749 },
27492750 Token.Id.Keyword_struct, Token.Id.Keyword_union, Token.Id.Keyword_enum => {
2750 prevToken(&tok_it, &tree);
2751 prevToken(&tok_it, tree);
27512752 stack.append(State{
27522753 .ContainerKind = ContainerKindCtx{
27532754 .opt_ctx = opt_ctx,
......@@ -2864,7 +2865,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
28642865 },
28652866 else => {
28662867 if (!try parseBlockExpr(&stack, arena, opt_ctx, token.ptr.*, token.index)) {
2867 prevToken(&tok_it, &tree);
2868 prevToken(&tok_it, tree);
28682869 if (opt_ctx != OptionalCtx.Optional) {
28692870 ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token.index } };
28702871 return tree;
......@@ -2876,7 +2877,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
28762877 },
28772878
28782879 State.ErrorTypeOrSetDecl => |ctx| {
2879 if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) {
2880 if (eatToken(&tok_it, tree, Token.Id.LBrace) == null) {
28802881 const node = try arena.create(ast.Node.InfixOp);
28812882 node.* = ast.Node.InfixOp{
28822883 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
......@@ -2914,11 +2915,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
29142915 continue;
29152916 },
29162917 State.StringLiteral => |opt_ctx| {
2917 const token = nextToken(&tok_it, &tree);
2918 const token = nextToken(&tok_it, tree);
29182919 const token_index = token.index;
29192920 const token_ptr = token.ptr;
2920 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) orelse {
2921 prevToken(&tok_it, &tree);
2921 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, tree)) orelse {
2922 prevToken(&tok_it, tree);
29222923 if (opt_ctx != OptionalCtx.Optional) {
29232924 ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token_index } };
29242925 return tree;
......@@ -2929,13 +2930,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
29292930 },
29302931
29312932 State.Identifier => |opt_ctx| {
2932 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |ident_token| {
2933 if (eatToken(&tok_it, tree, Token.Id.Identifier)) |ident_token| {
29332934 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.Identifier, ident_token);
29342935 continue;
29352936 }
29362937
29372938 if (opt_ctx != OptionalCtx.Optional) {
2938 const token = nextToken(&tok_it, &tree);
2939 const token = nextToken(&tok_it, tree);
29392940 const token_index = token.index;
29402941 const token_ptr = token.ptr;
29412942 ((try tree.errors.addOne())).* = Error{
......@@ -2949,8 +2950,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
29492950 },
29502951
29512952 State.ErrorTag => |node_ptr| {
2952 const comments = try eatDocComments(arena, &tok_it, &tree);
2953 const ident_token = nextToken(&tok_it, &tree);
2953 const comments = try eatDocComments(arena, &tok_it, tree);
2954 const ident_token = nextToken(&tok_it, tree);
29542955 const ident_token_index = ident_token.index;
29552956 const ident_token_ptr = ident_token.ptr;
29562957 if (ident_token_ptr.id != Token.Id.Identifier) {
......@@ -2974,7 +2975,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
29742975 },
29752976
29762977 State.ExpectToken => |token_id| {
2977 const token = nextToken(&tok_it, &tree);
2978 const token = nextToken(&tok_it, tree);
29782979 const token_index = token.index;
29792980 const token_ptr = token.ptr;
29802981 if (token_ptr.id != token_id) {
......@@ -2989,7 +2990,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
29892990 continue;
29902991 },
29912992 State.ExpectTokenSave => |expect_token_save| {
2992 const token = nextToken(&tok_it, &tree);
2993 const token = nextToken(&tok_it, tree);
29932994 const token_index = token.index;
29942995 const token_ptr = token.ptr;
29952996 if (token_ptr.id != expect_token_save.id) {
......@@ -3005,7 +3006,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
30053006 continue;
30063007 },
30073008 State.IfToken => |token_id| {
3008 if (eatToken(&tok_it, &tree, token_id)) |_| {
3009 if (eatToken(&tok_it, tree, token_id)) |_| {
30093010 continue;
30103011 }
30113012
......@@ -3013,7 +3014,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
30133014 continue;
30143015 },
30153016 State.IfTokenSave => |if_token_save| {
3016 if (eatToken(&tok_it, &tree, if_token_save.id)) |token_index| {
3017 if (eatToken(&tok_it, tree, if_token_save.id)) |token_index| {
30173018 (if_token_save.ptr).* = token_index;
30183019 continue;
30193020 }
......@@ -3022,7 +3023,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
30223023 continue;
30233024 },
30243025 State.OptionalTokenSave => |optional_token_save| {
3025 if (eatToken(&tok_it, &tree, optional_token_save.id)) |token_index| {
3026 if (eatToken(&tok_it, tree, optional_token_save.id)) |token_index| {
30263027 (optional_token_save.ptr).* = token_index;
30273028 continue;
30283029 }
std/zig/parser_test.zig+2-2
......@@ -2137,7 +2137,7 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
21372137 var stderr_file = try io.getStdErr();
21382138 var stderr = &stderr_file.outStream().stream;
21392139
2140 var tree = try std.zig.parse(allocator, source);
2140 const tree = try std.zig.parse(allocator, source);
21412141 defer tree.deinit();
21422142
21432143 var error_it = tree.errors.iterator(0);
......@@ -2170,7 +2170,7 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
21702170 errdefer buffer.deinit();
21712171
21722172 var buffer_out_stream = io.BufferOutStream.init(&buffer);
2173 anything_changed.* = try std.zig.render(allocator, &buffer_out_stream.stream, &tree);
2173 anything_changed.* = try std.zig.render(allocator, &buffer_out_stream.stream, tree);
21742174 return buffer.toOwnedSlice();
21752175}
21762176