| ... | ... | @@ -9,7 +9,7 @@ const Error = ast.Error; |
| 9 | 9 | |
| 10 | 10 | /// Result should be freed with tree.deinit() when there are |
| 11 | 11 | /// no more references to any of the tokens or nodes. |
| 12 | | pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 12 | pub fn parse(allocator: *mem.Allocator, source: []const u8) !*ast.Tree { |
| 13 | 13 | var tree_arena = std.heap.ArenaAllocator.init(allocator); |
| 14 | 14 | errdefer tree_arena.deinit(); |
| 15 | 15 | |
| ... | ... | @@ -26,7 +26,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 26 | 26 | .eof_token = undefined, |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | | var tree = ast.Tree{ |
| 29 | const tree = try arena.create(ast.Tree); |
| 30 | tree.* = ast.Tree{ |
| 30 | 31 | .source = source, |
| 31 | 32 | .root_node = root_node, |
| 32 | 33 | .arena_allocator = tree_arena, |
| ... | ... | @@ -57,9 +58,9 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 57 | 58 | |
| 58 | 59 | switch (state) { |
| 59 | 60 | State.TopLevel => { |
| 60 | | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 61 | const comments = try eatDocComments(arena, &tok_it, tree); |
| 61 | 62 | |
| 62 | | const token = nextToken(&tok_it, &tree); |
| 63 | const token = nextToken(&tok_it, tree); |
| 63 | 64 | const token_index = token.index; |
| 64 | 65 | const token_ptr = token.ptr; |
| 65 | 66 | switch (token_ptr.id) { |
| ... | ... | @@ -140,7 +141,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 140 | 141 | continue; |
| 141 | 142 | }, |
| 142 | 143 | else => { |
| 143 | | prevToken(&tok_it, &tree); |
| 144 | prevToken(&tok_it, tree); |
| 144 | 145 | stack.append(State.TopLevel) catch unreachable; |
| 145 | 146 | try stack.append(State{ |
| 146 | 147 | .TopLevelExtern = TopLevelDeclCtx{ |
| ... | ... | @@ -156,7 +157,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 156 | 157 | } |
| 157 | 158 | }, |
| 158 | 159 | State.TopLevelExtern => |ctx| { |
| 159 | | const token = nextToken(&tok_it, &tree); |
| 160 | const token = nextToken(&tok_it, tree); |
| 160 | 161 | const token_index = token.index; |
| 161 | 162 | const token_ptr = token.ptr; |
| 162 | 163 | switch (token_ptr.id) { |
| ... | ... | @@ -191,7 +192,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 191 | 192 | continue; |
| 192 | 193 | }, |
| 193 | 194 | else => { |
| 194 | | prevToken(&tok_it, &tree); |
| 195 | prevToken(&tok_it, tree); |
| 195 | 196 | stack.append(State{ .TopLevelDecl = ctx }) catch unreachable; |
| 196 | 197 | continue; |
| 197 | 198 | }, |
| ... | ... | @@ -199,11 +200,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 199 | 200 | }, |
| 200 | 201 | State.TopLevelLibname => |ctx| { |
| 201 | 202 | const lib_name = blk: { |
| 202 | | const lib_name_token = nextToken(&tok_it, &tree); |
| 203 | const lib_name_token = nextToken(&tok_it, tree); |
| 203 | 204 | const lib_name_token_index = lib_name_token.index; |
| 204 | 205 | const lib_name_token_ptr = lib_name_token.ptr; |
| 205 | | break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, &tree)) orelse { |
| 206 | | prevToken(&tok_it, &tree); |
| 206 | break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, tree)) orelse { |
| 207 | prevToken(&tok_it, tree); |
| 207 | 208 | break :blk null; |
| 208 | 209 | }; |
| 209 | 210 | }; |
| ... | ... | @@ -220,7 +221,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 220 | 221 | continue; |
| 221 | 222 | }, |
| 222 | 223 | State.ThreadLocal => |ctx| { |
| 223 | | const token = nextToken(&tok_it, &tree); |
| 224 | const token = nextToken(&tok_it, tree); |
| 224 | 225 | const token_index = token.index; |
| 225 | 226 | const token_ptr = token.ptr; |
| 226 | 227 | switch (token_ptr.id) { |
| ... | ... | @@ -246,7 +247,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 246 | 247 | } |
| 247 | 248 | }, |
| 248 | 249 | State.TopLevelDecl => |ctx| { |
| 249 | | const token = nextToken(&tok_it, &tree); |
| 250 | const token = nextToken(&tok_it, tree); |
| 250 | 251 | const token_index = token.index; |
| 251 | 252 | const token_ptr = token.ptr; |
| 252 | 253 | switch (token_ptr.id) { |
| ... | ... | @@ -387,7 +388,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 387 | 388 | } |
| 388 | 389 | }, |
| 389 | 390 | State.TopLevelExternOrField => |ctx| { |
| 390 | | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| { |
| 391 | if (eatToken(&tok_it, tree, Token.Id.Identifier)) |identifier| { |
| 391 | 392 | const node = try arena.create(ast.Node.StructField); |
| 392 | 393 | node.* = ast.Node.StructField{ |
| 393 | 394 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| ... | ... | @@ -424,11 +425,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 424 | 425 | }, |
| 425 | 426 | |
| 426 | 427 | State.FieldInitValue => |ctx| { |
| 427 | | const eq_tok = nextToken(&tok_it, &tree); |
| 428 | const eq_tok = nextToken(&tok_it, tree); |
| 428 | 429 | const eq_tok_index = eq_tok.index; |
| 429 | 430 | const eq_tok_ptr = eq_tok.ptr; |
| 430 | 431 | if (eq_tok_ptr.id != Token.Id.Equal) { |
| 431 | | prevToken(&tok_it, &tree); |
| 432 | prevToken(&tok_it, tree); |
| 432 | 433 | continue; |
| 433 | 434 | } |
| 434 | 435 | stack.append(State{ .Expression = ctx }) catch unreachable; |
| ... | ... | @@ -436,7 +437,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 436 | 437 | }, |
| 437 | 438 | |
| 438 | 439 | State.ContainerKind => |ctx| { |
| 439 | | const token = nextToken(&tok_it, &tree); |
| 440 | const token = nextToken(&tok_it, tree); |
| 440 | 441 | const token_index = token.index; |
| 441 | 442 | const token_ptr = token.ptr; |
| 442 | 443 | const node = try arena.create(ast.Node.ContainerDecl); |
| ... | ... | @@ -469,7 +470,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 469 | 470 | }, |
| 470 | 471 | |
| 471 | 472 | State.ContainerInitArgStart => |container_decl| { |
| 472 | | if (eatToken(&tok_it, &tree, Token.Id.LParen) == null) { |
| 473 | if (eatToken(&tok_it, tree, Token.Id.LParen) == null) { |
| 473 | 474 | continue; |
| 474 | 475 | } |
| 475 | 476 | |
| ... | ... | @@ -479,24 +480,24 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 479 | 480 | }, |
| 480 | 481 | |
| 481 | 482 | State.ContainerInitArg => |container_decl| { |
| 482 | | const init_arg_token = nextToken(&tok_it, &tree); |
| 483 | const init_arg_token = nextToken(&tok_it, tree); |
| 483 | 484 | const init_arg_token_index = init_arg_token.index; |
| 484 | 485 | const init_arg_token_ptr = init_arg_token.ptr; |
| 485 | 486 | switch (init_arg_token_ptr.id) { |
| 486 | 487 | Token.Id.Keyword_enum => { |
| 487 | 488 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Enum = null }; |
| 488 | | const lparen_tok = nextToken(&tok_it, &tree); |
| 489 | const lparen_tok = nextToken(&tok_it, tree); |
| 489 | 490 | const lparen_tok_index = lparen_tok.index; |
| 490 | 491 | const lparen_tok_ptr = lparen_tok.ptr; |
| 491 | 492 | if (lparen_tok_ptr.id == Token.Id.LParen) { |
| 492 | 493 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 493 | 494 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &container_decl.init_arg_expr.Enum } }); |
| 494 | 495 | } else { |
| 495 | | prevToken(&tok_it, &tree); |
| 496 | prevToken(&tok_it, tree); |
| 496 | 497 | } |
| 497 | 498 | }, |
| 498 | 499 | else => { |
| 499 | | prevToken(&tok_it, &tree); |
| 500 | prevToken(&tok_it, tree); |
| 500 | 501 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Type = undefined }; |
| 501 | 502 | stack.append(State{ .Expression = OptionalCtx{ .Required = &container_decl.init_arg_expr.Type } }) catch unreachable; |
| 502 | 503 | }, |
| ... | ... | @@ -505,8 +506,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 505 | 506 | }, |
| 506 | 507 | |
| 507 | 508 | State.ContainerDecl => |container_decl| { |
| 508 | | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 509 | | const token = nextToken(&tok_it, &tree); |
| 509 | const comments = try eatDocComments(arena, &tok_it, tree); |
| 510 | const token = nextToken(&tok_it, tree); |
| 510 | 511 | const token_index = token.index; |
| 511 | 512 | const token_ptr = token.ptr; |
| 512 | 513 | switch (token_ptr.id) { |
| ... | ... | @@ -657,7 +658,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 657 | 658 | continue; |
| 658 | 659 | }, |
| 659 | 660 | else => { |
| 660 | | prevToken(&tok_it, &tree); |
| 661 | prevToken(&tok_it, tree); |
| 661 | 662 | stack.append(State{ .ContainerDecl = container_decl }) catch unreachable; |
| 662 | 663 | try stack.append(State{ |
| 663 | 664 | .TopLevelExtern = TopLevelDeclCtx{ |
| ... | ... | @@ -709,7 +710,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 709 | 710 | State.VarDeclAlign => |var_decl| { |
| 710 | 711 | try stack.append(State{ .VarDeclSection = var_decl }); |
| 711 | 712 | |
| 712 | | const next_token = nextToken(&tok_it, &tree); |
| 713 | const next_token = nextToken(&tok_it, tree); |
| 713 | 714 | const next_token_index = next_token.index; |
| 714 | 715 | const next_token_ptr = next_token.ptr; |
| 715 | 716 | if (next_token_ptr.id == Token.Id.Keyword_align) { |
| ... | ... | @@ -719,13 +720,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 719 | 720 | continue; |
| 720 | 721 | } |
| 721 | 722 | |
| 722 | | prevToken(&tok_it, &tree); |
| 723 | prevToken(&tok_it, tree); |
| 723 | 724 | continue; |
| 724 | 725 | }, |
| 725 | 726 | State.VarDeclSection => |var_decl| { |
| 726 | 727 | try stack.append(State{ .VarDeclEq = var_decl }); |
| 727 | 728 | |
| 728 | | const next_token = nextToken(&tok_it, &tree); |
| 729 | const next_token = nextToken(&tok_it, tree); |
| 729 | 730 | const next_token_index = next_token.index; |
| 730 | 731 | const next_token_ptr = next_token.ptr; |
| 731 | 732 | if (next_token_ptr.id == Token.Id.Keyword_linksection) { |
| ... | ... | @@ -735,11 +736,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 735 | 736 | continue; |
| 736 | 737 | } |
| 737 | 738 | |
| 738 | | prevToken(&tok_it, &tree); |
| 739 | prevToken(&tok_it, tree); |
| 739 | 740 | continue; |
| 740 | 741 | }, |
| 741 | 742 | State.VarDeclEq => |var_decl| { |
| 742 | | const token = nextToken(&tok_it, &tree); |
| 743 | const token = nextToken(&tok_it, tree); |
| 743 | 744 | const token_index = token.index; |
| 744 | 745 | const token_ptr = token.ptr; |
| 745 | 746 | switch (token_ptr.id) { |
| ... | ... | @@ -761,7 +762,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 761 | 762 | }, |
| 762 | 763 | |
| 763 | 764 | State.VarDeclSemiColon => |var_decl| { |
| 764 | | const semicolon_token = nextToken(&tok_it, &tree); |
| 765 | const semicolon_token = nextToken(&tok_it, tree); |
| 765 | 766 | |
| 766 | 767 | if (semicolon_token.ptr.id != Token.Id.Semicolon) { |
| 767 | 768 | ((try tree.errors.addOne())).* = Error{ |
| ... | ... | @@ -775,18 +776,18 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 775 | 776 | |
| 776 | 777 | var_decl.semicolon_token = semicolon_token.index; |
| 777 | 778 | |
| 778 | | if (eatToken(&tok_it, &tree, Token.Id.DocComment)) |doc_comment_token| { |
| 779 | if (eatToken(&tok_it, tree, Token.Id.DocComment)) |doc_comment_token| { |
| 779 | 780 | const loc = tree.tokenLocation(semicolon_token.ptr.end, doc_comment_token); |
| 780 | 781 | if (loc.line == 0) { |
| 781 | 782 | try pushDocComment(arena, doc_comment_token, &var_decl.doc_comments); |
| 782 | 783 | } else { |
| 783 | | prevToken(&tok_it, &tree); |
| 784 | prevToken(&tok_it, tree); |
| 784 | 785 | } |
| 785 | 786 | } |
| 786 | 787 | }, |
| 787 | 788 | |
| 788 | 789 | State.FnDef => |fn_proto| { |
| 789 | | const token = nextToken(&tok_it, &tree); |
| 790 | const token = nextToken(&tok_it, tree); |
| 790 | 791 | const token_index = token.index; |
| 791 | 792 | const token_ptr = token.ptr; |
| 792 | 793 | switch (token_ptr.id) { |
| ... | ... | @@ -815,7 +816,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 815 | 816 | try stack.append(State{ .ParamDecl = fn_proto }); |
| 816 | 817 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 817 | 818 | |
| 818 | | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |name_token| { |
| 819 | if (eatToken(&tok_it, tree, Token.Id.Identifier)) |name_token| { |
| 819 | 820 | fn_proto.name_token = name_token; |
| 820 | 821 | } |
| 821 | 822 | continue; |
| ... | ... | @@ -823,7 +824,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 823 | 824 | State.FnProtoAlign => |fn_proto| { |
| 824 | 825 | stack.append(State{ .FnProtoSection = fn_proto }) catch unreachable; |
| 825 | 826 | |
| 826 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_align)) |align_token| { |
| 827 | if (eatToken(&tok_it, tree, Token.Id.Keyword_align)) |align_token| { |
| 827 | 828 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 828 | 829 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &fn_proto.align_expr } }); |
| 829 | 830 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| ... | ... | @@ -833,7 +834,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 833 | 834 | State.FnProtoSection => |fn_proto| { |
| 834 | 835 | stack.append(State{ .FnProtoReturnType = fn_proto }) catch unreachable; |
| 835 | 836 | |
| 836 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_linksection)) |align_token| { |
| 837 | if (eatToken(&tok_it, tree, Token.Id.Keyword_linksection)) |align_token| { |
| 837 | 838 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 838 | 839 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &fn_proto.section_expr } }); |
| 839 | 840 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| ... | ... | @@ -841,7 +842,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 841 | 842 | continue; |
| 842 | 843 | }, |
| 843 | 844 | State.FnProtoReturnType => |fn_proto| { |
| 844 | | const token = nextToken(&tok_it, &tree); |
| 845 | const token = nextToken(&tok_it, tree); |
| 845 | 846 | const token_index = token.index; |
| 846 | 847 | const token_ptr = token.ptr; |
| 847 | 848 | switch (token_ptr.id) { |
| ... | ... | @@ -864,7 +865,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 864 | 865 | } |
| 865 | 866 | } |
| 866 | 867 | |
| 867 | | prevToken(&tok_it, &tree); |
| 868 | prevToken(&tok_it, tree); |
| 868 | 869 | fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = undefined }; |
| 869 | 870 | stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &fn_proto.return_type.Explicit } }) catch unreachable; |
| 870 | 871 | continue; |
| ... | ... | @@ -873,8 +874,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 873 | 874 | }, |
| 874 | 875 | |
| 875 | 876 | State.ParamDecl => |fn_proto| { |
| 876 | | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 877 | | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { |
| 877 | const comments = try eatDocComments(arena, &tok_it, tree); |
| 878 | if (eatToken(&tok_it, tree, Token.Id.RParen)) |_| { |
| 878 | 879 | continue; |
| 879 | 880 | } |
| 880 | 881 | const param_decl = try arena.create(ast.Node.ParamDecl); |
| ... | ... | @@ -900,9 +901,9 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 900 | 901 | continue; |
| 901 | 902 | }, |
| 902 | 903 | State.ParamDeclAliasOrComptime => |param_decl| { |
| 903 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_comptime)) |comptime_token| { |
| 904 | if (eatToken(&tok_it, tree, Token.Id.Keyword_comptime)) |comptime_token| { |
| 904 | 905 | param_decl.comptime_token = comptime_token; |
| 905 | | } else if (eatToken(&tok_it, &tree, Token.Id.Keyword_noalias)) |noalias_token| { |
| 906 | } else if (eatToken(&tok_it, tree, Token.Id.Keyword_noalias)) |noalias_token| { |
| 906 | 907 | param_decl.noalias_token = noalias_token; |
| 907 | 908 | } |
| 908 | 909 | continue; |
| ... | ... | @@ -910,20 +911,20 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 910 | 911 | State.ParamDeclName => |param_decl| { |
| 911 | 912 | // TODO: Here, we eat two tokens in one state. This means that we can't have |
| 912 | 913 | // comments between these two tokens. |
| 913 | | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |ident_token| { |
| 914 | | if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| { |
| 914 | if (eatToken(&tok_it, tree, Token.Id.Identifier)) |ident_token| { |
| 915 | if (eatToken(&tok_it, tree, Token.Id.Colon)) |_| { |
| 915 | 916 | param_decl.name_token = ident_token; |
| 916 | 917 | } else { |
| 917 | | prevToken(&tok_it, &tree); |
| 918 | prevToken(&tok_it, tree); |
| 918 | 919 | } |
| 919 | 920 | } |
| 920 | 921 | continue; |
| 921 | 922 | }, |
| 922 | 923 | State.ParamDeclEnd => |ctx| { |
| 923 | | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 924 | if (eatToken(&tok_it, tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 924 | 925 | ctx.param_decl.var_args_token = ellipsis3; |
| 925 | 926 | |
| 926 | | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) { |
| 927 | switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RParen)) { |
| 927 | 928 | ExpectCommaOrEndResult.end_token => |t| { |
| 928 | 929 | if (t == null) { |
| 929 | 930 | stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable; |
| ... | ... | @@ -943,7 +944,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 943 | 944 | continue; |
| 944 | 945 | }, |
| 945 | 946 | State.ParamDeclComma => |fn_proto| { |
| 946 | | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) { |
| 947 | switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RParen)) { |
| 947 | 948 | ExpectCommaOrEndResult.end_token => |t| { |
| 948 | 949 | if (t == null) { |
| 949 | 950 | stack.append(State{ .ParamDecl = fn_proto }) catch unreachable; |
| ... | ... | @@ -958,7 +959,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 958 | 959 | }, |
| 959 | 960 | |
| 960 | 961 | State.MaybeLabeledExpression => |ctx| { |
| 961 | | if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| { |
| 962 | if (eatToken(&tok_it, tree, Token.Id.Colon)) |_| { |
| 962 | 963 | stack.append(State{ |
| 963 | 964 | .LabeledExpression = LabelCtx{ |
| 964 | 965 | .label = ctx.label, |
| ... | ... | @@ -972,7 +973,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 972 | 973 | continue; |
| 973 | 974 | }, |
| 974 | 975 | State.LabeledExpression => |ctx| { |
| 975 | | const token = nextToken(&tok_it, &tree); |
| 976 | const token = nextToken(&tok_it, tree); |
| 976 | 977 | const token_index = token.index; |
| 977 | 978 | const token_ptr = token.ptr; |
| 978 | 979 | switch (token_ptr.id) { |
| ... | ... | @@ -1027,13 +1028,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1027 | 1028 | return tree; |
| 1028 | 1029 | } |
| 1029 | 1030 | |
| 1030 | | prevToken(&tok_it, &tree); |
| 1031 | prevToken(&tok_it, tree); |
| 1031 | 1032 | continue; |
| 1032 | 1033 | }, |
| 1033 | 1034 | } |
| 1034 | 1035 | }, |
| 1035 | 1036 | State.Inline => |ctx| { |
| 1036 | | const token = nextToken(&tok_it, &tree); |
| 1037 | const token = nextToken(&tok_it, tree); |
| 1037 | 1038 | const token_index = token.index; |
| 1038 | 1039 | const token_ptr = token.ptr; |
| 1039 | 1040 | switch (token_ptr.id) { |
| ... | ... | @@ -1065,7 +1066,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1065 | 1066 | return tree; |
| 1066 | 1067 | } |
| 1067 | 1068 | |
| 1068 | | prevToken(&tok_it, &tree); |
| 1069 | prevToken(&tok_it, tree); |
| 1069 | 1070 | continue; |
| 1070 | 1071 | }, |
| 1071 | 1072 | } |
| ... | ... | @@ -1122,7 +1123,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1122 | 1123 | continue; |
| 1123 | 1124 | }, |
| 1124 | 1125 | State.Else => |dest| { |
| 1125 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 1126 | if (eatToken(&tok_it, tree, Token.Id.Keyword_else)) |else_token| { |
| 1126 | 1127 | const node = try arena.create(ast.Node.Else); |
| 1127 | 1128 | node.* = ast.Node.Else{ |
| 1128 | 1129 | .base = ast.Node{ .id = ast.Node.Id.Else }, |
| ... | ... | @@ -1141,7 +1142,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1141 | 1142 | }, |
| 1142 | 1143 | |
| 1143 | 1144 | State.Block => |block| { |
| 1144 | | const token = nextToken(&tok_it, &tree); |
| 1145 | const token = nextToken(&tok_it, tree); |
| 1145 | 1146 | const token_index = token.index; |
| 1146 | 1147 | const token_ptr = token.ptr; |
| 1147 | 1148 | switch (token_ptr.id) { |
| ... | ... | @@ -1150,7 +1151,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1150 | 1151 | continue; |
| 1151 | 1152 | }, |
| 1152 | 1153 | else => { |
| 1153 | | prevToken(&tok_it, &tree); |
| 1154 | prevToken(&tok_it, tree); |
| 1154 | 1155 | stack.append(State{ .Block = block }) catch unreachable; |
| 1155 | 1156 | |
| 1156 | 1157 | try stack.append(State{ .Statement = block }); |
| ... | ... | @@ -1159,7 +1160,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1159 | 1160 | } |
| 1160 | 1161 | }, |
| 1161 | 1162 | State.Statement => |block| { |
| 1162 | | const token = nextToken(&tok_it, &tree); |
| 1163 | const token = nextToken(&tok_it, tree); |
| 1163 | 1164 | const token_index = token.index; |
| 1164 | 1165 | const token_ptr = token.ptr; |
| 1165 | 1166 | switch (token_ptr.id) { |
| ... | ... | @@ -1216,7 +1217,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1216 | 1217 | continue; |
| 1217 | 1218 | }, |
| 1218 | 1219 | else => { |
| 1219 | | prevToken(&tok_it, &tree); |
| 1220 | prevToken(&tok_it, tree); |
| 1220 | 1221 | const statement = try block.statements.addOne(); |
| 1221 | 1222 | try stack.append(State{ .Semicolon = statement }); |
| 1222 | 1223 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } }); |
| ... | ... | @@ -1225,7 +1226,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1225 | 1226 | } |
| 1226 | 1227 | }, |
| 1227 | 1228 | State.ComptimeStatement => |ctx| { |
| 1228 | | const token = nextToken(&tok_it, &tree); |
| 1229 | const token = nextToken(&tok_it, tree); |
| 1229 | 1230 | const token_index = token.index; |
| 1230 | 1231 | const token_ptr = token.ptr; |
| 1231 | 1232 | switch (token_ptr.id) { |
| ... | ... | @@ -1245,8 +1246,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1245 | 1246 | continue; |
| 1246 | 1247 | }, |
| 1247 | 1248 | else => { |
| 1248 | | prevToken(&tok_it, &tree); |
| 1249 | | prevToken(&tok_it, &tree); |
| 1249 | prevToken(&tok_it, tree); |
| 1250 | prevToken(&tok_it, tree); |
| 1250 | 1251 | const statement = try ctx.block.statements.addOne(); |
| 1251 | 1252 | try stack.append(State{ .Semicolon = statement }); |
| 1252 | 1253 | try stack.append(State{ .Expression = OptionalCtx{ .Required = statement } }); |
| ... | ... | @@ -1264,11 +1265,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1264 | 1265 | }, |
| 1265 | 1266 | |
| 1266 | 1267 | State.AsmOutputItems => |items| { |
| 1267 | | const lbracket = nextToken(&tok_it, &tree); |
| 1268 | const lbracket = nextToken(&tok_it, tree); |
| 1268 | 1269 | const lbracket_index = lbracket.index; |
| 1269 | 1270 | const lbracket_ptr = lbracket.ptr; |
| 1270 | 1271 | if (lbracket_ptr.id != Token.Id.LBracket) { |
| 1271 | | prevToken(&tok_it, &tree); |
| 1272 | prevToken(&tok_it, tree); |
| 1272 | 1273 | continue; |
| 1273 | 1274 | } |
| 1274 | 1275 | |
| ... | ... | @@ -1299,7 +1300,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1299 | 1300 | continue; |
| 1300 | 1301 | }, |
| 1301 | 1302 | State.AsmOutputReturnOrType => |node| { |
| 1302 | | const token = nextToken(&tok_it, &tree); |
| 1303 | const token = nextToken(&tok_it, tree); |
| 1303 | 1304 | const token_index = token.index; |
| 1304 | 1305 | const token_ptr = token.ptr; |
| 1305 | 1306 | switch (token_ptr.id) { |
| ... | ... | @@ -1319,11 +1320,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1319 | 1320 | } |
| 1320 | 1321 | }, |
| 1321 | 1322 | State.AsmInputItems => |items| { |
| 1322 | | const lbracket = nextToken(&tok_it, &tree); |
| 1323 | const lbracket = nextToken(&tok_it, tree); |
| 1323 | 1324 | const lbracket_index = lbracket.index; |
| 1324 | 1325 | const lbracket_ptr = lbracket.ptr; |
| 1325 | 1326 | if (lbracket_ptr.id != Token.Id.LBracket) { |
| 1326 | | prevToken(&tok_it, &tree); |
| 1327 | prevToken(&tok_it, tree); |
| 1327 | 1328 | continue; |
| 1328 | 1329 | } |
| 1329 | 1330 | |
| ... | ... | @@ -1354,16 +1355,16 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1354 | 1355 | continue; |
| 1355 | 1356 | }, |
| 1356 | 1357 | State.AsmClobberItems => |items| { |
| 1357 | | while (eatToken(&tok_it, &tree, Token.Id.StringLiteral)) |strlit| { |
| 1358 | while (eatToken(&tok_it, tree, Token.Id.StringLiteral)) |strlit| { |
| 1358 | 1359 | try items.push(strlit); |
| 1359 | | if (eatToken(&tok_it, &tree, Token.Id.Comma) == null) |
| 1360 | if (eatToken(&tok_it, tree, Token.Id.Comma) == null) |
| 1360 | 1361 | break; |
| 1361 | 1362 | } |
| 1362 | 1363 | continue; |
| 1363 | 1364 | }, |
| 1364 | 1365 | |
| 1365 | 1366 | State.ExprListItemOrEnd => |list_state| { |
| 1366 | | if (eatToken(&tok_it, &tree, list_state.end)) |token_index| { |
| 1367 | if (eatToken(&tok_it, tree, list_state.end)) |token_index| { |
| 1367 | 1368 | (list_state.ptr).* = token_index; |
| 1368 | 1369 | continue; |
| 1369 | 1370 | } |
| ... | ... | @@ -1373,7 +1374,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1373 | 1374 | continue; |
| 1374 | 1375 | }, |
| 1375 | 1376 | State.ExprListCommaOrEnd => |list_state| { |
| 1376 | | switch (expectCommaOrEnd(&tok_it, &tree, list_state.end)) { |
| 1377 | switch (expectCommaOrEnd(&tok_it, tree, list_state.end)) { |
| 1377 | 1378 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1378 | 1379 | (list_state.ptr).* = end; |
| 1379 | 1380 | continue; |
| ... | ... | @@ -1388,7 +1389,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1388 | 1389 | } |
| 1389 | 1390 | }, |
| 1390 | 1391 | State.FieldInitListItemOrEnd => |list_state| { |
| 1391 | | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { |
| 1392 | if (eatToken(&tok_it, tree, Token.Id.RBrace)) |rbrace| { |
| 1392 | 1393 | (list_state.ptr).* = rbrace; |
| 1393 | 1394 | continue; |
| 1394 | 1395 | } |
| ... | ... | @@ -1420,7 +1421,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1420 | 1421 | continue; |
| 1421 | 1422 | }, |
| 1422 | 1423 | State.FieldInitListCommaOrEnd => |list_state| { |
| 1423 | | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) { |
| 1424 | switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RBrace)) { |
| 1424 | 1425 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1425 | 1426 | (list_state.ptr).* = end; |
| 1426 | 1427 | continue; |
| ... | ... | @@ -1435,17 +1436,17 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1435 | 1436 | } |
| 1436 | 1437 | }, |
| 1437 | 1438 | State.FieldListCommaOrEnd => |field_ctx| { |
| 1438 | | const end_token = nextToken(&tok_it, &tree); |
| 1439 | const end_token = nextToken(&tok_it, tree); |
| 1439 | 1440 | const end_token_index = end_token.index; |
| 1440 | 1441 | const end_token_ptr = end_token.ptr; |
| 1441 | 1442 | switch (end_token_ptr.id) { |
| 1442 | 1443 | Token.Id.Comma => { |
| 1443 | | if (eatToken(&tok_it, &tree, Token.Id.DocComment)) |doc_comment_token| { |
| 1444 | if (eatToken(&tok_it, tree, Token.Id.DocComment)) |doc_comment_token| { |
| 1444 | 1445 | const loc = tree.tokenLocation(end_token_ptr.end, doc_comment_token); |
| 1445 | 1446 | if (loc.line == 0) { |
| 1446 | 1447 | try pushDocComment(arena, doc_comment_token, field_ctx.doc_comments); |
| 1447 | 1448 | } else { |
| 1448 | | prevToken(&tok_it, &tree); |
| 1449 | prevToken(&tok_it, tree); |
| 1449 | 1450 | } |
| 1450 | 1451 | } |
| 1451 | 1452 | |
| ... | ... | @@ -1468,7 +1469,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1468 | 1469 | } |
| 1469 | 1470 | }, |
| 1470 | 1471 | State.ErrorTagListItemOrEnd => |list_state| { |
| 1471 | | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { |
| 1472 | if (eatToken(&tok_it, tree, Token.Id.RBrace)) |rbrace| { |
| 1472 | 1473 | (list_state.ptr).* = rbrace; |
| 1473 | 1474 | continue; |
| 1474 | 1475 | } |
| ... | ... | @@ -1480,7 +1481,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1480 | 1481 | continue; |
| 1481 | 1482 | }, |
| 1482 | 1483 | State.ErrorTagListCommaOrEnd => |list_state| { |
| 1483 | | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) { |
| 1484 | switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RBrace)) { |
| 1484 | 1485 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1485 | 1486 | (list_state.ptr).* = end; |
| 1486 | 1487 | continue; |
| ... | ... | @@ -1495,12 +1496,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1495 | 1496 | } |
| 1496 | 1497 | }, |
| 1497 | 1498 | State.SwitchCaseOrEnd => |list_state| { |
| 1498 | | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { |
| 1499 | if (eatToken(&tok_it, tree, Token.Id.RBrace)) |rbrace| { |
| 1499 | 1500 | (list_state.ptr).* = rbrace; |
| 1500 | 1501 | continue; |
| 1501 | 1502 | } |
| 1502 | 1503 | |
| 1503 | | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 1504 | const comments = try eatDocComments(arena, &tok_it, tree); |
| 1504 | 1505 | const node = try arena.create(ast.Node.SwitchCase); |
| 1505 | 1506 | node.* = ast.Node.SwitchCase{ |
| 1506 | 1507 | .base = ast.Node{ .id = ast.Node.Id.SwitchCase }, |
| ... | ... | @@ -1519,7 +1520,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1519 | 1520 | }, |
| 1520 | 1521 | |
| 1521 | 1522 | State.SwitchCaseCommaOrEnd => |list_state| { |
| 1522 | | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) { |
| 1523 | switch (expectCommaOrEnd(&tok_it, tree, Token.Id.RBrace)) { |
| 1523 | 1524 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1524 | 1525 | (list_state.ptr).* = end; |
| 1525 | 1526 | continue; |
| ... | ... | @@ -1535,7 +1536,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1535 | 1536 | }, |
| 1536 | 1537 | |
| 1537 | 1538 | State.SwitchCaseFirstItem => |switch_case| { |
| 1538 | | const token = nextToken(&tok_it, &tree); |
| 1539 | const token = nextToken(&tok_it, tree); |
| 1539 | 1540 | const token_index = token.index; |
| 1540 | 1541 | const token_ptr = token.ptr; |
| 1541 | 1542 | if (token_ptr.id == Token.Id.Keyword_else) { |
| ... | ... | @@ -1554,26 +1555,26 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1554 | 1555 | }); |
| 1555 | 1556 | continue; |
| 1556 | 1557 | } else { |
| 1557 | | prevToken(&tok_it, &tree); |
| 1558 | prevToken(&tok_it, tree); |
| 1558 | 1559 | stack.append(State{ .SwitchCaseItemCommaOrEnd = switch_case }) catch unreachable; |
| 1559 | 1560 | try stack.append(State{ .RangeExpressionBegin = OptionalCtx{ .Required = try switch_case.items.addOne() } }); |
| 1560 | 1561 | continue; |
| 1561 | 1562 | } |
| 1562 | 1563 | }, |
| 1563 | 1564 | State.SwitchCaseItemOrEnd => |switch_case| { |
| 1564 | | const token = nextToken(&tok_it, &tree); |
| 1565 | const token = nextToken(&tok_it, tree); |
| 1565 | 1566 | if (token.ptr.id == Token.Id.EqualAngleBracketRight) { |
| 1566 | 1567 | switch_case.arrow_token = token.index; |
| 1567 | 1568 | continue; |
| 1568 | 1569 | } else { |
| 1569 | | prevToken(&tok_it, &tree); |
| 1570 | prevToken(&tok_it, tree); |
| 1570 | 1571 | stack.append(State{ .SwitchCaseItemCommaOrEnd = switch_case }) catch unreachable; |
| 1571 | 1572 | try stack.append(State{ .RangeExpressionBegin = OptionalCtx{ .Required = try switch_case.items.addOne() } }); |
| 1572 | 1573 | continue; |
| 1573 | 1574 | } |
| 1574 | 1575 | }, |
| 1575 | 1576 | State.SwitchCaseItemCommaOrEnd => |switch_case| { |
| 1576 | | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.EqualAngleBracketRight)) { |
| 1577 | switch (expectCommaOrEnd(&tok_it, tree, Token.Id.EqualAngleBracketRight)) { |
| 1577 | 1578 | ExpectCommaOrEndResult.end_token => |end_token| { |
| 1578 | 1579 | if (end_token) |t| { |
| 1579 | 1580 | switch_case.arrow_token = t; |
| ... | ... | @@ -1591,14 +1592,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1591 | 1592 | }, |
| 1592 | 1593 | |
| 1593 | 1594 | State.SuspendBody => |suspend_node| { |
| 1594 | | const token = nextToken(&tok_it, &tree); |
| 1595 | const token = nextToken(&tok_it, tree); |
| 1595 | 1596 | switch (token.ptr.id) { |
| 1596 | 1597 | Token.Id.Semicolon => { |
| 1597 | | prevToken(&tok_it, &tree); |
| 1598 | prevToken(&tok_it, tree); |
| 1598 | 1599 | continue; |
| 1599 | 1600 | }, |
| 1600 | 1601 | Token.Id.LBrace => { |
| 1601 | | prevToken(&tok_it, &tree); |
| 1602 | prevToken(&tok_it, tree); |
| 1602 | 1603 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .RequiredNull = &suspend_node.body } }); |
| 1603 | 1604 | continue; |
| 1604 | 1605 | }, |
| ... | ... | @@ -1608,7 +1609,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1608 | 1609 | } |
| 1609 | 1610 | }, |
| 1610 | 1611 | State.AsyncAllocator => |async_node| { |
| 1611 | | if (eatToken(&tok_it, &tree, Token.Id.AngleBracketLeft) == null) { |
| 1612 | if (eatToken(&tok_it, tree, Token.Id.AngleBracketLeft) == null) { |
| 1612 | 1613 | continue; |
| 1613 | 1614 | } |
| 1614 | 1615 | |
| ... | ... | @@ -1649,7 +1650,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1649 | 1650 | }, |
| 1650 | 1651 | |
| 1651 | 1652 | State.ExternType => |ctx| { |
| 1652 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| { |
| 1653 | if (eatToken(&tok_it, tree, Token.Id.Keyword_fn)) |fn_token| { |
| 1653 | 1654 | const fn_proto = try arena.create(ast.Node.FnProto); |
| 1654 | 1655 | fn_proto.* = ast.Node.FnProto{ |
| 1655 | 1656 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| ... | ... | @@ -1682,7 +1683,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1682 | 1683 | continue; |
| 1683 | 1684 | }, |
| 1684 | 1685 | State.SliceOrArrayAccess => |node| { |
| 1685 | | const token = nextToken(&tok_it, &tree); |
| 1686 | const token = nextToken(&tok_it, tree); |
| 1686 | 1687 | const token_index = token.index; |
| 1687 | 1688 | const token_ptr = token.ptr; |
| 1688 | 1689 | switch (token_ptr.id) { |
| ... | ... | @@ -1715,7 +1716,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1715 | 1716 | } |
| 1716 | 1717 | }, |
| 1717 | 1718 | State.SliceOrArrayType => |node| { |
| 1718 | | if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| { |
| 1719 | if (eatToken(&tok_it, tree, Token.Id.RBracket)) |_| { |
| 1719 | 1720 | node.op = ast.Node.PrefixOp.Op{ |
| 1720 | 1721 | .SliceType = ast.Node.PrefixOp.PtrInfo{ |
| 1721 | 1722 | .align_info = null, |
| ... | ... | @@ -1737,7 +1738,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1737 | 1738 | }, |
| 1738 | 1739 | |
| 1739 | 1740 | State.PtrTypeModifiers => |addr_of_info| { |
| 1740 | | const token = nextToken(&tok_it, &tree); |
| 1741 | const token = nextToken(&tok_it, tree); |
| 1741 | 1742 | const token_index = token.index; |
| 1742 | 1743 | const token_ptr = token.ptr; |
| 1743 | 1744 | switch (token_ptr.id) { |
| ... | ... | @@ -1787,14 +1788,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1787 | 1788 | continue; |
| 1788 | 1789 | }, |
| 1789 | 1790 | else => { |
| 1790 | | prevToken(&tok_it, &tree); |
| 1791 | prevToken(&tok_it, tree); |
| 1791 | 1792 | continue; |
| 1792 | 1793 | }, |
| 1793 | 1794 | } |
| 1794 | 1795 | }, |
| 1795 | 1796 | |
| 1796 | 1797 | State.AlignBitRange => |align_info| { |
| 1797 | | const token = nextToken(&tok_it, &tree); |
| 1798 | const token = nextToken(&tok_it, tree); |
| 1798 | 1799 | switch (token.ptr.id) { |
| 1799 | 1800 | Token.Id.Colon => { |
| 1800 | 1801 | align_info.bit_range = ast.Node.PrefixOp.PtrInfo.Align.BitRange(undefined); |
| ... | ... | @@ -1817,7 +1818,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1817 | 1818 | }, |
| 1818 | 1819 | |
| 1819 | 1820 | State.Payload => |opt_ctx| { |
| 1820 | | const token = nextToken(&tok_it, &tree); |
| 1821 | const token = nextToken(&tok_it, tree); |
| 1821 | 1822 | const token_index = token.index; |
| 1822 | 1823 | const token_ptr = token.ptr; |
| 1823 | 1824 | if (token_ptr.id != Token.Id.Pipe) { |
| ... | ... | @@ -1831,7 +1832,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1831 | 1832 | return tree; |
| 1832 | 1833 | } |
| 1833 | 1834 | |
| 1834 | | prevToken(&tok_it, &tree); |
| 1835 | prevToken(&tok_it, tree); |
| 1835 | 1836 | continue; |
| 1836 | 1837 | } |
| 1837 | 1838 | |
| ... | ... | @@ -1854,7 +1855,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1854 | 1855 | continue; |
| 1855 | 1856 | }, |
| 1856 | 1857 | State.PointerPayload => |opt_ctx| { |
| 1857 | | const token = nextToken(&tok_it, &tree); |
| 1858 | const token = nextToken(&tok_it, tree); |
| 1858 | 1859 | const token_index = token.index; |
| 1859 | 1860 | const token_ptr = token.ptr; |
| 1860 | 1861 | if (token_ptr.id != Token.Id.Pipe) { |
| ... | ... | @@ -1868,7 +1869,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1868 | 1869 | return tree; |
| 1869 | 1870 | } |
| 1870 | 1871 | |
| 1871 | | prevToken(&tok_it, &tree); |
| 1872 | prevToken(&tok_it, tree); |
| 1872 | 1873 | continue; |
| 1873 | 1874 | } |
| 1874 | 1875 | |
| ... | ... | @@ -1898,7 +1899,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1898 | 1899 | continue; |
| 1899 | 1900 | }, |
| 1900 | 1901 | State.PointerIndexPayload => |opt_ctx| { |
| 1901 | | const token = nextToken(&tok_it, &tree); |
| 1902 | const token = nextToken(&tok_it, tree); |
| 1902 | 1903 | const token_index = token.index; |
| 1903 | 1904 | const token_ptr = token.ptr; |
| 1904 | 1905 | if (token_ptr.id != Token.Id.Pipe) { |
| ... | ... | @@ -1912,7 +1913,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1912 | 1913 | return tree; |
| 1913 | 1914 | } |
| 1914 | 1915 | |
| 1915 | | prevToken(&tok_it, &tree); |
| 1916 | prevToken(&tok_it, tree); |
| 1916 | 1917 | continue; |
| 1917 | 1918 | } |
| 1918 | 1919 | |
| ... | ... | @@ -1946,7 +1947,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1946 | 1947 | }, |
| 1947 | 1948 | |
| 1948 | 1949 | State.Expression => |opt_ctx| { |
| 1949 | | const token = nextToken(&tok_it, &tree); |
| 1950 | const token = nextToken(&tok_it, tree); |
| 1950 | 1951 | const token_index = token.index; |
| 1951 | 1952 | const token_ptr = token.ptr; |
| 1952 | 1953 | switch (token_ptr.id) { |
| ... | ... | @@ -2000,7 +2001,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2000 | 2001 | }, |
| 2001 | 2002 | else => { |
| 2002 | 2003 | if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr.*, token_index)) { |
| 2003 | | prevToken(&tok_it, &tree); |
| 2004 | prevToken(&tok_it, tree); |
| 2004 | 2005 | stack.append(State{ .UnwrapExpressionBegin = opt_ctx }) catch unreachable; |
| 2005 | 2006 | } |
| 2006 | 2007 | continue; |
| ... | ... | @@ -2015,7 +2016,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2015 | 2016 | State.RangeExpressionEnd => |opt_ctx| { |
| 2016 | 2017 | const lhs = opt_ctx.get() orelse continue; |
| 2017 | 2018 | |
| 2018 | | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 2019 | if (eatToken(&tok_it, tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 2019 | 2020 | const node = try arena.create(ast.Node.InfixOp); |
| 2020 | 2021 | node.* = ast.Node.InfixOp{ |
| 2021 | 2022 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2038,7 +2039,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2038 | 2039 | State.AssignmentExpressionEnd => |opt_ctx| { |
| 2039 | 2040 | const lhs = opt_ctx.get() orelse continue; |
| 2040 | 2041 | |
| 2041 | | const token = nextToken(&tok_it, &tree); |
| 2042 | const token = nextToken(&tok_it, tree); |
| 2042 | 2043 | const token_index = token.index; |
| 2043 | 2044 | const token_ptr = token.ptr; |
| 2044 | 2045 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { |
| ... | ... | @@ -2055,7 +2056,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2055 | 2056 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }); |
| 2056 | 2057 | continue; |
| 2057 | 2058 | } else { |
| 2058 | | prevToken(&tok_it, &tree); |
| 2059 | prevToken(&tok_it, tree); |
| 2059 | 2060 | continue; |
| 2060 | 2061 | } |
| 2061 | 2062 | }, |
| ... | ... | @@ -2069,7 +2070,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2069 | 2070 | State.UnwrapExpressionEnd => |opt_ctx| { |
| 2070 | 2071 | const lhs = opt_ctx.get() orelse continue; |
| 2071 | 2072 | |
| 2072 | | const token = nextToken(&tok_it, &tree); |
| 2073 | const token = nextToken(&tok_it, tree); |
| 2073 | 2074 | const token_index = token.index; |
| 2074 | 2075 | const token_ptr = token.ptr; |
| 2075 | 2076 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { |
| ... | ... | @@ -2091,7 +2092,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2091 | 2092 | } |
| 2092 | 2093 | continue; |
| 2093 | 2094 | } else { |
| 2094 | | prevToken(&tok_it, &tree); |
| 2095 | prevToken(&tok_it, tree); |
| 2095 | 2096 | continue; |
| 2096 | 2097 | } |
| 2097 | 2098 | }, |
| ... | ... | @@ -2105,7 +2106,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2105 | 2106 | State.BoolOrExpressionEnd => |opt_ctx| { |
| 2106 | 2107 | const lhs = opt_ctx.get() orelse continue; |
| 2107 | 2108 | |
| 2108 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 2109 | if (eatToken(&tok_it, tree, Token.Id.Keyword_or)) |or_token| { |
| 2109 | 2110 | const node = try arena.create(ast.Node.InfixOp); |
| 2110 | 2111 | node.* = ast.Node.InfixOp{ |
| 2111 | 2112 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2130,7 +2131,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2130 | 2131 | State.BoolAndExpressionEnd => |opt_ctx| { |
| 2131 | 2132 | const lhs = opt_ctx.get() orelse continue; |
| 2132 | 2133 | |
| 2133 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 2134 | if (eatToken(&tok_it, tree, Token.Id.Keyword_and)) |and_token| { |
| 2134 | 2135 | const node = try arena.create(ast.Node.InfixOp); |
| 2135 | 2136 | node.* = ast.Node.InfixOp{ |
| 2136 | 2137 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2155,7 +2156,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2155 | 2156 | State.ComparisonExpressionEnd => |opt_ctx| { |
| 2156 | 2157 | const lhs = opt_ctx.get() orelse continue; |
| 2157 | 2158 | |
| 2158 | | const token = nextToken(&tok_it, &tree); |
| 2159 | const token = nextToken(&tok_it, tree); |
| 2159 | 2160 | const token_index = token.index; |
| 2160 | 2161 | const token_ptr = token.ptr; |
| 2161 | 2162 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { |
| ... | ... | @@ -2172,7 +2173,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2172 | 2173 | try stack.append(State{ .BinaryOrExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2173 | 2174 | continue; |
| 2174 | 2175 | } else { |
| 2175 | | prevToken(&tok_it, &tree); |
| 2176 | prevToken(&tok_it, tree); |
| 2176 | 2177 | continue; |
| 2177 | 2178 | } |
| 2178 | 2179 | }, |
| ... | ... | @@ -2186,7 +2187,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2186 | 2187 | State.BinaryOrExpressionEnd => |opt_ctx| { |
| 2187 | 2188 | const lhs = opt_ctx.get() orelse continue; |
| 2188 | 2189 | |
| 2189 | | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 2190 | if (eatToken(&tok_it, tree, Token.Id.Pipe)) |pipe| { |
| 2190 | 2191 | const node = try arena.create(ast.Node.InfixOp); |
| 2191 | 2192 | node.* = ast.Node.InfixOp{ |
| 2192 | 2193 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2211,7 +2212,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2211 | 2212 | State.BinaryXorExpressionEnd => |opt_ctx| { |
| 2212 | 2213 | const lhs = opt_ctx.get() orelse continue; |
| 2213 | 2214 | |
| 2214 | | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2215 | if (eatToken(&tok_it, tree, Token.Id.Caret)) |caret| { |
| 2215 | 2216 | const node = try arena.create(ast.Node.InfixOp); |
| 2216 | 2217 | node.* = ast.Node.InfixOp{ |
| 2217 | 2218 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2236,7 +2237,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2236 | 2237 | State.BinaryAndExpressionEnd => |opt_ctx| { |
| 2237 | 2238 | const lhs = opt_ctx.get() orelse continue; |
| 2238 | 2239 | |
| 2239 | | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2240 | if (eatToken(&tok_it, tree, Token.Id.Ampersand)) |ampersand| { |
| 2240 | 2241 | const node = try arena.create(ast.Node.InfixOp); |
| 2241 | 2242 | node.* = ast.Node.InfixOp{ |
| 2242 | 2243 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2261,7 +2262,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2261 | 2262 | State.BitShiftExpressionEnd => |opt_ctx| { |
| 2262 | 2263 | const lhs = opt_ctx.get() orelse continue; |
| 2263 | 2264 | |
| 2264 | | const token = nextToken(&tok_it, &tree); |
| 2265 | const token = nextToken(&tok_it, tree); |
| 2265 | 2266 | const token_index = token.index; |
| 2266 | 2267 | const token_ptr = token.ptr; |
| 2267 | 2268 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { |
| ... | ... | @@ -2278,7 +2279,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2278 | 2279 | try stack.append(State{ .AdditionExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2279 | 2280 | continue; |
| 2280 | 2281 | } else { |
| 2281 | | prevToken(&tok_it, &tree); |
| 2282 | prevToken(&tok_it, tree); |
| 2282 | 2283 | continue; |
| 2283 | 2284 | } |
| 2284 | 2285 | }, |
| ... | ... | @@ -2292,7 +2293,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2292 | 2293 | State.AdditionExpressionEnd => |opt_ctx| { |
| 2293 | 2294 | const lhs = opt_ctx.get() orelse continue; |
| 2294 | 2295 | |
| 2295 | | const token = nextToken(&tok_it, &tree); |
| 2296 | const token = nextToken(&tok_it, tree); |
| 2296 | 2297 | const token_index = token.index; |
| 2297 | 2298 | const token_ptr = token.ptr; |
| 2298 | 2299 | if (tokenIdToAddition(token_ptr.id)) |add_id| { |
| ... | ... | @@ -2309,7 +2310,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2309 | 2310 | try stack.append(State{ .MultiplyExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2310 | 2311 | continue; |
| 2311 | 2312 | } else { |
| 2312 | | prevToken(&tok_it, &tree); |
| 2313 | prevToken(&tok_it, tree); |
| 2313 | 2314 | continue; |
| 2314 | 2315 | } |
| 2315 | 2316 | }, |
| ... | ... | @@ -2323,7 +2324,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2323 | 2324 | State.MultiplyExpressionEnd => |opt_ctx| { |
| 2324 | 2325 | const lhs = opt_ctx.get() orelse continue; |
| 2325 | 2326 | |
| 2326 | | const token = nextToken(&tok_it, &tree); |
| 2327 | const token = nextToken(&tok_it, tree); |
| 2327 | 2328 | const token_index = token.index; |
| 2328 | 2329 | const token_ptr = token.ptr; |
| 2329 | 2330 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { |
| ... | ... | @@ -2340,7 +2341,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2340 | 2341 | try stack.append(State{ .CurlySuffixExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2341 | 2342 | continue; |
| 2342 | 2343 | } else { |
| 2343 | | prevToken(&tok_it, &tree); |
| 2344 | prevToken(&tok_it, tree); |
| 2344 | 2345 | continue; |
| 2345 | 2346 | } |
| 2346 | 2347 | }, |
| ... | ... | @@ -2405,7 +2406,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2405 | 2406 | State.TypeExprEnd => |opt_ctx| { |
| 2406 | 2407 | const lhs = opt_ctx.get() orelse continue; |
| 2407 | 2408 | |
| 2408 | | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2409 | if (eatToken(&tok_it, tree, Token.Id.Bang)) |bang| { |
| 2409 | 2410 | const node = try arena.create(ast.Node.InfixOp); |
| 2410 | 2411 | node.* = ast.Node.InfixOp{ |
| 2411 | 2412 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2422,7 +2423,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2422 | 2423 | }, |
| 2423 | 2424 | |
| 2424 | 2425 | State.PrefixOpExpression => |opt_ctx| { |
| 2425 | | const token = nextToken(&tok_it, &tree); |
| 2426 | const token = nextToken(&tok_it, tree); |
| 2426 | 2427 | const token_index = token.index; |
| 2427 | 2428 | const token_ptr = token.ptr; |
| 2428 | 2429 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { |
| ... | ... | @@ -2454,14 +2455,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2454 | 2455 | } |
| 2455 | 2456 | continue; |
| 2456 | 2457 | } else { |
| 2457 | | prevToken(&tok_it, &tree); |
| 2458 | prevToken(&tok_it, tree); |
| 2458 | 2459 | stack.append(State{ .SuffixOpExpressionBegin = opt_ctx }) catch unreachable; |
| 2459 | 2460 | continue; |
| 2460 | 2461 | } |
| 2461 | 2462 | }, |
| 2462 | 2463 | |
| 2463 | 2464 | State.SuffixOpExpressionBegin => |opt_ctx| { |
| 2464 | | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { |
| 2465 | if (eatToken(&tok_it, tree, Token.Id.Keyword_async)) |async_token| { |
| 2465 | 2466 | const async_node = try arena.create(ast.Node.AsyncAttribute); |
| 2466 | 2467 | async_node.* = ast.Node.AsyncAttribute{ |
| 2467 | 2468 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| ... | ... | @@ -2489,7 +2490,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2489 | 2490 | State.SuffixOpExpressionEnd => |opt_ctx| { |
| 2490 | 2491 | const lhs = opt_ctx.get() orelse continue; |
| 2491 | 2492 | |
| 2492 | | const token = nextToken(&tok_it, &tree); |
| 2493 | const token = nextToken(&tok_it, tree); |
| 2493 | 2494 | const token_index = token.index; |
| 2494 | 2495 | const token_ptr = token.ptr; |
| 2495 | 2496 | switch (token_ptr.id) { |
| ... | ... | @@ -2534,7 +2535,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2534 | 2535 | continue; |
| 2535 | 2536 | }, |
| 2536 | 2537 | Token.Id.Period => { |
| 2537 | | if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| { |
| 2538 | if (eatToken(&tok_it, tree, Token.Id.Asterisk)) |asterisk_token| { |
| 2538 | 2539 | const node = try arena.create(ast.Node.SuffixOp); |
| 2539 | 2540 | node.* = ast.Node.SuffixOp{ |
| 2540 | 2541 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| ... | ... | @@ -2546,7 +2547,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2546 | 2547 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2547 | 2548 | continue; |
| 2548 | 2549 | } |
| 2549 | | if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| { |
| 2550 | if (eatToken(&tok_it, tree, Token.Id.QuestionMark)) |question_token| { |
| 2550 | 2551 | const node = try arena.create(ast.Node.SuffixOp); |
| 2551 | 2552 | node.* = ast.Node.SuffixOp{ |
| 2552 | 2553 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| ... | ... | @@ -2573,21 +2574,21 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2573 | 2574 | continue; |
| 2574 | 2575 | }, |
| 2575 | 2576 | else => { |
| 2576 | | prevToken(&tok_it, &tree); |
| 2577 | prevToken(&tok_it, tree); |
| 2577 | 2578 | continue; |
| 2578 | 2579 | }, |
| 2579 | 2580 | } |
| 2580 | 2581 | }, |
| 2581 | 2582 | |
| 2582 | 2583 | State.PrimaryExpression => |opt_ctx| { |
| 2583 | | const token = nextToken(&tok_it, &tree); |
| 2584 | const token = nextToken(&tok_it, tree); |
| 2584 | 2585 | switch (token.ptr.id) { |
| 2585 | 2586 | Token.Id.IntegerLiteral => { |
| 2586 | 2587 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.IntegerLiteral, token.index); |
| 2587 | 2588 | continue; |
| 2588 | 2589 | }, |
| 2589 | 2590 | Token.Id.Period => { |
| 2590 | | const name_token = nextToken(&tok_it, &tree); |
| 2591 | const name_token = nextToken(&tok_it, tree); |
| 2591 | 2592 | if (name_token.ptr.id != Token.Id.Identifier) { |
| 2592 | 2593 | ((try tree.errors.addOne())).* = Error{ |
| 2593 | 2594 | .ExpectedToken = Error.ExpectedToken{ |
| ... | ... | @@ -2643,11 +2644,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2643 | 2644 | .result = null, |
| 2644 | 2645 | }; |
| 2645 | 2646 | opt_ctx.store(&node.base); |
| 2646 | | const next_token = nextToken(&tok_it, &tree); |
| 2647 | const next_token = nextToken(&tok_it, tree); |
| 2647 | 2648 | const next_token_index = next_token.index; |
| 2648 | 2649 | const next_token_ptr = next_token.ptr; |
| 2649 | 2650 | if (next_token_ptr.id != Token.Id.Arrow) { |
| 2650 | | prevToken(&tok_it, &tree); |
| 2651 | prevToken(&tok_it, tree); |
| 2651 | 2652 | continue; |
| 2652 | 2653 | } |
| 2653 | 2654 | node.result = ast.Node.PromiseType.Result{ |
| ... | ... | @@ -2659,7 +2660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2659 | 2660 | continue; |
| 2660 | 2661 | }, |
| 2661 | 2662 | Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => { |
| 2662 | | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) orelse unreachable); |
| 2663 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, tree)) orelse unreachable); |
| 2663 | 2664 | continue; |
| 2664 | 2665 | }, |
| 2665 | 2666 | Token.Id.LParen => { |
| ... | ... | @@ -2747,7 +2748,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2747 | 2748 | continue; |
| 2748 | 2749 | }, |
| 2749 | 2750 | Token.Id.Keyword_struct, Token.Id.Keyword_union, Token.Id.Keyword_enum => { |
| 2750 | | prevToken(&tok_it, &tree); |
| 2751 | prevToken(&tok_it, tree); |
| 2751 | 2752 | stack.append(State{ |
| 2752 | 2753 | .ContainerKind = ContainerKindCtx{ |
| 2753 | 2754 | .opt_ctx = opt_ctx, |
| ... | ... | @@ -2864,7 +2865,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2864 | 2865 | }, |
| 2865 | 2866 | else => { |
| 2866 | 2867 | if (!try parseBlockExpr(&stack, arena, opt_ctx, token.ptr.*, token.index)) { |
| 2867 | | prevToken(&tok_it, &tree); |
| 2868 | prevToken(&tok_it, tree); |
| 2868 | 2869 | if (opt_ctx != OptionalCtx.Optional) { |
| 2869 | 2870 | ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token.index } }; |
| 2870 | 2871 | return tree; |
| ... | ... | @@ -2876,7 +2877,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2876 | 2877 | }, |
| 2877 | 2878 | |
| 2878 | 2879 | State.ErrorTypeOrSetDecl => |ctx| { |
| 2879 | | if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) { |
| 2880 | if (eatToken(&tok_it, tree, Token.Id.LBrace) == null) { |
| 2880 | 2881 | const node = try arena.create(ast.Node.InfixOp); |
| 2881 | 2882 | node.* = ast.Node.InfixOp{ |
| 2882 | 2883 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| ... | ... | @@ -2914,11 +2915,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2914 | 2915 | continue; |
| 2915 | 2916 | }, |
| 2916 | 2917 | State.StringLiteral => |opt_ctx| { |
| 2917 | | const token = nextToken(&tok_it, &tree); |
| 2918 | const token = nextToken(&tok_it, tree); |
| 2918 | 2919 | const token_index = token.index; |
| 2919 | 2920 | const token_ptr = token.ptr; |
| 2920 | | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) orelse { |
| 2921 | | prevToken(&tok_it, &tree); |
| 2921 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, tree)) orelse { |
| 2922 | prevToken(&tok_it, tree); |
| 2922 | 2923 | if (opt_ctx != OptionalCtx.Optional) { |
| 2923 | 2924 | ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token_index } }; |
| 2924 | 2925 | return tree; |
| ... | ... | @@ -2929,13 +2930,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2929 | 2930 | }, |
| 2930 | 2931 | |
| 2931 | 2932 | State.Identifier => |opt_ctx| { |
| 2932 | | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |ident_token| { |
| 2933 | if (eatToken(&tok_it, tree, Token.Id.Identifier)) |ident_token| { |
| 2933 | 2934 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.Identifier, ident_token); |
| 2934 | 2935 | continue; |
| 2935 | 2936 | } |
| 2936 | 2937 | |
| 2937 | 2938 | if (opt_ctx != OptionalCtx.Optional) { |
| 2938 | | const token = nextToken(&tok_it, &tree); |
| 2939 | const token = nextToken(&tok_it, tree); |
| 2939 | 2940 | const token_index = token.index; |
| 2940 | 2941 | const token_ptr = token.ptr; |
| 2941 | 2942 | ((try tree.errors.addOne())).* = Error{ |
| ... | ... | @@ -2949,8 +2950,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2949 | 2950 | }, |
| 2950 | 2951 | |
| 2951 | 2952 | State.ErrorTag => |node_ptr| { |
| 2952 | | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 2953 | | const ident_token = nextToken(&tok_it, &tree); |
| 2953 | const comments = try eatDocComments(arena, &tok_it, tree); |
| 2954 | const ident_token = nextToken(&tok_it, tree); |
| 2954 | 2955 | const ident_token_index = ident_token.index; |
| 2955 | 2956 | const ident_token_ptr = ident_token.ptr; |
| 2956 | 2957 | if (ident_token_ptr.id != Token.Id.Identifier) { |
| ... | ... | @@ -2974,7 +2975,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2974 | 2975 | }, |
| 2975 | 2976 | |
| 2976 | 2977 | State.ExpectToken => |token_id| { |
| 2977 | | const token = nextToken(&tok_it, &tree); |
| 2978 | const token = nextToken(&tok_it, tree); |
| 2978 | 2979 | const token_index = token.index; |
| 2979 | 2980 | const token_ptr = token.ptr; |
| 2980 | 2981 | if (token_ptr.id != token_id) { |
| ... | ... | @@ -2989,7 +2990,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2989 | 2990 | continue; |
| 2990 | 2991 | }, |
| 2991 | 2992 | State.ExpectTokenSave => |expect_token_save| { |
| 2992 | | const token = nextToken(&tok_it, &tree); |
| 2993 | const token = nextToken(&tok_it, tree); |
| 2993 | 2994 | const token_index = token.index; |
| 2994 | 2995 | const token_ptr = token.ptr; |
| 2995 | 2996 | if (token_ptr.id != expect_token_save.id) { |
| ... | ... | @@ -3005,7 +3006,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 3005 | 3006 | continue; |
| 3006 | 3007 | }, |
| 3007 | 3008 | State.IfToken => |token_id| { |
| 3008 | | if (eatToken(&tok_it, &tree, token_id)) |_| { |
| 3009 | if (eatToken(&tok_it, tree, token_id)) |_| { |
| 3009 | 3010 | continue; |
| 3010 | 3011 | } |
| 3011 | 3012 | |
| ... | ... | @@ -3013,7 +3014,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 3013 | 3014 | continue; |
| 3014 | 3015 | }, |
| 3015 | 3016 | State.IfTokenSave => |if_token_save| { |
| 3016 | | if (eatToken(&tok_it, &tree, if_token_save.id)) |token_index| { |
| 3017 | if (eatToken(&tok_it, tree, if_token_save.id)) |token_index| { |
| 3017 | 3018 | (if_token_save.ptr).* = token_index; |
| 3018 | 3019 | continue; |
| 3019 | 3020 | } |
| ... | ... | @@ -3022,7 +3023,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 3022 | 3023 | continue; |
| 3023 | 3024 | }, |
| 3024 | 3025 | State.OptionalTokenSave => |optional_token_save| { |
| 3025 | | if (eatToken(&tok_it, &tree, optional_token_save.id)) |token_index| { |
| 3026 | if (eatToken(&tok_it, tree, optional_token_save.id)) |token_index| { |
| 3026 | 3027 | (optional_token_save.ptr).* = token_index; |
| 3027 | 3028 | continue; |
| 3028 | 3029 | } |