| ... | @@ -1517,8 +1517,15 @@ pub const Parser = struct { | ... | @@ -1517,8 +1517,15 @@ pub const Parser = struct { |
| 1517 | continue; | 1517 | continue; |
| 1518 | } | 1518 | } |
| 1519 | | 1519 | |
| 1520 | stack.append(State { .IdentifierListCommaOrEnd = list_state }) catch unreachable; | 1520 | const comments = try self.eatComments(arena); |
| 1521 | try stack.append(State { .Identifier = OptionalCtx { .Required = try list_state.list.addOne() } }); | 1521 | const node_ptr = try list_state.list.addOne(); |
| | 1522 | |
| | 1523 | try stack.append(State { .AddComments = AddCommentsCtx { |
| | 1524 | .node_ptr = node_ptr, |
| | 1525 | .comments = comments, |
| | 1526 | }}); |
| | 1527 | try stack.append(State { .IdentifierListCommaOrEnd = list_state }); |
| | 1528 | try stack.append(State { .Identifier = OptionalCtx { .Required = node_ptr } }); |
| 1522 | continue; | 1529 | continue; |
| 1523 | }, | 1530 | }, |
| 1524 | State.IdentifierListCommaOrEnd => |list_state| { | 1531 | State.IdentifierListCommaOrEnd => |list_state| { |
| ... | @@ -2739,14 +2746,17 @@ pub const Parser = struct { | ... | @@ -2739,14 +2746,17 @@ pub const Parser = struct { |
| 2739 | continue; | 2746 | continue; |
| 2740 | } | 2747 | } |
| 2741 | | 2748 | |
| 2742 | const node = try self.createToCtxNode(arena, ctx.opt_ctx, ast.Node.ErrorSetDecl, | 2749 | const node = try arena.construct(ast.Node.ErrorSetDecl { |
| 2743 | ast.Node.ErrorSetDecl { | 2750 | .base = ast.Node { |
| 2744 | .base = undefined, | 2751 | .id = ast.Node.Id.ErrorSetDecl, |
| 2745 | .error_token = ctx.error_token, | 2752 | .before_comments = null, |
| 2746 | .decls = ArrayList(&ast.Node).init(arena), | 2753 | .same_line_comment = null, |
| 2747 | .rbrace_token = undefined, | 2754 | }, |
| 2748 | } | 2755 | .error_token = ctx.error_token, |
| 2749 | ); | 2756 | .decls = ArrayList(&ast.Node).init(arena), |
| | 2757 | .rbrace_token = undefined, |
| | 2758 | }); |
| | 2759 | ctx.opt_ctx.store(&node.base); |
| 2750 | | 2760 | |
| 2751 | stack.append(State { | 2761 | stack.append(State { |
| 2752 | .IdentifierListItemOrEnd = ListSave(&ast.Node) { | 2762 | .IdentifierListItemOrEnd = ListSave(&ast.Node) { |
| ... | @@ -3337,6 +3347,7 @@ pub const Parser = struct { | ... | @@ -3337,6 +3347,7 @@ pub const Parser = struct { |
| 3337 | PrintIndent, | 3347 | PrintIndent, |
| 3338 | Indent: usize, | 3348 | Indent: usize, |
| 3339 | PrintSameLineComment: ?&Token, | 3349 | PrintSameLineComment: ?&Token, |
| | 3350 | PrintComments: &ast.Node, |
| 3340 | }; | 3351 | }; |
| 3341 | | 3352 | |
| 3342 | pub fn renderSource(self: &Parser, stream: var, root_node: &ast.Node.Root) !void { | 3353 | pub fn renderSource(self: &Parser, stream: var, root_node: &ast.Node.Root) !void { |
| ... | @@ -3978,6 +3989,7 @@ pub const Parser = struct { | ... | @@ -3978,6 +3989,7 @@ pub const Parser = struct { |
| 3978 | const node = decls[i]; | 3989 | const node = decls[i]; |
| 3979 | try stack.append(RenderState { .Text = "," }); | 3990 | try stack.append(RenderState { .Text = "," }); |
| 3980 | try stack.append(RenderState { .Expression = node }); | 3991 | try stack.append(RenderState { .Expression = node }); |
| | 3992 | try stack.append(RenderState { .PrintComments = node }); |
| 3981 | try stack.append(RenderState.PrintIndent); | 3993 | try stack.append(RenderState.PrintIndent); |
| 3982 | try stack.append(RenderState { | 3994 | try stack.append(RenderState { |
| 3983 | .Text = blk: { | 3995 | .Text = blk: { |
| ... | @@ -4466,6 +4478,10 @@ pub const Parser = struct { | ... | @@ -4466,6 +4478,10 @@ pub const Parser = struct { |
| 4466 | const comment_token = maybe_comment ?? break :blk; | 4478 | const comment_token = maybe_comment ?? break :blk; |
| 4467 | try stream.print(" {}", self.tokenizer.getTokenSlice(comment_token)); | 4479 | try stream.print(" {}", self.tokenizer.getTokenSlice(comment_token)); |
| 4468 | }, | 4480 | }, |
| | 4481 | |
| | 4482 | RenderState.PrintComments => |node| blk: { |
| | 4483 | try self.renderComments(stream, node, indent); |
| | 4484 | }, |
| 4469 | } | 4485 | } |
| 4470 | } | 4486 | } |
| 4471 | } | 4487 | } |