| ... | @@ -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 }); |
| ... | @@ -647,12 +640,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -647,12 +640,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 647 | switch (token_ptr.id) { | 640 | switch (token_ptr.id) { |
| 648 | Token.Id.Equal => { | 641 | Token.Id.Equal => { |
| 649 | var_decl.eq_token = token_index; | 642 | var_decl.eq_token = token_index; |
| 650 | stack.append(State { | 643 | stack.append(State { .VarDeclSemiColon = var_decl }) catch unreachable; |
| 651 | .ExpectTokenSave = ExpectTokenSave { | | |
| 652 | .id = Token.Id.Semicolon, | | |
| 653 | .ptr = &var_decl.semicolon_token, | | |
| 654 | }, | | |
| 655 | }) catch unreachable; | | |
| 656 | try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.init_node } }); | 644 | try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.init_node } }); |
| 657 | continue; | 645 | continue; |
| 658 | }, | 646 | }, |
| ... | @@ -669,6 +657,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -669,6 +657,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 669 | } | 657 | } |
| 670 | }, | 658 | }, |
| 671 | | 659 | |
| | 660 | State.VarDeclSemiColon => |var_decl| { |
| | 661 | const semicolon_token = nextToken(&tok_it, &tree); |
| | 662 | |
| | 663 | if (semicolon_token.ptr.id != Token.Id.Semicolon) { |
| | 664 | *(try tree.errors.addOne()) = Error { |
| | 665 | .ExpectedToken = Error.ExpectedToken { |
| | 666 | .token = semicolon_token.index, |
| | 667 | .expected_id = Token.Id.Semicolon, |
| | 668 | }, |
| | 669 | }; |
| | 670 | return tree; |
| | 671 | } |
| | 672 | |
| | 673 | var_decl.semicolon_token = semicolon_token.index; |
| | 674 | |
| | 675 | if (eatToken(&tok_it, &tree, Token.Id.DocComment)) |doc_comment_token| { |
| | 676 | const loc = tree.tokenLocation(semicolon_token.ptr.end, doc_comment_token); |
| | 677 | if (loc.line == 0) { |
| | 678 | try pushDocComment(arena, doc_comment_token, &var_decl.doc_comments); |
| | 679 | } else { |
| | 680 | putBackToken(&tok_it, &tree); |
| | 681 | } |
| | 682 | } |
| | 683 | }, |
| 672 | | 684 | |
| 673 | State.FnDef => |fn_proto| { | 685 | State.FnDef => |fn_proto| { |
| 674 | const token = nextToken(&tok_it, &tree); | 686 | const token = nextToken(&tok_it, &tree); |
| ... | @@ -844,15 +856,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -844,15 +856,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 844 | const token_ptr = token.ptr; | 856 | const token_ptr = token.ptr; |
| 845 | switch (token_ptr.id) { | 857 | switch (token_ptr.id) { |
| 846 | Token.Id.LBrace => { | 858 | Token.Id.LBrace => { |
| 847 | const block = try createToCtxNode(arena, ctx.opt_ctx, ast.Node.Block, | 859 | const block = try arena.construct(ast.Node.Block { |
| 848 | ast.Node.Block { | 860 | .base = ast.Node {.id = ast.Node.Id.Block}, |
| 849 | .base = undefined, | 861 | .label = ctx.label, |
| 850 | .label = ctx.label, | 862 | .lbrace = token_index, |
| 851 | .lbrace = token_index, | 863 | .statements = ast.Node.Block.StatementList.init(arena), |
| 852 | .statements = ast.Node.Block.StatementList.init(arena), | 864 | .rbrace = undefined, |
| 853 | .rbrace = undefined, | 865 | }); |
| 854 | } | 866 | ctx.opt_ctx.store(&block.base); |
| 855 | ); | | |
| 856 | stack.append(State { .Block = block }) catch unreachable; | 867 | stack.append(State { .Block = block }) catch unreachable; |
| 857 | continue; | 868 | continue; |
| 858 | }, | 869 | }, |
| ... | @@ -957,19 +968,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -957,19 +968,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 957 | } | 968 | } |
| 958 | }, | 969 | }, |
| 959 | State.While => |ctx| { | 970 | State.While => |ctx| { |
| 960 | const node = try createToCtxNode(arena, ctx.opt_ctx, ast.Node.While, | 971 | const node = try arena.construct(ast.Node.While { |
| 961 | ast.Node.While { | 972 | .base = ast.Node {.id = ast.Node.Id.While }, |
| 962 | .base = undefined, | 973 | .label = ctx.label, |
| 963 | .label = ctx.label, | 974 | .inline_token = ctx.inline_token, |
| 964 | .inline_token = ctx.inline_token, | 975 | .while_token = ctx.loop_token, |
| 965 | .while_token = ctx.loop_token, | 976 | .condition = undefined, |
| 966 | .condition = undefined, | 977 | .payload = null, |
| 967 | .payload = null, | 978 | .continue_expr = null, |
| 968 | .continue_expr = null, | 979 | .body = undefined, |
| 969 | .body = undefined, | 980 | .@"else" = null, |
| 970 | .@"else" = null, | 981 | }); |
| 971 | } | 982 | ctx.opt_ctx.store(&node.base); |
| 972 | ); | | |
| 973 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 983 | stack.append(State { .Else = &node.@"else" }) catch unreachable; |
| 974 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 984 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); |
| 975 | try stack.append(State { .WhileContinueExpr = &node.continue_expr }); | 985 | try stack.append(State { .WhileContinueExpr = &node.continue_expr }); |
| ... | @@ -987,18 +997,17 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -987,18 +997,17 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 987 | continue; | 997 | continue; |
| 988 | }, | 998 | }, |
| 989 | State.For => |ctx| { | 999 | State.For => |ctx| { |
| 990 | const node = try createToCtxNode(arena, ctx.opt_ctx, ast.Node.For, | 1000 | const node = try arena.construct(ast.Node.For { |
| 991 | ast.Node.For { | 1001 | .base = ast.Node {.id = ast.Node.Id.For }, |
| 992 | .base = undefined, | 1002 | .label = ctx.label, |
| 993 | .label = ctx.label, | 1003 | .inline_token = ctx.inline_token, |
| 994 | .inline_token = ctx.inline_token, | 1004 | .for_token = ctx.loop_token, |
| 995 | .for_token = ctx.loop_token, | 1005 | .array_expr = undefined, |
| 996 | .array_expr = undefined, | 1006 | .payload = null, |
| 997 | .payload = null, | 1007 | .body = undefined, |
| 998 | .body = undefined, | 1008 | .@"else" = null, |
| 999 | .@"else" = null, | 1009 | }); |
| 1000 | } | 1010 | ctx.opt_ctx.store(&node.base); |
| 1001 | ); | | |
| 1002 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 1011 | stack.append(State { .Else = &node.@"else" }) catch unreachable; |
| 1003 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 1012 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); |
| 1004 | try stack.append(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } }); | 1013 | try stack.append(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } }); |
| ... | @@ -1009,14 +1018,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1009,14 +1018,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1009 | }, | 1018 | }, |
| 1010 | State.Else => |dest| { | 1019 | State.Else => |dest| { |
| 1011 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { | 1020 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 1012 | const node = try createNode(arena, ast.Node.Else, | 1021 | const node = try arena.construct(ast.Node.Else { |
| 1013 | ast.Node.Else { | 1022 | .base = ast.Node {.id = ast.Node.Id.Else }, |
| 1014 | .base = undefined, | 1023 | .else_token = else_token, |
| 1015 | .else_token = else_token, | 1024 | .payload = null, |
| 1016 | .payload = null, | 1025 | .body = undefined, |
| 1017 | .body = undefined, | 1026 | }); |
| 1018 | } | | |
| 1019 | ); | | |
| 1020 | *dest = node; | 1027 | *dest = node; |
| 1021 | | 1028 | |
| 1022 | stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable; | 1029 | stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable; |
| ... | @@ -1170,14 +1177,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1170,14 +1177,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1170 | continue; | 1177 | continue; |
| 1171 | } | 1178 | } |
| 1172 | | 1179 | |
| 1173 | const node = try createNode(arena, ast.Node.AsmOutput, | 1180 | const node = try arena.construct(ast.Node.AsmOutput { |
| 1174 | ast.Node.AsmOutput { | 1181 | .base = ast.Node {.id = ast.Node.Id.AsmOutput }, |
| 1175 | .base = undefined, | 1182 | .symbolic_name = undefined, |
| 1176 | .symbolic_name = undefined, | 1183 | .constraint = undefined, |
| 1177 | .constraint = undefined, | 1184 | .kind = undefined, |
| 1178 | .kind = undefined, | 1185 | }); |
| 1179 | } | | |
| 1180 | ); | | |
| 1181 | try items.push(node); | 1186 | try items.push(node); |
| 1182 | | 1187 | |
| 1183 | stack.append(State { .AsmOutputItems = items }) catch unreachable; | 1188 | stack.append(State { .AsmOutputItems = items }) catch unreachable; |
| ... | @@ -1223,14 +1228,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1223,14 +1228,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1223 | continue; | 1228 | continue; |
| 1224 | } | 1229 | } |
| 1225 | | 1230 | |
| 1226 | const node = try createNode(arena, ast.Node.AsmInput, | 1231 | const node = try arena.construct(ast.Node.AsmInput { |
| 1227 | ast.Node.AsmInput { | 1232 | .base = ast.Node {.id = ast.Node.Id.AsmInput }, |
| 1228 | .base = undefined, | 1233 | .symbolic_name = undefined, |
| 1229 | .symbolic_name = undefined, | 1234 | .constraint = undefined, |
| 1230 | .constraint = undefined, | 1235 | .expr = undefined, |
| 1231 | .expr = undefined, | 1236 | }); |
| 1232 | } | | |
| 1233 | ); | | |
| 1234 | try items.push(node); | 1237 | try items.push(node); |
| 1235 | | 1238 | |
| 1236 | stack.append(State { .AsmInputItems = items }) catch unreachable; | 1239 | stack.append(State { .AsmInputItems = items }) catch unreachable; |
| ... | @@ -1668,14 +1671,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1668,14 +1671,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1668 | continue; | 1671 | continue; |
| 1669 | } | 1672 | } |
| 1670 | | 1673 | |
| 1671 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.Payload, | 1674 | const node = try arena.construct(ast.Node.Payload { |
| 1672 | ast.Node.Payload { | 1675 | .base = ast.Node {.id = ast.Node.Id.Payload }, |
| 1673 | .base = undefined, | 1676 | .lpipe = token_index, |
| 1674 | .lpipe = token_index, | 1677 | .error_symbol = undefined, |
| 1675 | .error_symbol = undefined, | 1678 | .rpipe = undefined |
| 1676 | .rpipe = undefined | 1679 | }); |
| 1677 | } | 1680 | opt_ctx.store(&node.base); |
| 1678 | ); | | |
| 1679 | | 1681 | |
| 1680 | stack.append(State { | 1682 | stack.append(State { |
| 1681 | .ExpectTokenSave = ExpectTokenSave { | 1683 | .ExpectTokenSave = ExpectTokenSave { |
| ... | @@ -1705,15 +1707,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1705,15 +1707,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1705 | continue; | 1707 | continue; |
| 1706 | } | 1708 | } |
| 1707 | | 1709 | |
| 1708 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PointerPayload, | 1710 | const node = try arena.construct(ast.Node.PointerPayload { |
| 1709 | ast.Node.PointerPayload { | 1711 | .base = ast.Node {.id = ast.Node.Id.PointerPayload }, |
| 1710 | .base = undefined, | 1712 | .lpipe = token_index, |
| 1711 | .lpipe = token_index, | 1713 | .ptr_token = null, |
| 1712 | .ptr_token = null, | 1714 | .value_symbol = undefined, |
| 1713 | .value_symbol = undefined, | 1715 | .rpipe = undefined |
| 1714 | .rpipe = undefined | 1716 | }); |
| 1715 | } | 1717 | opt_ctx.store(&node.base); |
| 1716 | ); | | |
| 1717 | | 1718 | |
| 1718 | try stack.append(State { | 1719 | try stack.append(State { |
| 1719 | .ExpectTokenSave = ExpectTokenSave { | 1720 | .ExpectTokenSave = ExpectTokenSave { |
| ... | @@ -1749,16 +1750,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1749,16 +1750,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1749 | continue; | 1750 | continue; |
| 1750 | } | 1751 | } |
| 1751 | | 1752 | |
| 1752 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PointerIndexPayload, | 1753 | const node = try arena.construct(ast.Node.PointerIndexPayload { |
| 1753 | ast.Node.PointerIndexPayload { | 1754 | .base = ast.Node {.id = ast.Node.Id.PointerIndexPayload }, |
| 1754 | .base = undefined, | 1755 | .lpipe = token_index, |
| 1755 | .lpipe = token_index, | 1756 | .ptr_token = null, |
| 1756 | .ptr_token = null, | 1757 | .value_symbol = undefined, |
| 1757 | .value_symbol = undefined, | 1758 | .index_symbol = null, |
| 1758 | .index_symbol = null, | 1759 | .rpipe = undefined |
| 1759 | .rpipe = undefined | 1760 | }); |
| 1760 | } | 1761 | opt_ctx.store(&node.base); |
| 1761 | ); | | |
| 1762 | | 1762 | |
| 1763 | stack.append(State { | 1763 | stack.append(State { |
| 1764 | .ExpectTokenSave = ExpectTokenSave { | 1764 | .ExpectTokenSave = ExpectTokenSave { |
| ... | @@ -1785,14 +1785,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1785,14 +1785,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1785 | const token_ptr = token.ptr; | 1785 | const token_ptr = token.ptr; |
| 1786 | switch (token_ptr.id) { | 1786 | switch (token_ptr.id) { |
| 1787 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { | 1787 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { |
| 1788 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.ControlFlowExpression, | 1788 | const node = try arena.construct(ast.Node.ControlFlowExpression { |
| 1789 | ast.Node.ControlFlowExpression { | 1789 | .base = ast.Node {.id = ast.Node.Id.ControlFlowExpression }, |
| 1790 | .base = undefined, | 1790 | .ltoken = token_index, |
| 1791 | .ltoken = token_index, | 1791 | .kind = undefined, |
| 1792 | .kind = undefined, | 1792 | .rhs = null, |
| 1793 | .rhs = null, | 1793 | }); |
| 1794 | } | 1794 | opt_ctx.store(&node.base); |
| 1795 | ); | | |
| 1796 | | 1795 | |
| 1797 | stack.append(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable; | 1796 | stack.append(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable; |
| 1798 | | 1797 | |
| ... | @@ -1815,19 +1814,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1815,19 +1814,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1815 | continue; | 1814 | continue; |
| 1816 | }, | 1815 | }, |
| 1817 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { | 1816 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { |
| 1818 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PrefixOp, | 1817 | const node = try arena.construct(ast.Node.PrefixOp { |
| 1819 | ast.Node.PrefixOp { | 1818 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, |
| 1820 | .base = undefined, | 1819 | .op_token = token_index, |
| 1821 | .op_token = token_index, | 1820 | .op = switch (token_ptr.id) { |
| 1822 | .op = switch (token_ptr.id) { | 1821 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{} }, |
| 1823 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{} }, | 1822 | Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op { .Cancel = void{} }, |
| 1824 | Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op { .Cancel = void{} }, | 1823 | Token.Id.Keyword_resume => ast.Node.PrefixOp.Op { .Resume = void{} }, |
| 1825 | Token.Id.Keyword_resume => ast.Node.PrefixOp.Op { .Resume = void{} }, | 1824 | else => unreachable, |
| 1826 | else => unreachable, | 1825 | }, |
| 1827 | }, | 1826 | .rhs = undefined, |
| 1828 | .rhs = undefined, | 1827 | }); |
| 1829 | } | 1828 | opt_ctx.store(&node.base); |
| 1830 | ); | | |
| 1831 | | 1829 | |
| 1832 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 1830 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; |
| 1833 | continue; | 1831 | continue; |
| ... | @@ -1850,15 +1848,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1850,15 +1848,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1850 | const lhs = opt_ctx.get() ?? continue; | 1848 | const lhs = opt_ctx.get() ?? continue; |
| 1851 | | 1849 | |
| 1852 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { | 1850 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 1853 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1851 | const node = try arena.construct(ast.Node.InfixOp { |
| 1854 | ast.Node.InfixOp { | 1852 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1855 | .base = undefined, | 1853 | .lhs = lhs, |
| 1856 | .lhs = lhs, | 1854 | .op_token = ellipsis3, |
| 1857 | .op_token = ellipsis3, | 1855 | .op = ast.Node.InfixOp.Op.Range, |
| 1858 | .op = ast.Node.InfixOp.Op.Range, | 1856 | .rhs = undefined, |
| 1859 | .rhs = undefined, | 1857 | }); |
| 1860 | } | 1858 | opt_ctx.store(&node.base); |
| 1861 | ); | | |
| 1862 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 1859 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; |
| 1863 | continue; | 1860 | continue; |
| 1864 | } | 1861 | } |
| ... | @@ -1876,15 +1873,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1876,15 +1873,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1876 | const token_index = token.index; | 1873 | const token_index = token.index; |
| 1877 | const token_ptr = token.ptr; | 1874 | const token_ptr = token.ptr; |
| 1878 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { | 1875 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { |
| 1879 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1876 | const node = try arena.construct(ast.Node.InfixOp { |
| 1880 | ast.Node.InfixOp { | 1877 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1881 | .base = undefined, | 1878 | .lhs = lhs, |
| 1882 | .lhs = lhs, | 1879 | .op_token = token_index, |
| 1883 | .op_token = token_index, | 1880 | .op = ass_id, |
| 1884 | .op = ass_id, | 1881 | .rhs = undefined, |
| 1885 | .rhs = undefined, | 1882 | }); |
| 1886 | } | 1883 | opt_ctx.store(&node.base); |
| 1887 | ); | | |
| 1888 | stack.append(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1884 | stack.append(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1889 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); | 1885 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); |
| 1890 | continue; | 1886 | continue; |
| ... | @@ -1907,15 +1903,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1907,15 +1903,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1907 | const token_index = token.index; | 1903 | const token_index = token.index; |
| 1908 | const token_ptr = token.ptr; | 1904 | const token_ptr = token.ptr; |
| 1909 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { | 1905 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { |
| 1910 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1906 | const node = try arena.construct(ast.Node.InfixOp { |
| 1911 | ast.Node.InfixOp { | 1907 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1912 | .base = undefined, | 1908 | .lhs = lhs, |
| 1913 | .lhs = lhs, | 1909 | .op_token = token_index, |
| 1914 | .op_token = token_index, | 1910 | .op = unwrap_id, |
| 1915 | .op = unwrap_id, | 1911 | .rhs = undefined, |
| 1916 | .rhs = undefined, | 1912 | }); |
| 1917 | } | 1913 | opt_ctx.store(&node.base); |
| 1918 | ); | | |
| 1919 | | 1914 | |
| 1920 | stack.append(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1915 | stack.append(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1921 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); | 1916 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); |
| ... | @@ -1940,15 +1935,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1940,15 +1935,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1940 | const lhs = opt_ctx.get() ?? continue; | 1935 | const lhs = opt_ctx.get() ?? continue; |
| 1941 | | 1936 | |
| 1942 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { | 1937 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 1943 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1938 | const node = try arena.construct(ast.Node.InfixOp { |
| 1944 | ast.Node.InfixOp { | 1939 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1945 | .base = undefined, | 1940 | .lhs = lhs, |
| 1946 | .lhs = lhs, | 1941 | .op_token = or_token, |
| 1947 | .op_token = or_token, | 1942 | .op = ast.Node.InfixOp.Op.BoolOr, |
| 1948 | .op = ast.Node.InfixOp.Op.BoolOr, | 1943 | .rhs = undefined, |
| 1949 | .rhs = undefined, | 1944 | }); |
| 1950 | } | 1945 | opt_ctx.store(&node.base); |
| 1951 | ); | | |
| 1952 | stack.append(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1946 | stack.append(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1953 | try stack.append(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1947 | try stack.append(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 1954 | continue; | 1948 | continue; |
| ... | @@ -1965,15 +1959,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1965,15 +1959,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1965 | const lhs = opt_ctx.get() ?? continue; | 1959 | const lhs = opt_ctx.get() ?? continue; |
| 1966 | | 1960 | |
| 1967 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { | 1961 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 1968 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1962 | const node = try arena.construct(ast.Node.InfixOp { |
| 1969 | ast.Node.InfixOp { | 1963 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1970 | .base = undefined, | 1964 | .lhs = lhs, |
| 1971 | .lhs = lhs, | 1965 | .op_token = and_token, |
| 1972 | .op_token = and_token, | 1966 | .op = ast.Node.InfixOp.Op.BoolAnd, |
| 1973 | .op = ast.Node.InfixOp.Op.BoolAnd, | 1967 | .rhs = undefined, |
| 1974 | .rhs = undefined, | 1968 | }); |
| 1975 | } | 1969 | opt_ctx.store(&node.base); |
| 1976 | ); | | |
| 1977 | stack.append(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1970 | stack.append(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1978 | try stack.append(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1971 | try stack.append(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 1979 | continue; | 1972 | continue; |
| ... | @@ -1993,15 +1986,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1993,15 +1986,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1993 | const token_index = token.index; | 1986 | const token_index = token.index; |
| 1994 | const token_ptr = token.ptr; | 1987 | const token_ptr = token.ptr; |
| 1995 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { | 1988 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { |
| 1996 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 1989 | const node = try arena.construct(ast.Node.InfixOp { |
| 1997 | ast.Node.InfixOp { | 1990 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 1998 | .base = undefined, | 1991 | .lhs = lhs, |
| 1999 | .lhs = lhs, | 1992 | .op_token = token_index, |
| 2000 | .op_token = token_index, | 1993 | .op = comp_id, |
| 2001 | .op = comp_id, | 1994 | .rhs = undefined, |
| 2002 | .rhs = undefined, | 1995 | }); |
| 2003 | } | 1996 | opt_ctx.store(&node.base); |
| 2004 | ); | | |
| 2005 | stack.append(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1997 | stack.append(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2006 | try stack.append(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1998 | try stack.append(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2007 | continue; | 1999 | continue; |
| ... | @@ -2021,15 +2013,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2021,15 +2013,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2021 | const lhs = opt_ctx.get() ?? continue; | 2013 | const lhs = opt_ctx.get() ?? continue; |
| 2022 | | 2014 | |
| 2023 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { | 2015 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 2024 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2016 | const node = try arena.construct(ast.Node.InfixOp { |
| 2025 | ast.Node.InfixOp { | 2017 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2026 | .base = undefined, | 2018 | .lhs = lhs, |
| 2027 | .lhs = lhs, | 2019 | .op_token = pipe, |
| 2028 | .op_token = pipe, | 2020 | .op = ast.Node.InfixOp.Op.BitOr, |
| 2029 | .op = ast.Node.InfixOp.Op.BitOr, | 2021 | .rhs = undefined, |
| 2030 | .rhs = undefined, | 2022 | }); |
| 2031 | } | 2023 | opt_ctx.store(&node.base); |
| 2032 | ); | | |
| 2033 | stack.append(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2024 | stack.append(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2034 | try stack.append(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2025 | try stack.append(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2035 | continue; | 2026 | continue; |
| ... | @@ -2046,15 +2037,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2046,15 +2037,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2046 | const lhs = opt_ctx.get() ?? continue; | 2037 | const lhs = opt_ctx.get() ?? continue; |
| 2047 | | 2038 | |
| 2048 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { | 2039 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2049 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2040 | const node = try arena.construct(ast.Node.InfixOp { |
| 2050 | ast.Node.InfixOp { | 2041 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2051 | .base = undefined, | 2042 | .lhs = lhs, |
| 2052 | .lhs = lhs, | 2043 | .op_token = caret, |
| 2053 | .op_token = caret, | 2044 | .op = ast.Node.InfixOp.Op.BitXor, |
| 2054 | .op = ast.Node.InfixOp.Op.BitXor, | 2045 | .rhs = undefined, |
| 2055 | .rhs = undefined, | 2046 | }); |
| 2056 | } | 2047 | opt_ctx.store(&node.base); |
| 2057 | ); | | |
| 2058 | stack.append(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2048 | stack.append(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2059 | try stack.append(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2049 | try stack.append(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2060 | continue; | 2050 | continue; |
| ... | @@ -2071,15 +2061,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2071,15 +2061,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2071 | const lhs = opt_ctx.get() ?? continue; | 2061 | const lhs = opt_ctx.get() ?? continue; |
| 2072 | | 2062 | |
| 2073 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { | 2063 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2074 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2064 | const node = try arena.construct(ast.Node.InfixOp { |
| 2075 | ast.Node.InfixOp { | 2065 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2076 | .base = undefined, | 2066 | .lhs = lhs, |
| 2077 | .lhs = lhs, | 2067 | .op_token = ampersand, |
| 2078 | .op_token = ampersand, | 2068 | .op = ast.Node.InfixOp.Op.BitAnd, |
| 2079 | .op = ast.Node.InfixOp.Op.BitAnd, | 2069 | .rhs = undefined, |
| 2080 | .rhs = undefined, | 2070 | }); |
| 2081 | } | 2071 | opt_ctx.store(&node.base); |
| 2082 | ); | | |
| 2083 | stack.append(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2072 | stack.append(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2084 | try stack.append(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2073 | try stack.append(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2085 | continue; | 2074 | continue; |
| ... | @@ -2099,15 +2088,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2099,15 +2088,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2099 | const token_index = token.index; | 2088 | const token_index = token.index; |
| 2100 | const token_ptr = token.ptr; | 2089 | const token_ptr = token.ptr; |
| 2101 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { | 2090 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { |
| 2102 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2091 | const node = try arena.construct(ast.Node.InfixOp { |
| 2103 | ast.Node.InfixOp { | 2092 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2104 | .base = undefined, | 2093 | .lhs = lhs, |
| 2105 | .lhs = lhs, | 2094 | .op_token = token_index, |
| 2106 | .op_token = token_index, | 2095 | .op = bitshift_id, |
| 2107 | .op = bitshift_id, | 2096 | .rhs = undefined, |
| 2108 | .rhs = undefined, | 2097 | }); |
| 2109 | } | 2098 | opt_ctx.store(&node.base); |
| 2110 | ); | | |
| 2111 | stack.append(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2099 | stack.append(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2112 | try stack.append(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2100 | try stack.append(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2113 | continue; | 2101 | continue; |
| ... | @@ -2130,15 +2118,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2130,15 +2118,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2130 | const token_index = token.index; | 2118 | const token_index = token.index; |
| 2131 | const token_ptr = token.ptr; | 2119 | const token_ptr = token.ptr; |
| 2132 | if (tokenIdToAddition(token_ptr.id)) |add_id| { | 2120 | if (tokenIdToAddition(token_ptr.id)) |add_id| { |
| 2133 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2121 | const node = try arena.construct(ast.Node.InfixOp { |
| 2134 | ast.Node.InfixOp { | 2122 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2135 | .base = undefined, | 2123 | .lhs = lhs, |
| 2136 | .lhs = lhs, | 2124 | .op_token = token_index, |
| 2137 | .op_token = token_index, | 2125 | .op = add_id, |
| 2138 | .op = add_id, | 2126 | .rhs = undefined, |
| 2139 | .rhs = undefined, | 2127 | }); |
| 2140 | } | 2128 | opt_ctx.store(&node.base); |
| 2141 | ); | | |
| 2142 | stack.append(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2129 | stack.append(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2143 | try stack.append(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2130 | try stack.append(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2144 | continue; | 2131 | continue; |
| ... | @@ -2161,15 +2148,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2161,15 +2148,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2161 | const token_index = token.index; | 2148 | const token_index = token.index; |
| 2162 | const token_ptr = token.ptr; | 2149 | const token_ptr = token.ptr; |
| 2163 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { | 2150 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { |
| 2164 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2151 | const node = try arena.construct(ast.Node.InfixOp { |
| 2165 | ast.Node.InfixOp { | 2152 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2166 | .base = undefined, | 2153 | .lhs = lhs, |
| 2167 | .lhs = lhs, | 2154 | .op_token = token_index, |
| 2168 | .op_token = token_index, | 2155 | .op = mult_id, |
| 2169 | .op = mult_id, | 2156 | .rhs = undefined, |
| 2170 | .rhs = undefined, | 2157 | }); |
| 2171 | } | 2158 | opt_ctx.store(&node.base); |
| 2172 | ); | | |
| 2173 | stack.append(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2159 | stack.append(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2174 | try stack.append(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2160 | try stack.append(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } }); |
| 2175 | continue; | 2161 | continue; |
| ... | @@ -2211,16 +2197,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2211,16 +2197,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2211 | continue; | 2197 | continue; |
| 2212 | } | 2198 | } |
| 2213 | | 2199 | |
| 2214 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.SuffixOp, | 2200 | const node = try arena.construct(ast.Node.SuffixOp { |
| 2215 | ast.Node.SuffixOp { | 2201 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, |
| 2216 | .base = undefined, | 2202 | .lhs = lhs, |
| 2217 | .lhs = lhs, | 2203 | .op = ast.Node.SuffixOp.Op { |
| 2218 | .op = ast.Node.SuffixOp.Op { | 2204 | .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena), |
| 2219 | .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena), | 2205 | }, |
| 2220 | }, | 2206 | .rtoken = undefined, |
| 2221 | .rtoken = undefined, | 2207 | }); |
| 2222 | } | 2208 | opt_ctx.store(&node.base); |
| 2223 | ); | | |
| 2224 | stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2209 | stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2225 | try stack.append(State { .IfToken = Token.Id.LBrace }); | 2210 | try stack.append(State { .IfToken = Token.Id.LBrace }); |
| 2226 | try stack.append(State { | 2211 | try stack.append(State { |
| ... | @@ -2243,15 +2228,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2243,15 +2228,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2243 | const lhs = opt_ctx.get() ?? continue; | 2228 | const lhs = opt_ctx.get() ?? continue; |
| 2244 | | 2229 | |
| 2245 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { | 2230 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2246 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2231 | const node = try arena.construct(ast.Node.InfixOp { |
| 2247 | ast.Node.InfixOp { | 2232 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2248 | .base = undefined, | 2233 | .lhs = lhs, |
| 2249 | .lhs = lhs, | 2234 | .op_token = bang, |
| 2250 | .op_token = bang, | 2235 | .op = ast.Node.InfixOp.Op.ErrorUnion, |
| 2251 | .op = ast.Node.InfixOp.Op.ErrorUnion, | 2236 | .rhs = undefined, |
| 2252 | .rhs = undefined, | 2237 | }); |
| 2253 | } | 2238 | opt_ctx.store(&node.base); |
| 2254 | ); | | |
| 2255 | stack.append(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; | 2239 | stack.append(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2256 | try stack.append(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } }); | 2240 | try stack.append(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } }); |
| 2257 | continue; | 2241 | continue; |
| ... | @@ -2263,25 +2247,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2263,25 +2247,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2263 | const token_index = token.index; | 2247 | const token_index = token.index; |
| 2264 | const token_ptr = token.ptr; | 2248 | const token_ptr = token.ptr; |
| 2265 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { | 2249 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { |
| 2266 | var node = try createToCtxNode(arena, opt_ctx, ast.Node.PrefixOp, | 2250 | var node = try arena.construct(ast.Node.PrefixOp { |
| 2267 | ast.Node.PrefixOp { | 2251 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, |
| 2268 | .base = undefined, | 2252 | .op_token = token_index, |
| 2269 | .op_token = token_index, | 2253 | .op = prefix_id, |
| 2270 | .op = prefix_id, | 2254 | .rhs = undefined, |
| 2271 | .rhs = undefined, | 2255 | }); |
| 2272 | } | 2256 | opt_ctx.store(&node.base); |
| 2273 | ); | | |
| 2274 | | 2257 | |
| 2275 | // Treat '**' token as two derefs | 2258 | // Treat '**' token as two derefs |
| 2276 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { | 2259 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { |
| 2277 | const child = try createNode(arena, ast.Node.PrefixOp, | 2260 | const child = try arena.construct(ast.Node.PrefixOp { |
| 2278 | ast.Node.PrefixOp { | 2261 | .base = ast.Node {.id = ast.Node.Id.PrefixOp}, |
| 2279 | .base = undefined, | 2262 | .op_token = token_index, |
| 2280 | .op_token = token_index, | 2263 | .op = prefix_id, |
| 2281 | .op = prefix_id, | 2264 | .rhs = undefined, |
| 2282 | .rhs = undefined, | 2265 | }); |
| 2283 | } | | |
| 2284 | ); | | |
| 2285 | node.rhs = &child.base; | 2266 | node.rhs = &child.base; |
| 2286 | node = child; | 2267 | node = child; |
| 2287 | } | 2268 | } |
| ... | @@ -2300,14 +2281,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2300,14 +2281,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2300 | | 2281 | |
| 2301 | State.SuffixOpExpressionBegin => |opt_ctx| { | 2282 | State.SuffixOpExpressionBegin => |opt_ctx| { |
| 2302 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { | 2283 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { |
| 2303 | const async_node = try createNode(arena, ast.Node.AsyncAttribute, | 2284 | const async_node = try arena.construct(ast.Node.AsyncAttribute { |
| 2304 | ast.Node.AsyncAttribute { | 2285 | .base = ast.Node {.id = ast.Node.Id.AsyncAttribute}, |
| 2305 | .base = undefined, | 2286 | .async_token = async_token, |
| 2306 | .async_token = async_token, | 2287 | .allocator_type = null, |
| 2307 | .allocator_type = null, | 2288 | .rangle_bracket = null, |
| 2308 | .rangle_bracket = null, | 2289 | }); |
| 2309 | } | | |
| 2310 | ); | | |
| 2311 | stack.append(State { | 2290 | stack.append(State { |
| 2312 | .AsyncEnd = AsyncEndCtx { | 2291 | .AsyncEnd = AsyncEndCtx { |
| 2313 | .ctx = opt_ctx, | 2292 | .ctx = opt_ctx, |
| ... | @@ -2333,19 +2312,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2333,19 +2312,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2333 | const token_ptr = token.ptr; | 2312 | const token_ptr = token.ptr; |
| 2334 | switch (token_ptr.id) { | 2313 | switch (token_ptr.id) { |
| 2335 | Token.Id.LParen => { | 2314 | Token.Id.LParen => { |
| 2336 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.SuffixOp, | 2315 | const node = try arena.construct(ast.Node.SuffixOp { |
| 2337 | ast.Node.SuffixOp { | 2316 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, |
| 2338 | .base = undefined, | 2317 | .lhs = lhs, |
| 2339 | .lhs = lhs, | 2318 | .op = ast.Node.SuffixOp.Op { |
| 2340 | .op = ast.Node.SuffixOp.Op { | 2319 | .Call = ast.Node.SuffixOp.Op.Call { |
| 2341 | .Call = ast.Node.SuffixOp.Op.Call { | 2320 | .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena), |
| 2342 | .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena), | 2321 | .async_attr = null, |
| 2343 | .async_attr = null, | 2322 | } |
| 2344 | } | 2323 | }, |
| 2345 | }, | 2324 | .rtoken = undefined, |
| 2346 | .rtoken = undefined, | 2325 | }); |
| 2347 | } | 2326 | opt_ctx.store(&node.base); |
| 2348 | ); | 2327 | |
| 2349 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2328 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2350 | try stack.append(State { | 2329 | try stack.append(State { |
| 2351 | .ExprListItemOrEnd = ExprListCtx { | 2330 | .ExprListItemOrEnd = ExprListCtx { |
| ... | @@ -2357,31 +2336,31 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2357,31 +2336,31 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2357 | continue; | 2336 | continue; |
| 2358 | }, | 2337 | }, |
| 2359 | Token.Id.LBracket => { | 2338 | Token.Id.LBracket => { |
| 2360 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.SuffixOp, | 2339 | const node = try arena.construct(ast.Node.SuffixOp { |
| 2361 | ast.Node.SuffixOp { | 2340 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, |
| 2362 | .base = undefined, | 2341 | .lhs = lhs, |
| 2363 | .lhs = lhs, | 2342 | .op = ast.Node.SuffixOp.Op { |
| 2364 | .op = ast.Node.SuffixOp.Op { | 2343 | .ArrayAccess = undefined, |
| 2365 | .ArrayAccess = undefined, | 2344 | }, |
| 2366 | }, | 2345 | .rtoken = undefined |
| 2367 | .rtoken = undefined | 2346 | }); |
| 2368 | } | 2347 | opt_ctx.store(&node.base); |
| 2369 | ); | 2348 | |
| 2370 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2349 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2371 | try stack.append(State { .SliceOrArrayAccess = node }); | 2350 | try stack.append(State { .SliceOrArrayAccess = node }); |
| 2372 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }}); | 2351 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }}); |
| 2373 | continue; | 2352 | continue; |
| 2374 | }, | 2353 | }, |
| 2375 | Token.Id.Period => { | 2354 | Token.Id.Period => { |
| 2376 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.InfixOp, | 2355 | const node = try arena.construct(ast.Node.InfixOp { |
| 2377 | ast.Node.InfixOp { | 2356 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, |
| 2378 | .base = undefined, | 2357 | .lhs = lhs, |
| 2379 | .lhs = lhs, | 2358 | .op_token = token_index, |
| 2380 | .op_token = token_index, | 2359 | .op = ast.Node.InfixOp.Op.Period, |
| 2381 | .op = ast.Node.InfixOp.Op.Period, | 2360 | .rhs = undefined, |
| 2382 | .rhs = undefined, | 2361 | }); |
| 2383 | } | 2362 | opt_ctx.store(&node.base); |
| 2384 | ); | 2363 | |
| 2385 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2364 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2386 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.rhs } }); | 2365 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.rhs } }); |
| 2387 | continue; | 2366 | continue; |
| ... | @@ -2461,14 +2440,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2461,14 +2440,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2461 | continue; | 2440 | continue; |
| 2462 | }, | 2441 | }, |
| 2463 | Token.Id.LParen => { | 2442 | Token.Id.LParen => { |
| 2464 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.GroupedExpression, | 2443 | const node = try arena.construct(ast.Node.GroupedExpression { |
| 2465 | ast.Node.GroupedExpression { | 2444 | .base = ast.Node {.id = ast.Node.Id.GroupedExpression }, |
| 2466 | .base = undefined, | 2445 | .lparen = token.index, |
| 2467 | .lparen = token.index, | 2446 | .expr = undefined, |
| 2468 | .expr = undefined, | 2447 | .rparen = undefined, |
| 2469 | .rparen = undefined, | 2448 | }); |
| 2470 | } | 2449 | opt_ctx.store(&node.base); |
| 2471 | ); | 2450 | |
| 2472 | stack.append(State { | 2451 | stack.append(State { |
| 2473 | .ExpectTokenSave = ExpectTokenSave { | 2452 | .ExpectTokenSave = ExpectTokenSave { |
| 2474 | .id = Token.Id.RParen, | 2453 | .id = Token.Id.RParen, |
| ... | @@ -2479,14 +2458,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2479,14 +2458,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2479 | continue; | 2458 | continue; |
| 2480 | }, | 2459 | }, |
| 2481 | Token.Id.Builtin => { | 2460 | Token.Id.Builtin => { |
| 2482 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.BuiltinCall, | 2461 | const node = try arena.construct(ast.Node.BuiltinCall { |
| 2483 | ast.Node.BuiltinCall { | 2462 | .base = ast.Node {.id = ast.Node.Id.BuiltinCall }, |
| 2484 | .base = undefined, | 2463 | .builtin_token = token.index, |
| 2485 | .builtin_token = token.index, | 2464 | .params = ast.Node.BuiltinCall.ParamList.init(arena), |
| 2486 | .params = ast.Node.BuiltinCall.ParamList.init(arena), | 2465 | .rparen_token = undefined, |
| 2487 | .rparen_token = undefined, | 2466 | }); |
| 2488 | } | 2467 | opt_ctx.store(&node.base); |
| 2489 | ); | 2468 | |
| 2490 | stack.append(State { | 2469 | stack.append(State { |
| 2491 | .ExprListItemOrEnd = ExprListCtx { | 2470 | .ExprListItemOrEnd = ExprListCtx { |
| 2492 | .list = &node.params, | 2471 | .list = &node.params, |
| ... | @@ -2498,14 +2477,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2498,14 +2477,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2498 | continue; | 2477 | continue; |
| 2499 | }, | 2478 | }, |
| 2500 | Token.Id.LBracket => { | 2479 | Token.Id.LBracket => { |
| 2501 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.PrefixOp, | 2480 | const node = try arena.construct(ast.Node.PrefixOp { |
| 2502 | ast.Node.PrefixOp { | 2481 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, |
| 2503 | .base = undefined, | 2482 | .op_token = token.index, |
| 2504 | .op_token = token.index, | 2483 | .op = undefined, |
| 2505 | .op = undefined, | 2484 | .rhs = undefined, |
| 2506 | .rhs = undefined, | 2485 | }); |
| 2507 | } | 2486 | opt_ctx.store(&node.base); |
| 2508 | ); | 2487 | |
| 2509 | stack.append(State { .SliceOrArrayType = node }) catch unreachable; | 2488 | stack.append(State { .SliceOrArrayType = node }) catch unreachable; |
| 2510 | continue; | 2489 | continue; |
| 2511 | }, | 2490 | }, |
| ... | @@ -2611,18 +2590,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2611,18 +2590,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2611 | continue; | 2590 | continue; |
| 2612 | }, | 2591 | }, |
| 2613 | Token.Id.Keyword_asm => { | 2592 | Token.Id.Keyword_asm => { |
| 2614 | const node = try createToCtxNode(arena, opt_ctx, ast.Node.Asm, | 2593 | const node = try arena.construct(ast.Node.Asm { |
| 2615 | ast.Node.Asm { | 2594 | .base = ast.Node {.id = ast.Node.Id.Asm }, |
| 2616 | .base = undefined, | 2595 | .asm_token = token.index, |
| 2617 | .asm_token = token.index, | 2596 | .volatile_token = null, |
| 2618 | .volatile_token = null, | 2597 | .template = undefined, |
| 2619 | .template = undefined, | 2598 | .outputs = ast.Node.Asm.OutputList.init(arena), |
| 2620 | .outputs = ast.Node.Asm.OutputList.init(arena), | 2599 | .inputs = ast.Node.Asm.InputList.init(arena), |
| 2621 | .inputs = ast.Node.Asm.InputList.init(arena), | 2600 | .clobbers = ast.Node.Asm.ClobberList.init(arena), |
| 2622 | .clobbers = ast.Node.Asm.ClobberList.init(arena), | 2601 | .rparen = undefined, |
| 2623 | .rparen = undefined, | 2602 | }); |
| 2624 | } | 2603 | opt_ctx.store(&node.base); |
| 2625 | ); | 2604 | |
| 2626 | stack.append(State { | 2605 | stack.append(State { |
| 2627 | .ExpectTokenSave = ExpectTokenSave { | 2606 | .ExpectTokenSave = ExpectTokenSave { |
| 2628 | .id = Token.Id.RParen, | 2607 | .id = Token.Id.RParen, |
| ... | @@ -2978,6 +2957,7 @@ const State = union(enum) { | ... | @@ -2978,6 +2957,7 @@ const State = union(enum) { |
| 2978 | VarDecl: VarDeclCtx, | 2957 | VarDecl: VarDeclCtx, |
| 2979 | VarDeclAlign: &ast.Node.VarDecl, | 2958 | VarDeclAlign: &ast.Node.VarDecl, |
| 2980 | VarDeclEq: &ast.Node.VarDecl, | 2959 | VarDeclEq: &ast.Node.VarDecl, |
| | 2960 | VarDeclSemiColon: &ast.Node.VarDecl, |
| 2981 | | 2961 | |
| 2982 | FnDef: &ast.Node.FnProto, | 2962 | FnDef: &ast.Node.FnProto, |
| 2983 | FnProto: &ast.Node.FnProto, | 2963 | FnProto: &ast.Node.FnProto, |
| ... | @@ -3082,25 +3062,29 @@ const State = union(enum) { | ... | @@ -3082,25 +3062,29 @@ const State = union(enum) { |
| 3082 | OptionalTokenSave: OptionalTokenSave, | 3062 | OptionalTokenSave: OptionalTokenSave, |
| 3083 | }; | 3063 | }; |
| 3084 | | 3064 | |
| | 3065 | fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&ast.Node.DocComment) !void { |
| | 3066 | const node = blk: { |
| | 3067 | if (*result) |comment_node| { |
| | 3068 | break :blk comment_node; |
| | 3069 | } else { |
| | 3070 | const comment_node = try arena.construct(ast.Node.DocComment { |
| | 3071 | .base = ast.Node { |
| | 3072 | .id = ast.Node.Id.DocComment, |
| | 3073 | }, |
| | 3074 | .lines = ast.Node.DocComment.LineList.init(arena), |
| | 3075 | }); |
| | 3076 | *result = comment_node; |
| | 3077 | break :blk comment_node; |
| | 3078 | } |
| | 3079 | }; |
| | 3080 | try node.lines.push(line_comment); |
| | 3081 | } |
| | 3082 | |
| 3085 | fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) !?&ast.Node.DocComment { | 3083 | fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) !?&ast.Node.DocComment { |
| 3086 | var result: ?&ast.Node.DocComment = null; | 3084 | var result: ?&ast.Node.DocComment = null; |
| 3087 | while (true) { | 3085 | while (true) { |
| 3088 | if (eatToken(tok_it, tree, Token.Id.DocComment)) |line_comment| { | 3086 | if (eatToken(tok_it, tree, Token.Id.DocComment)) |line_comment| { |
| 3089 | const node = blk: { | 3087 | try pushDocComment(arena, line_comment, &result); |
| 3090 | if (result) |comment_node| { | | |
| 3091 | break :blk comment_node; | | |
| 3092 | } else { | | |
| 3093 | const comment_node = try arena.construct(ast.Node.DocComment { | | |
| 3094 | .base = ast.Node { | | |
| 3095 | .id = ast.Node.Id.DocComment, | | |
| 3096 | }, | | |
| 3097 | .lines = ast.Node.DocComment.LineList.init(arena), | | |
| 3098 | }); | | |
| 3099 | result = comment_node; | | |
| 3100 | break :blk comment_node; | | |
| 3101 | } | | |
| 3102 | }; | | |
| 3103 | try node.lines.push(line_comment); | | |
| 3104 | continue; | 3088 | continue; |
| 3105 | } | 3089 | } |
| 3106 | break; | 3090 | break; |
| ... | @@ -3155,31 +3139,29 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con | ... | @@ -3155,31 +3139,29 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con |
| 3155 | token_ptr: &const Token, token_index: TokenIndex) !bool { | 3139 | token_ptr: &const Token, token_index: TokenIndex) !bool { |
| 3156 | switch (token_ptr.id) { | 3140 | switch (token_ptr.id) { |
| 3157 | Token.Id.Keyword_suspend => { | 3141 | Token.Id.Keyword_suspend => { |
| 3158 | const node = try createToCtxNode(arena, ctx, ast.Node.Suspend, | 3142 | const node = try arena.construct(ast.Node.Suspend { |
| 3159 | ast.Node.Suspend { | 3143 | .base = ast.Node {.id = ast.Node.Id.Suspend }, |
| 3160 | .base = undefined, | 3144 | .label = null, |
| 3161 | .label = null, | 3145 | .suspend_token = token_index, |
| 3162 | .suspend_token = token_index, | 3146 | .payload = null, |
| 3163 | .payload = null, | 3147 | .body = null, |
| 3164 | .body = null, | 3148 | }); |
| 3165 | } | 3149 | ctx.store(&node.base); |
| 3166 | ); | | |
| 3167 | | 3150 | |
| 3168 | stack.append(State { .SuspendBody = node }) catch unreachable; | 3151 | stack.append(State { .SuspendBody = node }) catch unreachable; |
| 3169 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); | 3152 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); |
| 3170 | return true; | 3153 | return true; |
| 3171 | }, | 3154 | }, |
| 3172 | Token.Id.Keyword_if => { | 3155 | Token.Id.Keyword_if => { |
| 3173 | const node = try createToCtxNode(arena, ctx, ast.Node.If, | 3156 | const node = try arena.construct(ast.Node.If { |
| 3174 | ast.Node.If { | 3157 | .base = ast.Node {.id = ast.Node.Id.If }, |
| 3175 | .base = undefined, | 3158 | .if_token = token_index, |
| 3176 | .if_token = token_index, | 3159 | .condition = undefined, |
| 3177 | .condition = undefined, | 3160 | .payload = null, |
| 3178 | .payload = null, | 3161 | .body = undefined, |
| 3179 | .body = undefined, | 3162 | .@"else" = null, |
| 3180 | .@"else" = null, | 3163 | }); |
| 3181 | } | 3164 | ctx.store(&node.base); |
| 3182 | ); | | |
| 3183 | | 3165 | |
| 3184 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 3166 | stack.append(State { .Else = &node.@"else" }) catch unreachable; |
| 3185 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 3167 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); |
| ... | @@ -3236,14 +3218,14 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con | ... | @@ -3236,14 +3218,14 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con |
| 3236 | return true; | 3218 | return true; |
| 3237 | }, | 3219 | }, |
| 3238 | Token.Id.Keyword_comptime => { | 3220 | Token.Id.Keyword_comptime => { |
| 3239 | const node = try createToCtxNode(arena, ctx, ast.Node.Comptime, | 3221 | const node = try arena.construct(ast.Node.Comptime { |
| 3240 | ast.Node.Comptime { | 3222 | .base = ast.Node {.id = ast.Node.Id.Comptime }, |
| 3241 | .base = undefined, | 3223 | .comptime_token = token_index, |
| 3242 | .comptime_token = token_index, | 3224 | .expr = undefined, |
| 3243 | .expr = undefined, | 3225 | .doc_comments = null, |
| 3244 | .doc_comments = null, | 3226 | }); |
| 3245 | } | 3227 | ctx.store(&node.base); |
| 3246 | ); | 3228 | |
| 3247 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); | 3229 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); |
| 3248 | return true; | 3230 | return true; |
| 3249 | }, | 3231 | }, |
| ... | @@ -3390,33 +3372,11 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op { | ... | @@ -3390,33 +3372,11 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op { |
| 3390 | }; | 3372 | }; |
| 3391 | } | 3373 | } |
| 3392 | | 3374 | |
| 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 { | 3375 | fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T { |
| 3414 | return createNode(arena, T, | 3376 | return arena.construct(T { |
| 3415 | T { | 3377 | .base = ast.Node {.id = ast.Node.typeToId(T)}, |
| 3416 | .base = undefined, | 3378 | .token = token_index, |
| 3417 | .token = token_index, | 3379 | }); |
| 3418 | } | | |
| 3419 | ); | | |
| 3420 | } | 3380 | } |
| 3421 | | 3381 | |
| 3422 | fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, comptime T: type, token_index: TokenIndex) !&T { | 3382 | fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, comptime T: type, token_index: TokenIndex) !&T { |