| ... | @@ -230,6 +230,7 @@ pub const Parser = struct { | ... | @@ -230,6 +230,7 @@ pub const Parser = struct { |
| 230 | Semicolon: &&ast.Node, | 230 | Semicolon: &&ast.Node, |
| 231 | AddComments: AddCommentsCtx, | 231 | AddComments: AddCommentsCtx, |
| 232 | LookForSameLineComment: &&ast.Node, | 232 | LookForSameLineComment: &&ast.Node, |
| | 233 | LookForSameLineCommentDirect: &ast.Node, |
| 233 | | 234 | |
| 234 | AsmOutputItems: &ArrayList(&ast.Node.AsmOutput), | 235 | AsmOutputItems: &ArrayList(&ast.Node.AsmOutput), |
| 235 | AsmOutputReturnOrType: &ast.Node.AsmOutput, | 236 | AsmOutputReturnOrType: &ast.Node.AsmOutput, |
| ... | @@ -532,7 +533,7 @@ pub const Parser = struct { | ... | @@ -532,7 +533,7 @@ pub const Parser = struct { |
| 532 | } | 533 | } |
| 533 | } | 534 | } |
| 534 | | 535 | |
| 535 | stack.append(State { | 536 | try stack.append(State { |
| 536 | .VarDecl = VarDeclCtx { | 537 | .VarDecl = VarDeclCtx { |
| 537 | .comments = ctx.comments, | 538 | .comments = ctx.comments, |
| 538 | .visib_token = ctx.visib_token, | 539 | .visib_token = ctx.visib_token, |
| ... | @@ -542,7 +543,7 @@ pub const Parser = struct { | ... | @@ -542,7 +543,7 @@ pub const Parser = struct { |
| 542 | .mut_token = token, | 543 | .mut_token = token, |
| 543 | .list = ctx.decls | 544 | .list = ctx.decls |
| 544 | } | 545 | } |
| 545 | }) catch unreachable; | 546 | }); |
| 546 | continue; | 547 | continue; |
| 547 | }, | 548 | }, |
| 548 | Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, | 549 | Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, |
| ... | @@ -705,6 +706,7 @@ pub const Parser = struct { | ... | @@ -705,6 +706,7 @@ pub const Parser = struct { |
| 705 | continue; | 706 | continue; |
| 706 | }, | 707 | }, |
| 707 | State.ContainerDecl => |container_decl| { | 708 | State.ContainerDecl => |container_decl| { |
| | 709 | const comments = try self.eatComments(arena); |
| 708 | const token = self.getNextToken(); | 710 | const token = self.getNextToken(); |
| 709 | switch (token.id) { | 711 | switch (token.id) { |
| 710 | Token.Id.Identifier => { | 712 | Token.Id.Identifier => { |
| ... | @@ -713,7 +715,7 @@ pub const Parser = struct { | ... | @@ -713,7 +715,7 @@ pub const Parser = struct { |
| 713 | const node = try arena.construct(ast.Node.StructField { | 715 | const node = try arena.construct(ast.Node.StructField { |
| 714 | .base = ast.Node { | 716 | .base = ast.Node { |
| 715 | .id = ast.Node.Id.StructField, | 717 | .id = ast.Node.Id.StructField, |
| 716 | .before_comments = null, | 718 | .before_comments = comments, |
| 717 | .same_line_comment = null, | 719 | .same_line_comment = null, |
| 718 | }, | 720 | }, |
| 719 | .visib_token = null, | 721 | .visib_token = null, |
| ... | @@ -765,7 +767,7 @@ pub const Parser = struct { | ... | @@ -765,7 +767,7 @@ pub const Parser = struct { |
| 765 | .TopLevelExternOrField = TopLevelExternOrFieldCtx { | 767 | .TopLevelExternOrField = TopLevelExternOrFieldCtx { |
| 766 | .visib_token = token, | 768 | .visib_token = token, |
| 767 | .container_decl = container_decl, | 769 | .container_decl = container_decl, |
| 768 | .comments = null, | 770 | .comments = comments, |
| 769 | } | 771 | } |
| 770 | }); | 772 | }); |
| 771 | continue; | 773 | continue; |
| ... | @@ -778,7 +780,7 @@ pub const Parser = struct { | ... | @@ -778,7 +780,7 @@ pub const Parser = struct { |
| 778 | .visib_token = token, | 780 | .visib_token = token, |
| 779 | .extern_export_inline_token = null, | 781 | .extern_export_inline_token = null, |
| 780 | .lib_name = null, | 782 | .lib_name = null, |
| 781 | .comments = null, | 783 | .comments = comments, |
| 782 | } | 784 | } |
| 783 | }); | 785 | }); |
| 784 | continue; | 786 | continue; |
| ... | @@ -793,7 +795,7 @@ pub const Parser = struct { | ... | @@ -793,7 +795,7 @@ pub const Parser = struct { |
| 793 | .visib_token = token, | 795 | .visib_token = token, |
| 794 | .extern_export_inline_token = null, | 796 | .extern_export_inline_token = null, |
| 795 | .lib_name = null, | 797 | .lib_name = null, |
| 796 | .comments = null, | 798 | .comments = comments, |
| 797 | } | 799 | } |
| 798 | }); | 800 | }); |
| 799 | continue; | 801 | continue; |
| ... | @@ -811,7 +813,7 @@ pub const Parser = struct { | ... | @@ -811,7 +813,7 @@ pub const Parser = struct { |
| 811 | .visib_token = null, | 813 | .visib_token = null, |
| 812 | .extern_export_inline_token = null, | 814 | .extern_export_inline_token = null, |
| 813 | .lib_name = null, | 815 | .lib_name = null, |
| 814 | .comments = null, | 816 | .comments = comments, |
| 815 | } | 817 | } |
| 816 | }); | 818 | }); |
| 817 | continue; | 819 | continue; |
| ... | @@ -842,7 +844,8 @@ pub const Parser = struct { | ... | @@ -842,7 +844,8 @@ pub const Parser = struct { |
| 842 | }); | 844 | }); |
| 843 | try ctx.list.append(&var_decl.base); | 845 | try ctx.list.append(&var_decl.base); |
| 844 | | 846 | |
| 845 | stack.append(State { .VarDeclAlign = var_decl }) catch unreachable; | 847 | try stack.append(State { .LookForSameLineCommentDirect = &var_decl.base }); |
| | 848 | try stack.append(State { .VarDeclAlign = var_decl }); |
| 846 | try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &var_decl.type_node} }); | 849 | try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &var_decl.type_node} }); |
| 847 | try stack.append(State { .IfToken = Token.Id.Colon }); | 850 | try stack.append(State { .IfToken = Token.Id.Colon }); |
| 848 | try stack.append(State { | 851 | try stack.append(State { |
| ... | @@ -854,7 +857,7 @@ pub const Parser = struct { | ... | @@ -854,7 +857,7 @@ pub const Parser = struct { |
| 854 | continue; | 857 | continue; |
| 855 | }, | 858 | }, |
| 856 | State.VarDeclAlign => |var_decl| { | 859 | State.VarDeclAlign => |var_decl| { |
| 857 | stack.append(State { .VarDeclEq = var_decl }) catch unreachable; | 860 | try stack.append(State { .VarDeclEq = var_decl }); |
| 858 | | 861 | |
| 859 | const next_token = self.getNextToken(); | 862 | const next_token = self.getNextToken(); |
| 860 | if (next_token.id == Token.Id.Keyword_align) { | 863 | if (next_token.id == Token.Id.Keyword_align) { |
| ... | @@ -1348,6 +1351,11 @@ pub const Parser = struct { | ... | @@ -1348,6 +1351,11 @@ pub const Parser = struct { |
| 1348 | continue; | 1351 | continue; |
| 1349 | }, | 1352 | }, |
| 1350 | | 1353 | |
| | 1354 | State.LookForSameLineCommentDirect => |node| { |
| | 1355 | try self.lookForSameLineComment(arena, node); |
| | 1356 | continue; |
| | 1357 | }, |
| | 1358 | |
| 1351 | | 1359 | |
| 1352 | State.AsmOutputItems => |items| { | 1360 | State.AsmOutputItems => |items| { |
| 1353 | const lbracket = self.getNextToken(); | 1361 | const lbracket = self.getNextToken(); |