| ... | @@ -17,15 +17,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -17,15 +17,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 17 | defer stack.deinit(); | 17 | defer stack.deinit(); |
| 18 | | 18 | |
| 19 | const arena = &tree_arena.allocator; | 19 | const arena = &tree_arena.allocator; |
| 20 | const root_node = try createNode(arena, ast.Node.Root, | 20 | const root_node = try arena.construct(ast.Node.Root { |
| 21 | ast.Node.Root { | 21 | .base = ast.Node { .id = ast.Node.Id.Root }, |
| 22 | .base = undefined, | 22 | .decls = ast.Node.Root.DeclList.init(arena), |
| 23 | .decls = ast.Node.Root.DeclList.init(arena), | 23 | .doc_comments = null, |
| 24 | .doc_comments = null, | 24 | // initialized when we get the eof token |
| 25 | // initialized when we get the eof token | 25 | .eof_token = undefined, |
| 26 | .eof_token = undefined, | 26 | }); |
| 27 | } | | |
| 28 | ); | | |
| 29 | | 27 | |
| 30 | var tree = ast.Tree { | 28 | var tree = ast.Tree { |
| 31 | .source = source, | 29 | .source = source, |
| ... | @@ -113,15 +111,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -113,15 +111,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 113 | continue; | 111 | continue; |
| 114 | }, | 112 | }, |
| 115 | Token.Id.Keyword_comptime => { | 113 | Token.Id.Keyword_comptime => { |
| 116 | const block = try createNode(arena, ast.Node.Block, | 114 | const block = try arena.construct(ast.Node.Block { |
| 117 | ast.Node.Block { | 115 | .base = ast.Node {.id = ast.Node.Id.Block }, |
| 118 | .base = undefined, | 116 | .label = null, |
| 119 | .label = null, | 117 | .lbrace = undefined, |
| 120 | .lbrace = undefined, | 118 | .statements = ast.Node.Block.StatementList.init(arena), |
| 121 | .statements = ast.Node.Block.StatementList.init(arena), | 119 | .rbrace = undefined, |
| 122 | .rbrace = undefined, | 120 | }); |
| 123 | } | | |
| 124 | ); | | |
| 125 | const node = try arena.construct(ast.Node.Comptime { | 121 | const node = try arena.construct(ast.Node.Comptime { |
| 126 | .base = ast.Node { | 122 | .base = ast.Node { |
| 127 | .id = ast.Node.Id.Comptime, | 123 | .id = ast.Node.Id.Comptime, |
| ... | @@ -312,14 +308,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -312,14 +308,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 312 | continue; | 308 | continue; |
| 313 | }, | 309 | }, |
| 314 | Token.Id.Keyword_async => { | 310 | Token.Id.Keyword_async => { |
| 315 | const async_node = try createNode(arena, ast.Node.AsyncAttribute, | 311 | const async_node = try arena.construct(ast.Node.AsyncAttribute { |
| 316 | ast.Node.AsyncAttribute { | 312 | .base = ast.Node {.id = ast.Node.Id.AsyncAttribute }, |
| 317 | .base = undefined, | 313 | .async_token = token_index, |
| 318 | .async_token = token_index, | 314 | .allocator_type = null, |
| 319 | .allocator_type = null, | 315 | .rangle_bracket = null, |
| 320 | .rangle_bracket = null, | 316 | }); |
| 321 | } | | |
| 322 | ); | | |
| 323 | fn_proto.async_attr = async_node; | 317 | fn_proto.async_attr = async_node; |
| 324 | | 318 | |
| 325 | try stack.append(State { | 319 | try stack.append(State { |
| ... | @@ -396,27 +390,26 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -396,27 +390,26 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 396 | const token = nextToken(&tok_it, &tree); | 390 | const token = nextToken(&tok_it, &tree); |
| 397 | const token_index = token.index; | 391 | const token_index = token.index; |
| 398 | const token_ptr = token.ptr; | 392 | const token_ptr = token.ptr; |
| 399 | const node = try createToCtxNode(arena, ctx.opt_ctx, ast.Node.ContainerDecl, | 393 | const node = try arena.construct(ast.Node.ContainerDecl { |
| 400 | ast.Node.ContainerDecl { | 394 | .base = ast.Node {.id = ast.Node.Id.ContainerDecl }, |
| 401 | .base = undefined, | 395 | .ltoken = ctx.ltoken, |
| 402 | .ltoken = ctx.ltoken, | 396 | .layout = ctx.layout, |
| 403 | .layout = ctx.layout, | 397 | .kind = switch (token_ptr.id) { |
| 404 | .kind = switch (token_ptr.id) { | 398 | Token.Id.Keyword_struct => ast.Node.ContainerDecl.Kind.Struct, |
| 405 | Token.Id.Keyword_struct => ast.Node.ContainerDecl.Kind.Struct, | 399 | Token.Id.Keyword_union => ast.Node.ContainerDecl.Kind.Union, |
| 406 | Token.Id.Keyword_union => ast.Node.ContainerDecl.Kind.Union, | 400 | Token.Id.Keyword_enum => ast.Node.ContainerDecl.Kind.Enum, |
| 407 | Token.Id.Keyword_enum => ast.Node.ContainerDecl.Kind.Enum, | 401 | else => { |
| 408 | else => { | 402 | *(try tree.errors.addOne()) = Error { |
| 409 | *(try tree.errors.addOne()) = Error { | 403 | .ExpectedAggregateKw = Error.ExpectedAggregateKw { .token = token_index }, |
| 410 | .ExpectedAggregateKw = Error.ExpectedAggregateKw { .token = token_index }, | 404 | }; |
| 411 | }; | 405 | return tree; |
| 412 | return tree; | | |
| 413 | }, | | |
| 414 | }, | 406 | }, |
| 415 | .init_arg_expr = ast.Node.ContainerDecl.InitArg.None, | 407 | }, |
| 416 | .fields_and_decls = ast.Node.ContainerDecl.DeclList.init(arena), | 408 | .init_arg_expr = ast.Node.ContainerDecl.InitArg.None, |
| 417 | .rbrace_token = undefined, | 409 | .fields_and_decls = ast.Node.ContainerDecl.DeclList.init(arena), |
| 418 | } | 410 | .rbrace_token = undefined, |
| 419 | ); | 411 | }); |
| | 412 | ctx.opt_ctx.store(&node.base); |
| 420 | | 413 | |
| 421 | stack.append(State { .ContainerDecl = node }) catch unreachable; | 414 | stack.append(State { .ContainerDecl = node }) catch unreachable; |
| 422 | try stack.append(State { .ExpectToken = Token.Id.LBrace }); | 415 | try stack.append(State { .ExpectToken = Token.Id.LBrace }); |
| ... | @@ -844,15 +837,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -844,15 +837,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 844 | const token_ptr = token.ptr; | 837 | const token_ptr = token.ptr; |
| 845 | switch (token_ptr.id) { | 838 | switch (token_ptr.id) { |
| 846 | Token.Id.LBrace => { | 839 | Token.Id.LBrace => { |
| 847 | const block = try createToCtxNode(arena, ctx.opt_ctx, ast.Node.Block, | 840 | const block = try arena.construct(ast.Node.Block { |
| 848 | ast.Node.Block { | 841 | .base = ast.Node {.id = ast.Node.Id.Block}, |
| 849 | .base = undefined, | 842 | .label = ctx.label, |
| 850 | .label = ctx.label, | 843 | .lbrace = token_index, |
| 851 | .lbrace = token_index, | 844 | .statements = ast.Node.Block.StatementList.init(arena), |
| 852 | .statements = ast.Node.Block.StatementList.init(arena), | 845 | .rbrace = undefined, |
| 853 | .rbrace = undefined, | 846 | }); |
| 854 | } | 847 | ctx.opt_ctx.store(&block.base); |
| 855 | ); | | |
| 856 | stack.append(State { .Block = block }) catch unreachable; | 848 | stack.append(State { .Block = block }) catch unreachable; |
| 857 | continue; | 849 | continue; |
| 858 | }, | 850 | }, |
| ... | @@ -957,19 +949,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -957,19 +949,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 957 | } | 949 | } |
| 958 | }, | 950 | }, |
| 959 | State.While => |ctx| { | 951 | State.While => |ctx| { |
| 960 | const node = try createToCtxNode(arena, ctx.opt_ctx, ast.Node.While, | 952 | const node = try arena.construct(ast.Node.While { |
| 961 | ast.Node.While { | 953 | .base = ast.Node {.id = ast.Node.Id.While }, |
| 962 | .base = undefined, | 954 | .label = ctx.label, |
| 963 | .label = ctx.label, | 955 | .inline_token = ctx.inline_token, |
| 964 | .inline_token = ctx.inline_token, | 956 | .while_token = ctx.loop_token, |
| 965 | .while_token = ctx.loop_token, | 957 | .condition = undefined, |
| 966 | .condition = undefined, | 958 | .payload = null, |
| 967 | .payload = null, | 959 | .continue_expr = null, |
| 968 | .continue_expr = null, | 960 | .body = undefined, |
| 969 | .body = undefined, | 961 | .@"else" = null, |
| 970 | .@"else" = null, | 962 | }); |
| 971 | } | 963 | ctx.opt_ctx.store(&node.base); |
| 972 | ); | | |
| 973 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 964 | stack.append(State { .Else = &node.@"else" }) catch unreachable; |
| 974 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 965 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); |
| 975 | try stack.append(State { .WhileContinueExpr = &node.continue_expr }); | 966 | try stack.append(State { .WhileContinueExpr = &node.continue_expr }); |
| ... | @@ -987,18 +978,17 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -987,18 +978,17 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 987 | continue; | 978 | continue; |
| 988 | }, | 979 | }, |
| 989 | State.For => |ctx| { | 980 | State.For => |ctx| { |
| 990 | const node = try createToCtxNode(arena, ctx.opt_ctx, ast.Node.For, | 981 | const node = try arena.construct(ast.Node.For { |
| 991 | ast.Node.For { | 982 | .base = ast.Node {.id = ast.Node.Id.For }, |
| 992 | .base = undefined, | 983 | .label = ctx.label, |
| 993 | .label = ctx.label, | 984 | .inline_token = ctx.inline_token, |
| 994 | .inline_token = ctx.inline_token, | 985 | .for_token = ctx.loop_token, |
| 995 | .for_token = ctx.loop_token, | 986 | .array_expr = undefined, |
| 996 | .array_expr = undefined, | 987 | .payload = null, |
| 997 | .payload = null, | 988 | .body = undefined, |
| 998 | .body = undefined, | 989 | .@"else" = null, |
| 999 | .@"else" = null, | 990 | }); |
| 1000 | } | 991 | ctx.opt_ctx.store(&node.base); |
| 1001 | ); | | |
| 1002 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 992 | stack.append(State { .Else = &node.@"else" }) catch unreachable; |
| 1003 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 993 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); |
| 1004 | try stack.append(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } }); | 994 | try stack.append(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } }); |
| ... | @@ -1009,14 +999,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1009,14 +999,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1009 | }, | 999 | }, |
| 1010 | State.Else => |dest| { | 1000 | State.Else => |dest| { |
| 1011 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { | 1001 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 1012 | const node = try createNode(arena, ast.Node.Else, | 1002 | const node = try arena.construct(ast.Node.Else { |
| 1013 | ast.Node.Else { | 1003 | .base = ast.Node {.id = ast.Node.Id.Else }, |
| 1014 | .base = undefined, | 1004 | .else_token = else_token, |
| 1015 | .else_token = else_token, | 1005 | .payload = null, |
| 1016 | .payload = null, | 1006 | .body = undefined, |
| 1017 | .body = undefined, | 1007 | }); |
| 1018 | } | | |
| 1019 | ); | | |
| 1020 | *dest = node; | 1008 | *dest = node; |
| 1021 | | 1009 | |
| 1022 | stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable; | 1010 | stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable; |
| ... | @@ -1170,14 +1158,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1170,14 +1158,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1170 | continue; | 1158 | continue; |
| 1171 | } | 1159 | } |
| 1172 | | 1160 | |
| 1173 | const node = try createNode(arena, ast.Node.AsmOutput, | 1161 | const node = try arena.construct(ast.Node.AsmOutput { |
| 1174 | ast.Node.AsmOutput { | 1162 | .base = ast.Node {.id = ast.Node.Id.AsmOutput }, |
| 1175 | .base = undefined, | 1163 | .symbolic_name = undefined, |
| 1176 | .symbolic_name = undefined, | 1164 | .constraint = undefined, |
| 1177 | .constraint = undefined, | 1165 | .kind = undefined, |
| 1178 | .kind = undefined, | 1166 | }); |
| 1179 | } | | |
| 1180 | ); | | |
| 1181 | try items.push(node); | 1167 | try items.push(node); |
| 1182 | | 1168 | |
| 1183 | stack.append(State { .AsmOutputItems = items }) catch unreachable; | 1169 | stack.append(State { .AsmOutputItems = items }) catch unreachable; |
| ... | @@ -1223,14 +1209,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1223,14 +1209,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1223 | continue; | 1209 | continue; |
| 1224 | } | 1210 | } |
| 1225 | | 1211 | |
| 1226 | const node = try createNode(arena, ast.Node.AsmInput, | 1212 | const node = try arena.construct(ast.Node.AsmInput { |
| 1227 | ast.Node.AsmInput { | 1213 | .base = ast.Node {.id = ast.Node.Id.AsmInput }, |
| 1228 | .base = undefined, | 1214 | .symbolic_name = undefined, |
| 1229 | .symbolic_name = undefined, | 1215 | .constraint = undefined, |
| 1230 | .constraint = undefined, | 1216 | .expr = undefined, |
| 1231 | .expr = undefined, | 1217 | }); |
| 1232 | } | | |
| 1233 | ); | | |
| 1234 | try items.push(node); | 1218 | try items.push(node); |
| 1235 | | 1219 | |
| 1236 | stack.append(State { .AsmInputItems = items }) catch unreachable; | 1220 | stack.append(State { .AsmInputItems = items }) catch unreachable; |
| ... | @@ -1668,14 +1652,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1668,14 +1652,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1668 | continue; | 1652 | continue; |
| 1669 | } | 1653 | } |
| 1670 | | 1654 | |
| 1671 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.Payload, | 1655 | const node = try arena.construct(ast.Node.Payload { |
| 1672 | ast.Node.Payload { | 1656 | .base = ast.Node {.id = ast.Node.Id.Payload }, |
| 1673 | .base = undefined, | 1657 | .lpipe = token_index, |
| 1674 | .lpipe = token_index, | 1658 | .error_symbol = undefined, |
| 1675 | .error_symbol = undefined, | 1659 | .rpipe = undefined |
| 1676 | .rpipe = undefined | 1660 | }); |
| 1677 | } | 1661 | opt_ctx.store(&node.base); |
| 1678 | ); | | |
| 1679 | | 1662 | |
| 1680 | stack.append(State { | 1663 | stack.append(State { |
| 1681 | .ExpectTokenSave = ExpectTokenSave { | 1664 | .ExpectTokenSave = ExpectTokenSave { |
| ... | @@ -1705,15 +1688,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1705,15 +1688,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1705 | continue; | 1688 | continue; |
| 1706 | } | 1689 | } |
| 1707 | | 1690 | |
| 1708 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PointerPayload, | 1691 | const node = try arena.construct(ast.Node.PointerPayload { |
| 1709 | ast.Node.PointerPayload { | 1692 | .base = ast.Node {.id = ast.Node.Id.PointerPayload }, |
| 1710 | .base = undefined, | 1693 | .lpipe = token_index, |
| 1711 | .lpipe = token_index, | 1694 | .ptr_token = null, |
| 1712 | .ptr_token = null, | 1695 | .value_symbol = undefined, |
| 1713 | .value_symbol = undefined, | 1696 | .rpipe = undefined |
| 1714 | .rpipe = undefined | 1697 | }); |
| 1715 | } | 1698 | opt_ctx.store(&node.base); |
| 1716 | ); | | |
| 1717 | | 1699 | |
| 1718 | try stack.append(State { | 1700 | try stack.append(State { |
| 1719 | .ExpectTokenSave = ExpectTokenSave { | 1701 | .ExpectTokenSave = ExpectTokenSave { |
| ... | @@ -1749,16 +1731,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1749,16 +1731,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1749 | continue; | 1731 | continue; |
| 1750 | } | 1732 | } |
| 1751 | | 1733 | |
| 1752 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PointerIndexPayload, | 1734 | const node = try arena.construct(ast.Node.PointerIndexPayload { |
| 1753 | ast.Node.PointerIndexPayload { | 1735 | .base = ast.Node {.id = ast.Node.Id.PointerIndexPayload }, |
| 1754 | .base = undefined, | 1736 | .lpipe = token_index, |
| 1755 | .lpipe = token_index, | 1737 | .ptr_token = null, |
| 1756 | .ptr_token = null, | 1738 | .value_symbol = undefined, |
| 1757 | .value_symbol = undefined, | 1739 | .index_symbol = null, |
| 1758 | .index_symbol = null, | 1740 | .rpipe = undefined |
| 1759 | .rpipe = undefined | 1741 | }); |
| 1760 | } | 1742 | opt_ctx.store(&node.base); |
| 1761 | ); | | |
| 1762 | | 1743 | |
| 1763 | stack.append(State { | 1744 | stack.append(State { |
| 1764 | .ExpectTokenSave = ExpectTokenSave { | 1745 | .ExpectTokenSave = ExpectTokenSave { |
| ... | @@ -1785,14 +1766,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1785,14 +1766,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1785 | const token_ptr = token.ptr; | 1766 | const token_ptr = token.ptr; |
| 1786 | switch (token_ptr.id) { | 1767 | switch (token_ptr.id) { |
| 1787 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { | 1768 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { |
| 1788 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.ControlFlowExpression, | 1769 | const node = try arena.construct(ast.Node.ControlFlowExpression { |
| 1789 | ast.Node.ControlFlowExpression { | 1770 | .base = ast.Node {.id = ast.Node.Id.ControlFlowExpression }, |
| 1790 | .base = undefined, | 1771 | .ltoken = token_index, |
| 1791 | .ltoken = token_index, | 1772 | .kind = undefined, |
| 1792 | .kind = undefined, | 1773 | .rhs = null, |
| 1793 | .rhs = null, | 1774 | }); |
| 1794 | } | 1775 | opt_ctx.store(&node.base); |
| 1795 | ); | | |
| 1796 | | 1776 | |
| 1797 | stack.append(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable; | 1777 | stack.append(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable; |
| 1798 | | 1778 | |
| ... | @@ -1815,19 +1795,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1815,19 +1795,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1815 | continue; | 1795 | continue; |
| 1816 | }, | 1796 | }, |
| 1817 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { | 1797 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { |
| 1818 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PrefixOp, | 1798 | const node = try arena.construct(ast.Node.PrefixOp { |
| 1819 | ast.Node.PrefixOp { | 1799 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, |
| 1820 | .base = undefined, | 1800 | .op_token = token_index, |
| 1821 | .op_token = token_index, | 1801 | .op = switch (token_ptr.id) { |
| 1822 | .op = switch (token_ptr.id) { | 1802 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{} }, |
| 1823 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{} }, | 1803 | Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op { .Cancel = void{} }, |
| 1824 | Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op { .Cancel = void{} }, | 1804 | Token.Id.Keyword_resume => ast.Node.PrefixOp.Op { .Resume = void{} }, |
| 1825 | Token.Id.Keyword_resume => ast.Node.PrefixOp.Op { .Resume = void{} }, | 1805 | else => unreachable, |
| 1826 | else => unreachable, | 1806 | }, |
| 1827 | }, | 1807 | .rhs = undefined, |
| 1828 | .rhs = undefined, | 1808 | }); |
| 1829 | } | 1809 | opt_ctx.store(&node.base); |
| 1830 | ); | | |
| 1831 | | 1810 | |
| 1832 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 1811 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; |
| 1833 | continue; | 1812 | continue; |
| ... | @@ -1850,15 +1829,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1850,15 +1829,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1850 | const lhs = opt_ctx.get() ?? continue; | 1829 | const lhs = opt_ctx.get() ?? continue; |
| 1851 | | 1830 | |
| 1852 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { | 1831 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 1853 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1832 | const node = try arena.construct(ast.Node.InfixOp { |
| 1854 | ast.Node.InfixOp { | 1833 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1855 | .base = undefined, | 1834 | .lhs = lhs, |
| 1856 | .lhs = lhs, | 1835 | .op_token = ellipsis3, |
| 1857 | .op_token = ellipsis3, | 1836 | .op = ast.Node.InfixOp.Op.Range, |
| 1858 | .op = ast.Node.InfixOp.Op.Range, | 1837 | .rhs = undefined, |
| 1859 | .rhs = undefined, | 1838 | }); |
| 1860 | } | 1839 | opt_ctx.store(&node.base); |
| 1861 | ); | | |
| 1862 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 1840 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; |
| 1863 | continue; | 1841 | continue; |
| 1864 | } | 1842 | } |
| ... | @@ -1876,15 +1854,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1876,15 +1854,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1876 | const token_index = token.index; | 1854 | const token_index = token.index; |
| 1877 | const token_ptr = token.ptr; | 1855 | const token_ptr = token.ptr; |
| 1878 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { | 1856 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { |
| 1879 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1857 | const node = try arena.construct(ast.Node.InfixOp { |
| 1880 | ast.Node.InfixOp { | 1858 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1881 | .base = undefined, | 1859 | .lhs = lhs, |
| 1882 | .lhs = lhs, | 1860 | .op_token = token_index, |
| 1883 | .op_token = token_index, | 1861 | .op = ass_id, |
| 1884 | .op = ass_id, | 1862 | .rhs = undefined, |
| 1885 | .rhs = undefined, | 1863 | }); |
| 1886 | } | 1864 | opt_ctx.store(&node.base); |
| 1887 | ); | | |
| 1888 | stack.append(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1865 | stack.append(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1889 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); | 1866 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); |
| 1890 | continue; | 1867 | continue; |
| ... | @@ -1907,15 +1884,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1907,15 +1884,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1907 | const token_index = token.index; | 1884 | const token_index = token.index; |
| 1908 | const token_ptr = token.ptr; | 1885 | const token_ptr = token.ptr; |
| 1909 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { | 1886 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { |
| 1910 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1887 | const node = try arena.construct(ast.Node.InfixOp { |
| 1911 | ast.Node.InfixOp { | 1888 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1912 | .base = undefined, | 1889 | .lhs = lhs, |
| 1913 | .lhs = lhs, | 1890 | .op_token = token_index, |
| 1914 | .op_token = token_index, | 1891 | .op = unwrap_id, |
| 1915 | .op = unwrap_id, | 1892 | .rhs = undefined, |
| 1916 | .rhs = undefined, | 1893 | }); |
| 1917 | } | 1894 | opt_ctx.store(&node.base); |
| 1918 | ); | | |
| 1919 | | 1895 | |
| 1920 | stack.append(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1896 | stack.append(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1921 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); | 1897 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); |
| ... | @@ -1940,15 +1916,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1940,15 +1916,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1940 | const lhs = opt_ctx.get() ?? continue; | 1916 | const lhs = opt_ctx.get() ?? continue; |
| 1941 | | 1917 | |
| 1942 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { | 1918 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 1943 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1919 | const node = try arena.construct(ast.Node.InfixOp { |
| 1944 | ast.Node.InfixOp { | 1920 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1945 | .base = undefined, | 1921 | .lhs = lhs, |
| 1946 | .lhs = lhs, | 1922 | .op_token = or_token, |
| 1947 | .op_token = or_token, | 1923 | .op = ast.Node.InfixOp.Op.BoolOr, |
| 1948 | .op = ast.Node.InfixOp.Op.BoolOr, | 1924 | .rhs = undefined, |
| 1949 | .rhs = undefined, | 1925 | }); |
| 1950 | } | 1926 | opt_ctx.store(&node.base); |
| 1951 | ); | | |
| 1952 | stack.append(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1927 | stack.append(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1953 | try stack.append(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1928 | try stack.append(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 1954 | continue; | 1929 | continue; |
| ... | @@ -1965,15 +1940,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1965,15 +1940,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1965 | const lhs = opt_ctx.get() ?? continue; | 1940 | const lhs = opt_ctx.get() ?? continue; |
| 1966 | | 1941 | |
| 1967 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { | 1942 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 1968 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1943 | const node = try arena.construct(ast.Node.InfixOp { |
| 1969 | ast.Node.InfixOp { | 1944 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1970 | .base = undefined, | 1945 | .lhs = lhs, |
| 1971 | .lhs = lhs, | 1946 | .op_token = and_token, |
| 1972 | .op_token = and_token, | 1947 | .op = ast.Node.InfixOp.Op.BoolAnd, |
| 1973 | .op = ast.Node.InfixOp.Op.BoolAnd, | 1948 | .rhs = undefined, |
| 1974 | .rhs = undefined, | 1949 | }); |
| 1975 | } | 1950 | opt_ctx.store(&node.base); |
| 1976 | ); | | |
| 1977 | stack.append(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1951 | stack.append(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1978 | try stack.append(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1952 | try stack.append(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 1979 | continue; | 1953 | continue; |
| ... | @@ -1993,15 +1967,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1993,15 +1967,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1993 | const token_index = token.index; | 1967 | const token_index = token.index; |
| 1994 | const token_ptr = token.ptr; | 1968 | const token_ptr = token.ptr; |
| 1995 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { | 1969 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { |
| 1996 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1970 | const node = try arena.construct(ast.Node.InfixOp { |
| 1997 | ast.Node.InfixOp { | 1971 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1998 | .base = undefined, | 1972 | .lhs = lhs, |
| 1999 | .lhs = lhs, | 1973 | .op_token = token_index, |
| 2000 | .op_token = token_index, | 1974 | .op = comp_id, |
| 2001 | .op = comp_id, | 1975 | .rhs = undefined, |
| 2002 | .rhs = undefined, | 1976 | }); |
| 2003 | } | 1977 | opt_ctx.store(&node.base); |
| 2004 | ); | | |
| 2005 | stack.append(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1978 | stack.append(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2006 | try stack.append(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1979 | try stack.append(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2007 | continue; | 1980 | continue; |
| ... | @@ -2021,15 +1994,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2021,15 +1994,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2021 | const lhs = opt_ctx.get() ?? continue; | 1994 | const lhs = opt_ctx.get() ?? continue; |
| 2022 | | 1995 | |
| 2023 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { | 1996 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 2024 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1997 | const node = try arena.construct(ast.Node.InfixOp { |
| 2025 | ast.Node.InfixOp { | 1998 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2026 | .base = undefined, | 1999 | .lhs = lhs, |
| 2027 | .lhs = lhs, | 2000 | .op_token = pipe, |
| 2028 | .op_token = pipe, | 2001 | .op = ast.Node.InfixOp.Op.BitOr, |
| 2029 | .op = ast.Node.InfixOp.Op.BitOr, | 2002 | .rhs = undefined, |
| 2030 | .rhs = undefined, | 2003 | }); |
| 2031 | } | 2004 | opt_ctx.store(&node.base); |
| 2032 | ); | | |
| 2033 | stack.append(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2005 | stack.append(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2034 | try stack.append(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2006 | try stack.append(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2035 | continue; | 2007 | continue; |
| ... | @@ -2046,15 +2018,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2046,15 +2018,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2046 | const lhs = opt_ctx.get() ?? continue; | 2018 | const lhs = opt_ctx.get() ?? continue; |
| 2047 | | 2019 | |
| 2048 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { | 2020 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2049 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2021 | const node = try arena.construct(ast.Node.InfixOp { |
| 2050 | ast.Node.InfixOp { | 2022 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2051 | .base = undefined, | 2023 | .lhs = lhs, |
| 2052 | .lhs = lhs, | 2024 | .op_token = caret, |
| 2053 | .op_token = caret, | 2025 | .op = ast.Node.InfixOp.Op.BitXor, |
| 2054 | .op = ast.Node.InfixOp.Op.BitXor, | 2026 | .rhs = undefined, |
| 2055 | .rhs = undefined, | 2027 | }); |
| 2056 | } | 2028 | opt_ctx.store(&node.base); |
| 2057 | ); | | |
| 2058 | stack.append(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2029 | stack.append(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2059 | try stack.append(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2030 | try stack.append(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2060 | continue; | 2031 | continue; |
| ... | @@ -2071,15 +2042,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2071,15 +2042,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2071 | const lhs = opt_ctx.get() ?? continue; | 2042 | const lhs = opt_ctx.get() ?? continue; |
| 2072 | | 2043 | |
| 2073 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { | 2044 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2074 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2045 | const node = try arena.construct(ast.Node.InfixOp { |
| 2075 | ast.Node.InfixOp { | 2046 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2076 | .base = undefined, | 2047 | .lhs = lhs, |
| 2077 | .lhs = lhs, | 2048 | .op_token = ampersand, |
| 2078 | .op_token = ampersand, | 2049 | .op = ast.Node.InfixOp.Op.BitAnd, |
| 2079 | .op = ast.Node.InfixOp.Op.BitAnd, | 2050 | .rhs = undefined, |
| 2080 | .rhs = undefined, | 2051 | }); |
| 2081 | } | 2052 | opt_ctx.store(&node.base); |
| 2082 | ); | | |
| 2083 | stack.append(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2053 | stack.append(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2084 | try stack.append(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2054 | try stack.append(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2085 | continue; | 2055 | continue; |
| ... | @@ -2099,15 +2069,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2099,15 +2069,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2099 | const token_index = token.index; | 2069 | const token_index = token.index; |
| 2100 | const token_ptr = token.ptr; | 2070 | const token_ptr = token.ptr; |
| 2101 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { | 2071 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { |
| 2102 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2072 | const node = try arena.construct(ast.Node.InfixOp { |
| 2103 | ast.Node.InfixOp { | 2073 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2104 | .base = undefined, | 2074 | .lhs = lhs, |
| 2105 | .lhs = lhs, | 2075 | .op_token = token_index, |
| 2106 | .op_token = token_index, | 2076 | .op = bitshift_id, |
| 2107 | .op = bitshift_id, | 2077 | .rhs = undefined, |
| 2108 | .rhs = undefined, | 2078 | }); |
| 2109 | } | 2079 | opt_ctx.store(&node.base); |
| 2110 | ); | | |
| 2111 | stack.append(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2080 | stack.append(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2112 | try stack.append(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2081 | try stack.append(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2113 | continue; | 2082 | continue; |
| ... | @@ -2130,15 +2099,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2130,15 +2099,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2130 | const token_index = token.index; | 2099 | const token_index = token.index; |
| 2131 | const token_ptr = token.ptr; | 2100 | const token_ptr = token.ptr; |
| 2132 | if (tokenIdToAddition(token_ptr.id)) |add_id| { | 2101 | if (tokenIdToAddition(token_ptr.id)) |add_id| { |
| 2133 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2102 | const node = try arena.construct(ast.Node.InfixOp { |
| 2134 | ast.Node.InfixOp { | 2103 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2135 | .base = undefined, | 2104 | .lhs = lhs, |
| 2136 | .lhs = lhs, | 2105 | .op_token = token_index, |
| 2137 | .op_token = token_index, | 2106 | .op = add_id, |
| 2138 | .op = add_id, | 2107 | .rhs = undefined, |
| 2139 | .rhs = undefined, | 2108 | }); |
| 2140 | } | 2109 | opt_ctx.store(&node.base); |
| 2141 | ); | | |
| 2142 | stack.append(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2110 | stack.append(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2143 | try stack.append(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2111 | try stack.append(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2144 | continue; | 2112 | continue; |
| ... | @@ -2161,15 +2129,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2161,15 +2129,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2161 | const token_index = token.index; | 2129 | const token_index = token.index; |
| 2162 | const token_ptr = token.ptr; | 2130 | const token_ptr = token.ptr; |
| 2163 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { | 2131 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { |
| 2164 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2132 | const node = try arena.construct(ast.Node.InfixOp { |
| 2165 | ast.Node.InfixOp { | 2133 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2166 | .base = undefined, | 2134 | .lhs = lhs, |
| 2167 | .lhs = lhs, | 2135 | .op_token = token_index, |
| 2168 | .op_token = token_index, | 2136 | .op = mult_id, |
| 2169 | .op = mult_id, | 2137 | .rhs = undefined, |
| 2170 | .rhs = undefined, | 2138 | }); |
| 2171 | } | 2139 | opt_ctx.store(&node.base); |
| 2172 | ); | | |
| 2173 | stack.append(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2140 | stack.append(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2174 | try stack.append(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2141 | try stack.append(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2175 | continue; | 2142 | continue; |
| ... | @@ -2211,16 +2178,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2211,16 +2178,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2211 | continue; | 2178 | continue; |
| 2212 | } | 2179 | } |
| 2213 | | 2180 | |
| 2214 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.SuffixOp, | 2181 | const node = try arena.construct(ast.Node.SuffixOp { |
| 2215 | ast.Node.SuffixOp { | 2182 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, |
| 2216 | .base = undefined, | 2183 | .lhs = lhs, |
| 2217 | .lhs = lhs, | 2184 | .op = ast.Node.SuffixOp.Op { |
| 2218 | .op = ast.Node.SuffixOp.Op { | 2185 | .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena), |
| 2219 | .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena), | 2186 | }, |
| 2220 | }, | 2187 | .rtoken = undefined, |
| 2221 | .rtoken = undefined, | 2188 | }); |
| 2222 | } | 2189 | opt_ctx.store(&node.base); |
| 2223 | ); | | |
| 2224 | stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2190 | stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2225 | try stack.append(State { .IfToken = Token.Id.LBrace }); | 2191 | try stack.append(State { .IfToken = Token.Id.LBrace }); |
| 2226 | try stack.append(State { | 2192 | try stack.append(State { |
| ... | @@ -2243,15 +2209,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2243,15 +2209,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2243 | const lhs = opt_ctx.get() ?? continue; | 2209 | const lhs = opt_ctx.get() ?? continue; |
| 2244 | | 2210 | |
| 2245 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { | 2211 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2246 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2212 | const node = try arena.construct(ast.Node.InfixOp { |
| 2247 | ast.Node.InfixOp { | 2213 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2248 | .base = undefined, | 2214 | .lhs = lhs, |
| 2249 | .lhs = lhs, | 2215 | .op_token = bang, |
| 2250 | .op_token = bang, | 2216 | .op = ast.Node.InfixOp.Op.ErrorUnion, |
| 2251 | .op = ast.Node.InfixOp.Op.ErrorUnion, | 2217 | .rhs = undefined, |
| 2252 | .rhs = undefined, | 2218 | }); |
| 2253 | } | 2219 | opt_ctx.store(&node.base); |
| 2254 | ); | | |
| 2255 | stack.append(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; | 2220 | stack.append(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2256 | try stack.append(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } }); | 2221 | try stack.append(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } }); |
| 2257 | continue; | 2222 | continue; |
| ... | @@ -2263,25 +2228,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2263,25 +2228,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2263 | const token_index = token.index; | 2228 | const token_index = token.index; |
| 2264 | const token_ptr = token.ptr; | 2229 | const token_ptr = token.ptr; |
| 2265 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { | 2230 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { |
| 2266 | var node = try createToCtxNode(arena, opt_ctx, ast.Node.PrefixOp, | 2231 | var node = try arena.construct(ast.Node.PrefixOp { |
| 2267 | ast.Node.PrefixOp { | 2232 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, |
| 2268 | .base = undefined, | 2233 | .op_token = token_index, |
| 2269 | .op_token = token_index, | 2234 | .op = prefix_id, |
| 2270 | .op = prefix_id, | 2235 | .rhs = undefined, |
| 2271 | .rhs = undefined, | 2236 | }); |
| 2272 | } | 2237 | opt_ctx.store(&node.base); |
| 2273 | ); | | |
| 2274 | | 2238 | |
| 2275 | // Treat '**' token as two derefs | 2239 | // Treat '**' token as two derefs |
| 2276 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { | 2240 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { |
| 2277 | const child = try createNode(arena, ast.Node.PrefixOp, | 2241 | const child = try arena.construct(ast.Node.PrefixOp { |
| 2278 | ast.Node.PrefixOp { | 2242 | .base = ast.Node {.id = ast.Node.Id.PrefixOp}, |
| 2279 | .base = undefined, | 2243 | .op_token = token_index, |
| 2280 | .op_token = token_index, | 2244 | .op = prefix_id, |
| 2281 | .op = prefix_id, | 2245 | .rhs = undefined, |
| 2282 | .rhs = undefined, | 2246 | }); |
| 2283 | } | | |
| 2284 | ); | | |
| 2285 | node.rhs = &child.base; | 2247 | node.rhs = &child.base; |
| 2286 | node = child; | 2248 | node = child; |
| 2287 | } | 2249 | } |
| ... | @@ -2300,14 +2262,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2300,14 +2262,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2300 | | 2262 | |
| 2301 | State.SuffixOpExpressionBegin => |opt_ctx| { | 2263 | State.SuffixOpExpressionBegin => |opt_ctx| { |
| 2302 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { | 2264 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { |
| 2303 | const async_node = try createNode(arena, ast.Node.AsyncAttribute, | 2265 | const async_node = try arena.construct(ast.Node.AsyncAttribute { |
| 2304 | ast.Node.AsyncAttribute { | 2266 | .base = ast.Node {.id = ast.Node.Id.AsyncAttribute}, |
| 2305 | .base = undefined, | 2267 | .async_token = async_token, |
| 2306 | .async_token = async_token, | 2268 | .allocator_type = null, |
| 2307 | .allocator_type = null, | 2269 | .rangle_bracket = null, |
| 2308 | .rangle_bracket = null, | 2270 | }); |
| 2309 | } | | |
| 2310 | ); | | |
| 2311 | stack.append(State { | 2271 | stack.append(State { |
| 2312 | .AsyncEnd = AsyncEndCtx { | 2272 | .AsyncEnd = AsyncEndCtx { |
| 2313 | .ctx = opt_ctx, | 2273 | .ctx = opt_ctx, |
| ... | @@ -2333,19 +2293,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2333,19 +2293,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2333 | const token_ptr = token.ptr; | 2293 | const token_ptr = token.ptr; |
| 2334 | switch (token_ptr.id) { | 2294 | switch (token_ptr.id) { |
| 2335 | Token.Id.LParen => { | 2295 | Token.Id.LParen => { |
| 2336 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.SuffixOp, | 2296 | const node = try arena.construct(ast.Node.SuffixOp { |
| 2337 | ast.Node.SuffixOp { | 2297 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, |
| 2338 | .base = undefined, | 2298 | .lhs = lhs, |
| 2339 | .lhs = lhs, | 2299 | .op = ast.Node.SuffixOp.Op { |
| 2340 | .op = ast.Node.SuffixOp.Op { | 2300 | .Call = ast.Node.SuffixOp.Op.Call { |
| 2341 | .Call = ast.Node.SuffixOp.Op.Call { | 2301 | .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena), |
| 2342 | .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena), | 2302 | .async_attr = null, |
| 2343 | .async_attr = null, | 2303 | } |
| 2344 | } | 2304 | }, |
| 2345 | }, | 2305 | .rtoken = undefined, |
| 2346 | .rtoken = undefined, | 2306 | }); |
| 2347 | } | 2307 | opt_ctx.store(&node.base); |
| 2348 | ); | 2308 | |
| 2349 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2309 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2350 | try stack.append(State { | 2310 | try stack.append(State { |
| 2351 | .ExprListItemOrEnd = ExprListCtx { | 2311 | .ExprListItemOrEnd = ExprListCtx { |
| ... | @@ -2357,31 +2317,31 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2357,31 +2317,31 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2357 | continue; | 2317 | continue; |
| 2358 | }, | 2318 | }, |
| 2359 | Token.Id.LBracket => { | 2319 | Token.Id.LBracket => { |
| 2360 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.SuffixOp, | 2320 | const node = try arena.construct(ast.Node.SuffixOp { |
| 2361 | ast.Node.SuffixOp { | 2321 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, |
| 2362 | .base = undefined, | 2322 | .lhs = lhs, |
| 2363 | .lhs = lhs, | 2323 | .op = ast.Node.SuffixOp.Op { |
| 2364 | .op = ast.Node.SuffixOp.Op { | 2324 | .ArrayAccess = undefined, |
| 2365 | .ArrayAccess = undefined, | 2325 | }, |
| 2366 | }, | 2326 | .rtoken = undefined |
| 2367 | .rtoken = undefined | 2327 | }); |
| 2368 | } | 2328 | opt_ctx.store(&node.base); |
| 2369 | ); | 2329 | |
| 2370 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2330 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2371 | try stack.append(State { .SliceOrArrayAccess = node }); | 2331 | try stack.append(State { .SliceOrArrayAccess = node }); |
| 2372 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }}); | 2332 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }}); |
| 2373 | continue; | 2333 | continue; |
| 2374 | }, | 2334 | }, |
| 2375 | Token.Id.Period => { | 2335 | Token.Id.Period => { |
| 2376 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2336 | const node = try arena.construct(ast.Node.InfixOp { |
| 2377 | ast.Node.InfixOp { | 2337 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2378 | .base = undefined, | 2338 | .lhs = lhs, |
| 2379 | .lhs = lhs, | 2339 | .op_token = token_index, |
| 2380 | .op_token = token_index, | 2340 | .op = ast.Node.InfixOp.Op.Period, |
| 2381 | .op = ast.Node.InfixOp.Op.Period, | 2341 | .rhs = undefined, |
| 2382 | .rhs = undefined, | 2342 | }); |
| 2383 | } | 2343 | opt_ctx.store(&node.base); |
| 2384 | ); | 2344 | |
| 2385 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2345 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2386 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.rhs } }); | 2346 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.rhs } }); |
| 2387 | continue; | 2347 | continue; |
| ... | @@ -2461,14 +2421,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2461,14 +2421,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2461 | continue; | 2421 | continue; |
| 2462 | }, | 2422 | }, |
| 2463 | Token.Id.LParen => { | 2423 | Token.Id.LParen => { |
| 2464 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.GroupedExpression, | 2424 | const node = try arena.construct(ast.Node.GroupedExpression { |
| 2465 | ast.Node.GroupedExpression { | 2425 | .base = ast.Node {.id = ast.Node.Id.GroupedExpression }, |
| 2466 | .base = undefined, | 2426 | .lparen = token.index, |
| 2467 | .lparen = token.index, | 2427 | .expr = undefined, |
| 2468 | .expr = undefined, | 2428 | .rparen = undefined, |
| 2469 | .rparen = undefined, | 2429 | }); |
| 2470 | } | 2430 | opt_ctx.store(&node.base); |
| 2471 | ); | 2431 | |
| 2472 | stack.append(State { | 2432 | stack.append(State { |
| 2473 | .ExpectTokenSave = ExpectTokenSave { | 2433 | .ExpectTokenSave = ExpectTokenSave { |
| 2474 | .id = Token.Id.RParen, | 2434 | .id = Token.Id.RParen, |
| ... | @@ -2479,14 +2439,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2479,14 +2439,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2479 | continue; | 2439 | continue; |
| 2480 | }, | 2440 | }, |
| 2481 | Token.Id.Builtin => { | 2441 | Token.Id.Builtin => { |
| 2482 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.BuiltinCall, | 2442 | const node = try arena.construct(ast.Node.BuiltinCall { |
| 2483 | ast.Node.BuiltinCall { | 2443 | .base = ast.Node {.id = ast.Node.Id.BuiltinCall }, |
| 2484 | .base = undefined, | 2444 | .builtin_token = token.index, |
| 2485 | .builtin_token = token.index, | 2445 | .params = ast.Node.BuiltinCall.ParamList.init(arena), |
| 2486 | .params = ast.Node.BuiltinCall.ParamList.init(arena), | 2446 | .rparen_token = undefined, |
| 2487 | .rparen_token = undefined, | 2447 | }); |
| 2488 | } | 2448 | opt_ctx.store(&node.base); |
| 2489 | ); | 2449 | |
| 2490 | stack.append(State { | 2450 | stack.append(State { |
| 2491 | .ExprListItemOrEnd = ExprListCtx { | 2451 | .ExprListItemOrEnd = ExprListCtx { |
| 2492 | .list = &node.params, | 2452 | .list = &node.params, |
| ... | @@ -2498,14 +2458,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2498,14 +2458,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2498 | continue; | 2458 | continue; |
| 2499 | }, | 2459 | }, |
| 2500 | Token.Id.LBracket => { | 2460 | Token.Id.LBracket => { |
| 2501 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PrefixOp, | 2461 | const node = try arena.construct(ast.Node.PrefixOp { |
| 2502 | ast.Node.PrefixOp { | 2462 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, |
| 2503 | .base = undefined, | 2463 | .op_token = token.index, |
| 2504 | .op_token = token.index, | 2464 | .op = undefined, |
| 2505 | .op = undefined, | 2465 | .rhs = undefined, |
| 2506 | .rhs = undefined, | 2466 | }); |
| 2507 | } | 2467 | opt_ctx.store(&node.base); |
| 2508 | ); | 2468 | |
| 2509 | stack.append(State { .SliceOrArrayType = node }) catch unreachable; | 2469 | stack.append(State { .SliceOrArrayType = node }) catch unreachable; |
| 2510 | continue; | 2470 | continue; |
| 2511 | }, | 2471 | }, |
| ... | @@ -2611,18 +2571,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2611,18 +2571,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2611 | continue; | 2571 | continue; |
| 2612 | }, | 2572 | }, |
| 2613 | Token.Id.Keyword_asm => { | 2573 | Token.Id.Keyword_asm => { |
| 2614 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.Asm, | 2574 | const node = try arena.construct(ast.Node.Asm { |
| 2615 | ast.Node.Asm { | 2575 | .base = ast.Node {.id = ast.Node.Id.Asm }, |
| 2616 | .base = undefined, | 2576 | .asm_token = token.index, |
| 2617 | .asm_token = token.index, | 2577 | .volatile_token = null, |
| 2618 | .volatile_token = null, | 2578 | .template = undefined, |
| 2619 | .template = undefined, | 2579 | .outputs = ast.Node.Asm.OutputList.init(arena), |
| 2620 | .outputs = ast.Node.Asm.OutputList.init(arena), | 2580 | .inputs = ast.Node.Asm.InputList.init(arena), |
| 2621 | .inputs = ast.Node.Asm.InputList.init(arena), | 2581 | .clobbers = ast.Node.Asm.ClobberList.init(arena), |
| 2622 | .clobbers = ast.Node.Asm.ClobberList.init(arena), | 2582 | .rparen = undefined, |
| 2623 | .rparen = undefined, | 2583 | }); |
| 2624 | } | 2584 | opt_ctx.store(&node.base); |
| 2625 | ); | 2585 | |
| 2626 | stack.append(State { | 2586 | stack.append(State { |
| 2627 | .ExpectTokenSave = ExpectTokenSave { | 2587 | .ExpectTokenSave = ExpectTokenSave { |
| 2628 | .id = Token.Id.RParen, | 2588 | .id = Token.Id.RParen, |
| ... | @@ -3155,31 +3115,29 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con | ... | @@ -3155,31 +3115,29 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con |
| 3155 | token_ptr: &const Token, token_index: TokenIndex) !bool { | 3115 | token_ptr: &const Token, token_index: TokenIndex) !bool { |
| 3156 | switch (token_ptr.id) { | 3116 | switch (token_ptr.id) { |
| 3157 | Token.Id.Keyword_suspend => { | 3117 | Token.Id.Keyword_suspend => { |
| 3158 | const node = try createToCtxNode(arena, ctx, ast.Node.Suspend, | 3118 | const node = try arena.construct(ast.Node.Suspend { |
| 3159 | ast.Node.Suspend { | 3119 | .base = ast.Node {.id = ast.Node.Id.Suspend }, |
| 3160 | .base = undefined, | 3120 | .label = null, |
| 3161 | .label = null, | 3121 | .suspend_token = token_index, |
| 3162 | .suspend_token = token_index, | 3122 | .payload = null, |
| 3163 | .payload = null, | 3123 | .body = null, |
| 3164 | .body = null, | 3124 | }); |
| 3165 | } | 3125 | ctx.store(&node.base); |
| 3166 | ); | | |
| 3167 | | 3126 | |
| 3168 | stack.append(State { .SuspendBody = node }) catch unreachable; | 3127 | stack.append(State { .SuspendBody = node }) catch unreachable; |
| 3169 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); | 3128 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); |
| 3170 | return true; | 3129 | return true; |
| 3171 | }, | 3130 | }, |
| 3172 | Token.Id.Keyword_if => { | 3131 | Token.Id.Keyword_if => { |
| 3173 | const node = try createToCtxNode(arena, ctx, ast.Node.If, | 3132 | const node = try arena.construct(ast.Node.If { |
| 3174 | ast.Node.If { | 3133 | .base = ast.Node {.id = ast.Node.Id.If }, |
| 3175 | .base = undefined, | 3134 | .if_token = token_index, |
| 3176 | .if_token = token_index, | 3135 | .condition = undefined, |
| 3177 | .condition = undefined, | 3136 | .payload = null, |
| 3178 | .payload = null, | 3137 | .body = undefined, |
| 3179 | .body = undefined, | 3138 | .@"else" = null, |
| 3180 | .@"else" = null, | 3139 | }); |
| 3181 | } | 3140 | ctx.store(&node.base); |
| 3182 | ); | | |
| 3183 | | 3141 | |
| 3184 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 3142 | stack.append(State { .Else = &node.@"else" }) catch unreachable; |
| 3185 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 3143 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); |
| ... | @@ -3236,14 +3194,14 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con | ... | @@ -3236,14 +3194,14 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con |
| 3236 | return true; | 3194 | return true; |
| 3237 | }, | 3195 | }, |
| 3238 | Token.Id.Keyword_comptime => { | 3196 | Token.Id.Keyword_comptime => { |
| 3239 | const node = try createToCtxNode(arena, ctx, ast.Node.Comptime, | 3197 | const node = try arena.construct(ast.Node.Comptime { |
| 3240 | ast.Node.Comptime { | 3198 | .base = ast.Node {.id = ast.Node.Id.Comptime }, |
| 3241 | .base = undefined, | 3199 | .comptime_token = token_index, |
| 3242 | .comptime_token = token_index, | 3200 | .expr = undefined, |
| 3243 | .expr = undefined, | 3201 | .doc_comments = null, |
| 3244 | .doc_comments = null, | 3202 | }); |
| 3245 | } | 3203 | ctx.store(&node.base); |
| 3246 | ); | 3204 | |
| 3247 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); | 3205 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); |
| 3248 | return true; | 3206 | return true; |
| 3249 | }, | 3207 | }, |
| ... | @@ -3390,33 +3348,11 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op { | ... | @@ -3390,33 +3348,11 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op { |
| 3390 | }; | 3348 | }; |
| 3391 | } | 3349 | } |
| 3392 | | 3350 | |
| 3393 | fn createNode(arena: &mem.Allocator, comptime T: type, init_to: &const T) !&T { | | |
| 3394 | const node = try arena.create(T); | | |
| 3395 | *node = *init_to; | | |
| 3396 | node.base = blk: { | | |
| 3397 | const id = ast.Node.typeToId(T); | | |
| 3398 | break :blk ast.Node { | | |
| 3399 | .id = id, | | |
| 3400 | }; | | |
| 3401 | }; | | |
| 3402 | | | |
| 3403 | return node; | | |
| 3404 | } | | |
| 3405 | | | |
| 3406 | fn createToCtxNode(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, comptime T: type, init_to: &const T) !&T { | | |
| 3407 | const node = try createNode(arena, T, init_to); | | |
| 3408 | opt_ctx.store(&node.base); | | |
| 3409 | | | |
| 3410 | return node; | | |
| 3411 | } | | |
| 3412 | | | |
| 3413 | fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T { | 3351 | fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T { |
| 3414 | return createNode(arena, T, | 3352 | return arena.construct(T { |
| 3415 | T { | 3353 | .base = ast.Node {.id = ast.Node.typeToId(T)}, |
| 3416 | .base = undefined, | 3354 | .token = token_index, |
| 3417 | .token = token_index, | 3355 | }); |
| 3418 | } | | |
| 3419 | ); | | |
| 3420 | } | 3356 | } |
| 3421 | | 3357 | |
| 3422 | fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, comptime T: type, token_index: TokenIndex) !&T { | 3358 | fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, comptime T: type, token_index: TokenIndex) !&T { |