| ... | @@ -1891,12 +1891,13 @@ pub const Parser = struct { | ... | @@ -1891,12 +1891,13 @@ pub const Parser = struct { |
| 1891 | } | 1891 | } |
| 1892 | ); | 1892 | ); |
| 1893 | | 1893 | |
| 1894 | stack.append(State { | 1894 | stack.append(State {.LookForSameLineCommentDirect = &node.base }) catch unreachable; |
| | 1895 | try stack.append(State { |
| 1895 | .ExpectTokenSave = ExpectTokenSave { | 1896 | .ExpectTokenSave = ExpectTokenSave { |
| 1896 | .id = Token.Id.Pipe, | 1897 | .id = Token.Id.Pipe, |
| 1897 | .ptr = &node.rpipe, | 1898 | .ptr = &node.rpipe, |
| 1898 | } | 1899 | } |
| 1899 | }) catch unreachable; | 1900 | }); |
| 1900 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } }); | 1901 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } }); |
| 1901 | try stack.append(State { | 1902 | try stack.append(State { |
| 1902 | .OptionalTokenSave = OptionalTokenSave { | 1903 | .OptionalTokenSave = OptionalTokenSave { |
| ... | @@ -3122,6 +3123,7 @@ pub const Parser = struct { | ... | @@ -3122,6 +3123,7 @@ pub const Parser = struct { |
| 3122 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 3123 | stack.append(State { .Else = &node.@"else" }) catch unreachable; |
| 3123 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 3124 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); |
| 3124 | try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } }); | 3125 | try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } }); |
| | 3126 | try stack.append(State { .LookForSameLineComment = &node.condition }); |
| 3125 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 3127 | try stack.append(State { .ExpectToken = Token.Id.RParen }); |
| 3126 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } }); | 3128 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } }); |
| 3127 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 3129 | try stack.append(State { .ExpectToken = Token.Id.LParen }); |
| ... | @@ -3460,6 +3462,7 @@ pub const Parser = struct { | ... | @@ -3460,6 +3462,7 @@ pub const Parser = struct { |
| 3460 | PrintIndent, | 3462 | PrintIndent, |
| 3461 | Indent: usize, | 3463 | Indent: usize, |
| 3462 | PrintSameLineComment: ?&Token, | 3464 | PrintSameLineComment: ?&Token, |
| | 3465 | PrintLineComment: &Token, |
| 3463 | }; | 3466 | }; |
| 3464 | | 3467 | |
| 3465 | pub fn renderSource(self: &Parser, stream: var, root_node: &ast.Node.Root) !void { | 3468 | pub fn renderSource(self: &Parser, stream: var, root_node: &ast.Node.Root) !void { |
| ... | @@ -4517,7 +4520,18 @@ pub const Parser = struct { | ... | @@ -4517,7 +4520,18 @@ pub const Parser = struct { |
| 4517 | } | 4520 | } |
| 4518 | } | 4521 | } |
| 4519 | | 4522 | |
| 4520 | try stack.append(RenderState { .Expression = if_node.body }); | 4523 | if (if_node.condition.same_line_comment) |comment| { |
| | 4524 | try stack.append(RenderState { .Indent = indent }); |
| | 4525 | try stack.append(RenderState { .Expression = if_node.body }); |
| | 4526 | try stack.append(RenderState.PrintIndent); |
| | 4527 | try stack.append(RenderState { .Indent = indent + indent_delta }); |
| | 4528 | try stack.append(RenderState { .Text = "\n" }); |
| | 4529 | try stack.append(RenderState { .PrintLineComment = comment }); |
| | 4530 | } else { |
| | 4531 | try stack.append(RenderState { .Expression = if_node.body }); |
| | 4532 | } |
| | 4533 | |
| | 4534 | |
| 4521 | try stack.append(RenderState { .Text = " " }); | 4535 | try stack.append(RenderState { .Text = " " }); |
| 4522 | | 4536 | |
| 4523 | if (if_node.payload) |payload| { | 4537 | if (if_node.payload) |payload| { |
| ... | @@ -4678,6 +4692,9 @@ pub const Parser = struct { | ... | @@ -4678,6 +4692,9 @@ pub const Parser = struct { |
| 4678 | const comment_token = maybe_comment ?? break :blk; | 4692 | const comment_token = maybe_comment ?? break :blk; |
| 4679 | try stream.print(" {}", self.tokenizer.getTokenSlice(comment_token)); | 4693 | try stream.print(" {}", self.tokenizer.getTokenSlice(comment_token)); |
| 4680 | }, | 4694 | }, |
| | 4695 | RenderState.PrintLineComment => |comment_token| { |
| | 4696 | try stream.write(self.tokenizer.getTokenSlice(comment_token)); |
| | 4697 | }, |
| 4681 | } | 4698 | } |
| 4682 | } | 4699 | } |
| 4683 | } | 4700 | } |