| ... | @@ -17,14 +17,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -17,14 +17,15 @@ 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 arena.create(ast.Node.Root{ | 20 | const root_node = try arena.create(ast.Node.Root); |
| | 21 | root_node.* = ast.Node.Root{ |
| 21 | .base = ast.Node{ .id = ast.Node.Id.Root }, | 22 | .base = ast.Node{ .id = ast.Node.Id.Root }, |
| 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 | .shebang = null, | 25 | .shebang = null, |
| 25 | // initialized when we get the eof token | 26 | // initialized when we get the eof token |
| 26 | .eof_token = undefined, | 27 | .eof_token = undefined, |
| 27 | }); | 28 | }; |
| 28 | | 29 | |
| 29 | var tree = ast.Tree{ | 30 | var tree = ast.Tree{ |
| 30 | .source = source, | 31 | .source = source, |
| ... | @@ -75,20 +76,22 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -75,20 +76,22 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 75 | Token.Id.Keyword_test => { | 76 | Token.Id.Keyword_test => { |
| 76 | stack.append(State.TopLevel) catch unreachable; | 77 | stack.append(State.TopLevel) catch unreachable; |
| 77 | | 78 | |
| 78 | const block = try arena.create(ast.Node.Block{ | 79 | const block = try arena.create(ast.Node.Block); |
| | 80 | block.* = ast.Node.Block{ |
| 79 | .base = ast.Node{ .id = ast.Node.Id.Block }, | 81 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 80 | .label = null, | 82 | .label = null, |
| 81 | .lbrace = undefined, | 83 | .lbrace = undefined, |
| 82 | .statements = ast.Node.Block.StatementList.init(arena), | 84 | .statements = ast.Node.Block.StatementList.init(arena), |
| 83 | .rbrace = undefined, | 85 | .rbrace = undefined, |
| 84 | }); | 86 | }; |
| 85 | const test_node = try arena.create(ast.Node.TestDecl{ | 87 | const test_node = try arena.create(ast.Node.TestDecl); |
| | 88 | test_node.* = ast.Node.TestDecl{ |
| 86 | .base = ast.Node{ .id = ast.Node.Id.TestDecl }, | 89 | .base = ast.Node{ .id = ast.Node.Id.TestDecl }, |
| 87 | .doc_comments = comments, | 90 | .doc_comments = comments, |
| 88 | .test_token = token_index, | 91 | .test_token = token_index, |
| 89 | .name = undefined, | 92 | .name = undefined, |
| 90 | .body_node = &block.base, | 93 | .body_node = &block.base, |
| 91 | }); | 94 | }; |
| 92 | try root_node.decls.push(&test_node.base); | 95 | try root_node.decls.push(&test_node.base); |
| 93 | try stack.append(State{ .Block = block }); | 96 | try stack.append(State{ .Block = block }); |
| 94 | try stack.append(State{ | 97 | try stack.append(State{ |
| ... | @@ -119,19 +122,21 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -119,19 +122,21 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 119 | continue; | 122 | continue; |
| 120 | }, | 123 | }, |
| 121 | Token.Id.Keyword_comptime => { | 124 | Token.Id.Keyword_comptime => { |
| 122 | const block = try arena.create(ast.Node.Block{ | 125 | const block = try arena.create(ast.Node.Block); |
| | 126 | block.* = ast.Node.Block{ |
| 123 | .base = ast.Node{ .id = ast.Node.Id.Block }, | 127 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 124 | .label = null, | 128 | .label = null, |
| 125 | .lbrace = undefined, | 129 | .lbrace = undefined, |
| 126 | .statements = ast.Node.Block.StatementList.init(arena), | 130 | .statements = ast.Node.Block.StatementList.init(arena), |
| 127 | .rbrace = undefined, | 131 | .rbrace = undefined, |
| 128 | }); | 132 | }; |
| 129 | const node = try arena.create(ast.Node.Comptime{ | 133 | const node = try arena.create(ast.Node.Comptime); |
| | 134 | node.* = ast.Node.Comptime{ |
| 130 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, | 135 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 131 | .comptime_token = token_index, | 136 | .comptime_token = token_index, |
| 132 | .expr = &block.base, | 137 | .expr = &block.base, |
| 133 | .doc_comments = comments, | 138 | .doc_comments = comments, |
| 134 | }); | 139 | }; |
| 135 | try root_node.decls.push(&node.base); | 140 | try root_node.decls.push(&node.base); |
| 136 | | 141 | |
| 137 | stack.append(State.TopLevel) catch unreachable; | 142 | stack.append(State.TopLevel) catch unreachable; |
| ... | @@ -235,14 +240,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -235,14 +240,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 235 | return tree; | 240 | return tree; |
| 236 | } | 241 | } |
| 237 | | 242 | |
| 238 | const node = try arena.create(ast.Node.Use{ | 243 | const node = try arena.create(ast.Node.Use); |
| | 244 | node.* = ast.Node.Use{ |
| 239 | .base = ast.Node{ .id = ast.Node.Id.Use }, | 245 | .base = ast.Node{ .id = ast.Node.Id.Use }, |
| 240 | .use_token = token_index, | 246 | .use_token = token_index, |
| 241 | .visib_token = ctx.visib_token, | 247 | .visib_token = ctx.visib_token, |
| 242 | .expr = undefined, | 248 | .expr = undefined, |
| 243 | .semicolon_token = undefined, | 249 | .semicolon_token = undefined, |
| 244 | .doc_comments = ctx.comments, | 250 | .doc_comments = ctx.comments, |
| 245 | }); | 251 | }; |
| 246 | try ctx.decls.push(&node.base); | 252 | try ctx.decls.push(&node.base); |
| 247 | | 253 | |
| 248 | stack.append(State{ | 254 | stack.append(State{ |
| ... | @@ -276,7 +282,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -276,7 +282,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 276 | continue; | 282 | continue; |
| 277 | }, | 283 | }, |
| 278 | Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => { | 284 | Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => { |
| 279 | const fn_proto = try arena.create(ast.Node.FnProto{ | 285 | const fn_proto = try arena.create(ast.Node.FnProto); |
| | 286 | fn_proto.* = ast.Node.FnProto{ |
| 280 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, | 287 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 281 | .doc_comments = ctx.comments, | 288 | .doc_comments = ctx.comments, |
| 282 | .visib_token = ctx.visib_token, | 289 | .visib_token = ctx.visib_token, |
| ... | @@ -292,7 +299,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -292,7 +299,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 292 | .lib_name = ctx.lib_name, | 299 | .lib_name = ctx.lib_name, |
| 293 | .align_expr = null, | 300 | .align_expr = null, |
| 294 | .section_expr = null, | 301 | .section_expr = null, |
| 295 | }); | 302 | }; |
| 296 | try ctx.decls.push(&fn_proto.base); | 303 | try ctx.decls.push(&fn_proto.base); |
| 297 | stack.append(State{ .FnDef = fn_proto }) catch unreachable; | 304 | stack.append(State{ .FnDef = fn_proto }) catch unreachable; |
| 298 | try stack.append(State{ .FnProto = fn_proto }); | 305 | try stack.append(State{ .FnProto = fn_proto }); |
| ... | @@ -309,12 +316,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -309,12 +316,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 309 | continue; | 316 | continue; |
| 310 | }, | 317 | }, |
| 311 | Token.Id.Keyword_async => { | 318 | Token.Id.Keyword_async => { |
| 312 | const async_node = try arena.create(ast.Node.AsyncAttribute{ | 319 | const async_node = try arena.create(ast.Node.AsyncAttribute); |
| | 320 | async_node.* = ast.Node.AsyncAttribute{ |
| 313 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, | 321 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 314 | .async_token = token_index, | 322 | .async_token = token_index, |
| 315 | .allocator_type = null, | 323 | .allocator_type = null, |
| 316 | .rangle_bracket = null, | 324 | .rangle_bracket = null, |
| 317 | }); | 325 | }; |
| 318 | fn_proto.async_attr = async_node; | 326 | fn_proto.async_attr = async_node; |
| 319 | | 327 | |
| 320 | try stack.append(State{ | 328 | try stack.append(State{ |
| ... | @@ -341,13 +349,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -341,13 +349,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 341 | }, | 349 | }, |
| 342 | State.TopLevelExternOrField => |ctx| { | 350 | State.TopLevelExternOrField => |ctx| { |
| 343 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| { | 351 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| { |
| 344 | const node = try arena.create(ast.Node.StructField{ | 352 | const node = try arena.create(ast.Node.StructField); |
| | 353 | node.* = ast.Node.StructField{ |
| 345 | .base = ast.Node{ .id = ast.Node.Id.StructField }, | 354 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 346 | .doc_comments = ctx.comments, | 355 | .doc_comments = ctx.comments, |
| 347 | .visib_token = ctx.visib_token, | 356 | .visib_token = ctx.visib_token, |
| 348 | .name_token = identifier, | 357 | .name_token = identifier, |
| 349 | .type_expr = undefined, | 358 | .type_expr = undefined, |
| 350 | }); | 359 | }; |
| 351 | const node_ptr = try ctx.container_decl.fields_and_decls.addOne(); | 360 | const node_ptr = try ctx.container_decl.fields_and_decls.addOne(); |
| 352 | node_ptr.* = &node.base; | 361 | node_ptr.* = &node.base; |
| 353 | | 362 | |
| ... | @@ -391,7 +400,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -391,7 +400,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 391 | const token = nextToken(&tok_it, &tree); | 400 | const token = nextToken(&tok_it, &tree); |
| 392 | const token_index = token.index; | 401 | const token_index = token.index; |
| 393 | const token_ptr = token.ptr; | 402 | const token_ptr = token.ptr; |
| 394 | const node = try arena.create(ast.Node.ContainerDecl{ | 403 | const node = try arena.create(ast.Node.ContainerDecl); |
| | 404 | node.* = ast.Node.ContainerDecl{ |
| 395 | .base = ast.Node{ .id = ast.Node.Id.ContainerDecl }, | 405 | .base = ast.Node{ .id = ast.Node.Id.ContainerDecl }, |
| 396 | .layout_token = ctx.layout_token, | 406 | .layout_token = ctx.layout_token, |
| 397 | .kind_token = switch (token_ptr.id) { | 407 | .kind_token = switch (token_ptr.id) { |
| ... | @@ -405,7 +415,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -405,7 +415,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 405 | .fields_and_decls = ast.Node.ContainerDecl.DeclList.init(arena), | 415 | .fields_and_decls = ast.Node.ContainerDecl.DeclList.init(arena), |
| 406 | .lbrace_token = undefined, | 416 | .lbrace_token = undefined, |
| 407 | .rbrace_token = undefined, | 417 | .rbrace_token = undefined, |
| 408 | }); | 418 | }; |
| 409 | ctx.opt_ctx.store(&node.base); | 419 | ctx.opt_ctx.store(&node.base); |
| 410 | | 420 | |
| 411 | stack.append(State{ .ContainerDecl = node }) catch unreachable; | 421 | stack.append(State{ .ContainerDecl = node }) catch unreachable; |
| ... | @@ -464,13 +474,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -464,13 +474,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 464 | Token.Id.Identifier => { | 474 | Token.Id.Identifier => { |
| 465 | switch (tree.tokens.at(container_decl.kind_token).id) { | 475 | switch (tree.tokens.at(container_decl.kind_token).id) { |
| 466 | Token.Id.Keyword_struct => { | 476 | Token.Id.Keyword_struct => { |
| 467 | const node = try arena.create(ast.Node.StructField{ | 477 | const node = try arena.create(ast.Node.StructField); |
| | 478 | node.* = ast.Node.StructField{ |
| 468 | .base = ast.Node{ .id = ast.Node.Id.StructField }, | 479 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 469 | .doc_comments = comments, | 480 | .doc_comments = comments, |
| 470 | .visib_token = null, | 481 | .visib_token = null, |
| 471 | .name_token = token_index, | 482 | .name_token = token_index, |
| 472 | .type_expr = undefined, | 483 | .type_expr = undefined, |
| 473 | }); | 484 | }; |
| 474 | const node_ptr = try container_decl.fields_and_decls.addOne(); | 485 | const node_ptr = try container_decl.fields_and_decls.addOne(); |
| 475 | node_ptr.* = &node.base; | 486 | node_ptr.* = &node.base; |
| 476 | | 487 | |
| ... | @@ -485,13 +496,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -485,13 +496,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 485 | continue; | 496 | continue; |
| 486 | }, | 497 | }, |
| 487 | Token.Id.Keyword_union => { | 498 | Token.Id.Keyword_union => { |
| 488 | const node = try arena.create(ast.Node.UnionTag{ | 499 | const node = try arena.create(ast.Node.UnionTag); |
| | 500 | node.* = ast.Node.UnionTag{ |
| 489 | .base = ast.Node{ .id = ast.Node.Id.UnionTag }, | 501 | .base = ast.Node{ .id = ast.Node.Id.UnionTag }, |
| 490 | .name_token = token_index, | 502 | .name_token = token_index, |
| 491 | .type_expr = null, | 503 | .type_expr = null, |
| 492 | .value_expr = null, | 504 | .value_expr = null, |
| 493 | .doc_comments = comments, | 505 | .doc_comments = comments, |
| 494 | }); | 506 | }; |
| 495 | try container_decl.fields_and_decls.push(&node.base); | 507 | try container_decl.fields_and_decls.push(&node.base); |
| 496 | | 508 | |
| 497 | try stack.append(State{ | 509 | try stack.append(State{ |
| ... | @@ -506,12 +518,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -506,12 +518,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 506 | continue; | 518 | continue; |
| 507 | }, | 519 | }, |
| 508 | Token.Id.Keyword_enum => { | 520 | Token.Id.Keyword_enum => { |
| 509 | const node = try arena.create(ast.Node.EnumTag{ | 521 | const node = try arena.create(ast.Node.EnumTag); |
| | 522 | node.* = ast.Node.EnumTag{ |
| 510 | .base = ast.Node{ .id = ast.Node.Id.EnumTag }, | 523 | .base = ast.Node{ .id = ast.Node.Id.EnumTag }, |
| 511 | .name_token = token_index, | 524 | .name_token = token_index, |
| 512 | .value = null, | 525 | .value = null, |
| 513 | .doc_comments = comments, | 526 | .doc_comments = comments, |
| 514 | }); | 527 | }; |
| 515 | try container_decl.fields_and_decls.push(&node.base); | 528 | try container_decl.fields_and_decls.push(&node.base); |
| 516 | | 529 | |
| 517 | try stack.append(State{ | 530 | try stack.append(State{ |
| ... | @@ -593,7 +606,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -593,7 +606,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 593 | }, | 606 | }, |
| 594 | | 607 | |
| 595 | State.VarDecl => |ctx| { | 608 | State.VarDecl => |ctx| { |
| 596 | const var_decl = try arena.create(ast.Node.VarDecl{ | 609 | const var_decl = try arena.create(ast.Node.VarDecl); |
| | 610 | var_decl.* = ast.Node.VarDecl{ |
| 597 | .base = ast.Node{ .id = ast.Node.Id.VarDecl }, | 611 | .base = ast.Node{ .id = ast.Node.Id.VarDecl }, |
| 598 | .doc_comments = ctx.comments, | 612 | .doc_comments = ctx.comments, |
| 599 | .visib_token = ctx.visib_token, | 613 | .visib_token = ctx.visib_token, |
| ... | @@ -609,7 +623,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -609,7 +623,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 609 | .name_token = undefined, | 623 | .name_token = undefined, |
| 610 | .eq_token = undefined, | 624 | .eq_token = undefined, |
| 611 | .semicolon_token = undefined, | 625 | .semicolon_token = undefined, |
| 612 | }); | 626 | }; |
| 613 | try ctx.list.push(&var_decl.base); | 627 | try ctx.list.push(&var_decl.base); |
| 614 | | 628 | |
| 615 | try stack.append(State{ .VarDeclAlign = var_decl }); | 629 | try stack.append(State{ .VarDeclAlign = var_decl }); |
| ... | @@ -708,13 +722,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -708,13 +722,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 708 | const token_ptr = token.ptr; | 722 | const token_ptr = token.ptr; |
| 709 | switch (token_ptr.id) { | 723 | switch (token_ptr.id) { |
| 710 | Token.Id.LBrace => { | 724 | Token.Id.LBrace => { |
| 711 | const block = try arena.create(ast.Node.Block{ | 725 | const block = try arena.create(ast.Node.Block); |
| | 726 | block.* = ast.Node.Block{ |
| 712 | .base = ast.Node{ .id = ast.Node.Id.Block }, | 727 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 713 | .label = null, | 728 | .label = null, |
| 714 | .lbrace = token_index, | 729 | .lbrace = token_index, |
| 715 | .statements = ast.Node.Block.StatementList.init(arena), | 730 | .statements = ast.Node.Block.StatementList.init(arena), |
| 716 | .rbrace = undefined, | 731 | .rbrace = undefined, |
| 717 | }); | 732 | }; |
| 718 | fn_proto.body_node = &block.base; | 733 | fn_proto.body_node = &block.base; |
| 719 | stack.append(State{ .Block = block }) catch unreachable; | 734 | stack.append(State{ .Block = block }) catch unreachable; |
| 720 | continue; | 735 | continue; |
| ... | @@ -770,10 +785,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -770,10 +785,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 770 | // TODO: this is a special case. Remove this when #760 is fixed | 785 | // TODO: this is a special case. Remove this when #760 is fixed |
| 771 | if (token_ptr.id == Token.Id.Keyword_anyerror) { | 786 | if (token_ptr.id == Token.Id.Keyword_anyerror) { |
| 772 | if (tok_it.peek().?.id == Token.Id.LBrace) { | 787 | if (tok_it.peek().?.id == Token.Id.LBrace) { |
| 773 | const error_type_node = try arena.create(ast.Node.ErrorType{ | 788 | const error_type_node = try arena.create(ast.Node.ErrorType); |
| | 789 | error_type_node.* = ast.Node.ErrorType{ |
| 774 | .base = ast.Node{ .id = ast.Node.Id.ErrorType }, | 790 | .base = ast.Node{ .id = ast.Node.Id.ErrorType }, |
| 775 | .token = token_index, | 791 | .token = token_index, |
| 776 | }); | 792 | }; |
| 777 | fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = &error_type_node.base }; | 793 | fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = &error_type_node.base }; |
| 778 | continue; | 794 | continue; |
| 779 | } | 795 | } |
| ... | @@ -791,14 +807,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -791,14 +807,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 791 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { | 807 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { |
| 792 | continue; | 808 | continue; |
| 793 | } | 809 | } |
| 794 | const param_decl = try arena.create(ast.Node.ParamDecl{ | 810 | const param_decl = try arena.create(ast.Node.ParamDecl); |
| | 811 | param_decl.* = ast.Node.ParamDecl{ |
| 795 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, | 812 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, |
| 796 | .comptime_token = null, | 813 | .comptime_token = null, |
| 797 | .noalias_token = null, | 814 | .noalias_token = null, |
| 798 | .name_token = null, | 815 | .name_token = null, |
| 799 | .type_node = undefined, | 816 | .type_node = undefined, |
| 800 | .var_args_token = null, | 817 | .var_args_token = null, |
| 801 | }); | 818 | }; |
| 802 | try fn_proto.params.push(&param_decl.base); | 819 | try fn_proto.params.push(&param_decl.base); |
| 803 | | 820 | |
| 804 | stack.append(State{ | 821 | stack.append(State{ |
| ... | @@ -877,13 +894,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -877,13 +894,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 877 | const token_ptr = token.ptr; | 894 | const token_ptr = token.ptr; |
| 878 | switch (token_ptr.id) { | 895 | switch (token_ptr.id) { |
| 879 | Token.Id.LBrace => { | 896 | Token.Id.LBrace => { |
| 880 | const block = try arena.create(ast.Node.Block{ | 897 | const block = try arena.create(ast.Node.Block); |
| | 898 | block.* = ast.Node.Block{ |
| 881 | .base = ast.Node{ .id = ast.Node.Id.Block }, | 899 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 882 | .label = ctx.label, | 900 | .label = ctx.label, |
| 883 | .lbrace = token_index, | 901 | .lbrace = token_index, |
| 884 | .statements = ast.Node.Block.StatementList.init(arena), | 902 | .statements = ast.Node.Block.StatementList.init(arena), |
| 885 | .rbrace = undefined, | 903 | .rbrace = undefined, |
| 886 | }); | 904 | }; |
| 887 | ctx.opt_ctx.store(&block.base); | 905 | ctx.opt_ctx.store(&block.base); |
| 888 | stack.append(State{ .Block = block }) catch unreachable; | 906 | stack.append(State{ .Block = block }) catch unreachable; |
| 889 | continue; | 907 | continue; |
| ... | @@ -970,7 +988,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -970,7 +988,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 970 | } | 988 | } |
| 971 | }, | 989 | }, |
| 972 | State.While => |ctx| { | 990 | State.While => |ctx| { |
| 973 | const node = try arena.create(ast.Node.While{ | 991 | const node = try arena.create(ast.Node.While); |
| | 992 | node.* = ast.Node.While{ |
| 974 | .base = ast.Node{ .id = ast.Node.Id.While }, | 993 | .base = ast.Node{ .id = ast.Node.Id.While }, |
| 975 | .label = ctx.label, | 994 | .label = ctx.label, |
| 976 | .inline_token = ctx.inline_token, | 995 | .inline_token = ctx.inline_token, |
| ... | @@ -980,7 +999,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -980,7 +999,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 980 | .continue_expr = null, | 999 | .continue_expr = null, |
| 981 | .body = undefined, | 1000 | .body = undefined, |
| 982 | .@"else" = null, | 1001 | .@"else" = null, |
| 983 | }); | 1002 | }; |
| 984 | ctx.opt_ctx.store(&node.base); | 1003 | ctx.opt_ctx.store(&node.base); |
| 985 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; | 1004 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| 986 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); | 1005 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); |
| ... | @@ -999,7 +1018,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -999,7 +1018,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 999 | continue; | 1018 | continue; |
| 1000 | }, | 1019 | }, |
| 1001 | State.For => |ctx| { | 1020 | State.For => |ctx| { |
| 1002 | const node = try arena.create(ast.Node.For{ | 1021 | const node = try arena.create(ast.Node.For); |
| | 1022 | node.* = ast.Node.For{ |
| 1003 | .base = ast.Node{ .id = ast.Node.Id.For }, | 1023 | .base = ast.Node{ .id = ast.Node.Id.For }, |
| 1004 | .label = ctx.label, | 1024 | .label = ctx.label, |
| 1005 | .inline_token = ctx.inline_token, | 1025 | .inline_token = ctx.inline_token, |
| ... | @@ -1008,7 +1028,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1008,7 +1028,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1008 | .payload = null, | 1028 | .payload = null, |
| 1009 | .body = undefined, | 1029 | .body = undefined, |
| 1010 | .@"else" = null, | 1030 | .@"else" = null, |
| 1011 | }); | 1031 | }; |
| 1012 | ctx.opt_ctx.store(&node.base); | 1032 | ctx.opt_ctx.store(&node.base); |
| 1013 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; | 1033 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| 1014 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); | 1034 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); |
| ... | @@ -1020,12 +1040,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1020,12 +1040,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1020 | }, | 1040 | }, |
| 1021 | State.Else => |dest| { | 1041 | State.Else => |dest| { |
| 1022 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { | 1042 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 1023 | const node = try arena.create(ast.Node.Else{ | 1043 | const node = try arena.create(ast.Node.Else); |
| | 1044 | node.* = ast.Node.Else{ |
| 1024 | .base = ast.Node{ .id = ast.Node.Id.Else }, | 1045 | .base = ast.Node{ .id = ast.Node.Id.Else }, |
| 1025 | .else_token = else_token, | 1046 | .else_token = else_token, |
| 1026 | .payload = null, | 1047 | .payload = null, |
| 1027 | .body = undefined, | 1048 | .body = undefined, |
| 1028 | }); | 1049 | }; |
| 1029 | dest.* = node; | 1050 | dest.* = node; |
| 1030 | | 1051 | |
| 1031 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }) catch unreachable; | 1052 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }) catch unreachable; |
| ... | @@ -1083,11 +1104,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1083,11 +1104,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1083 | continue; | 1104 | continue; |
| 1084 | }, | 1105 | }, |
| 1085 | Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => { | 1106 | Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => { |
| 1086 | const node = try arena.create(ast.Node.Defer{ | 1107 | const node = try arena.create(ast.Node.Defer); |
| | 1108 | node.* = ast.Node.Defer{ |
| 1087 | .base = ast.Node{ .id = ast.Node.Id.Defer }, | 1109 | .base = ast.Node{ .id = ast.Node.Id.Defer }, |
| 1088 | .defer_token = token_index, | 1110 | .defer_token = token_index, |
| 1089 | .expr = undefined, | 1111 | .expr = undefined, |
| 1090 | }); | 1112 | }; |
| 1091 | const node_ptr = try block.statements.addOne(); | 1113 | const node_ptr = try block.statements.addOne(); |
| 1092 | node_ptr.* = &node.base; | 1114 | node_ptr.* = &node.base; |
| 1093 | | 1115 | |
| ... | @@ -1096,13 +1118,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1096,13 +1118,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1096 | continue; | 1118 | continue; |
| 1097 | }, | 1119 | }, |
| 1098 | Token.Id.LBrace => { | 1120 | Token.Id.LBrace => { |
| 1099 | const inner_block = try arena.create(ast.Node.Block{ | 1121 | const inner_block = try arena.create(ast.Node.Block); |
| | 1122 | inner_block.* = ast.Node.Block{ |
| 1100 | .base = ast.Node{ .id = ast.Node.Id.Block }, | 1123 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 1101 | .label = null, | 1124 | .label = null, |
| 1102 | .lbrace = token_index, | 1125 | .lbrace = token_index, |
| 1103 | .statements = ast.Node.Block.StatementList.init(arena), | 1126 | .statements = ast.Node.Block.StatementList.init(arena), |
| 1104 | .rbrace = undefined, | 1127 | .rbrace = undefined, |
| 1105 | }); | 1128 | }; |
| 1106 | try block.statements.push(&inner_block.base); | 1129 | try block.statements.push(&inner_block.base); |
| 1107 | | 1130 | |
| 1108 | stack.append(State{ .Block = inner_block }) catch unreachable; | 1131 | stack.append(State{ .Block = inner_block }) catch unreachable; |
| ... | @@ -1164,14 +1187,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1164,14 +1187,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1164 | continue; | 1187 | continue; |
| 1165 | } | 1188 | } |
| 1166 | | 1189 | |
| 1167 | const node = try arena.create(ast.Node.AsmOutput{ | 1190 | const node = try arena.create(ast.Node.AsmOutput); |
| | 1191 | node.* = ast.Node.AsmOutput{ |
| 1168 | .base = ast.Node{ .id = ast.Node.Id.AsmOutput }, | 1192 | .base = ast.Node{ .id = ast.Node.Id.AsmOutput }, |
| 1169 | .lbracket = lbracket_index, | 1193 | .lbracket = lbracket_index, |
| 1170 | .symbolic_name = undefined, | 1194 | .symbolic_name = undefined, |
| 1171 | .constraint = undefined, | 1195 | .constraint = undefined, |
| 1172 | .kind = undefined, | 1196 | .kind = undefined, |
| 1173 | .rparen = undefined, | 1197 | .rparen = undefined, |
| 1174 | }); | 1198 | }; |
| 1175 | try items.push(node); | 1199 | try items.push(node); |
| 1176 | | 1200 | |
| 1177 | stack.append(State{ .AsmOutputItems = items }) catch unreachable; | 1201 | stack.append(State{ .AsmOutputItems = items }) catch unreachable; |
| ... | @@ -1218,14 +1242,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1218,14 +1242,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1218 | continue; | 1242 | continue; |
| 1219 | } | 1243 | } |
| 1220 | | 1244 | |
| 1221 | const node = try arena.create(ast.Node.AsmInput{ | 1245 | const node = try arena.create(ast.Node.AsmInput); |
| | 1246 | node.* = ast.Node.AsmInput{ |
| 1222 | .base = ast.Node{ .id = ast.Node.Id.AsmInput }, | 1247 | .base = ast.Node{ .id = ast.Node.Id.AsmInput }, |
| 1223 | .lbracket = lbracket_index, | 1248 | .lbracket = lbracket_index, |
| 1224 | .symbolic_name = undefined, | 1249 | .symbolic_name = undefined, |
| 1225 | .constraint = undefined, | 1250 | .constraint = undefined, |
| 1226 | .expr = undefined, | 1251 | .expr = undefined, |
| 1227 | .rparen = undefined, | 1252 | .rparen = undefined, |
| 1228 | }); | 1253 | }; |
| 1229 | try items.push(node); | 1254 | try items.push(node); |
| 1230 | | 1255 | |
| 1231 | stack.append(State{ .AsmInputItems = items }) catch unreachable; | 1256 | stack.append(State{ .AsmInputItems = items }) catch unreachable; |
| ... | @@ -1283,12 +1308,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1283,12 +1308,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1283 | continue; | 1308 | continue; |
| 1284 | } | 1309 | } |
| 1285 | | 1310 | |
| 1286 | const node = try arena.create(ast.Node.FieldInitializer{ | 1311 | const node = try arena.create(ast.Node.FieldInitializer); |
| | 1312 | node.* = ast.Node.FieldInitializer{ |
| 1287 | .base = ast.Node{ .id = ast.Node.Id.FieldInitializer }, | 1313 | .base = ast.Node{ .id = ast.Node.Id.FieldInitializer }, |
| 1288 | .period_token = undefined, | 1314 | .period_token = undefined, |
| 1289 | .name_token = undefined, | 1315 | .name_token = undefined, |
| 1290 | .expr = undefined, | 1316 | .expr = undefined, |
| 1291 | }); | 1317 | }; |
| 1292 | try list_state.list.push(&node.base); | 1318 | try list_state.list.push(&node.base); |
| 1293 | | 1319 | |
| 1294 | stack.append(State{ .FieldInitListCommaOrEnd = list_state }) catch unreachable; | 1320 | stack.append(State{ .FieldInitListCommaOrEnd = list_state }) catch unreachable; |
| ... | @@ -1390,13 +1416,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1390,13 +1416,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1390 | } | 1416 | } |
| 1391 | | 1417 | |
| 1392 | const comments = try eatDocComments(arena, &tok_it, &tree); | 1418 | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 1393 | const node = try arena.create(ast.Node.SwitchCase{ | 1419 | const node = try arena.create(ast.Node.SwitchCase); |
| | 1420 | node.* = ast.Node.SwitchCase{ |
| 1394 | .base = ast.Node{ .id = ast.Node.Id.SwitchCase }, | 1421 | .base = ast.Node{ .id = ast.Node.Id.SwitchCase }, |
| 1395 | .items = ast.Node.SwitchCase.ItemList.init(arena), | 1422 | .items = ast.Node.SwitchCase.ItemList.init(arena), |
| 1396 | .payload = null, | 1423 | .payload = null, |
| 1397 | .expr = undefined, | 1424 | .expr = undefined, |
| 1398 | .arrow_token = undefined, | 1425 | .arrow_token = undefined, |
| 1399 | }); | 1426 | }; |
| 1400 | try list_state.list.push(&node.base); | 1427 | try list_state.list.push(&node.base); |
| 1401 | try stack.append(State{ .SwitchCaseCommaOrEnd = list_state }); | 1428 | try stack.append(State{ .SwitchCaseCommaOrEnd = list_state }); |
| 1402 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } }); | 1429 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } }); |
| ... | @@ -1427,10 +1454,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1427,10 +1454,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1427 | const token_index = token.index; | 1454 | const token_index = token.index; |
| 1428 | const token_ptr = token.ptr; | 1455 | const token_ptr = token.ptr; |
| 1429 | if (token_ptr.id == Token.Id.Keyword_else) { | 1456 | if (token_ptr.id == Token.Id.Keyword_else) { |
| 1430 | const else_node = try arena.create(ast.Node.SwitchElse{ | 1457 | const else_node = try arena.create(ast.Node.SwitchElse); |
| | 1458 | else_node.* = ast.Node.SwitchElse{ |
| 1431 | .base = ast.Node{ .id = ast.Node.Id.SwitchElse }, | 1459 | .base = ast.Node{ .id = ast.Node.Id.SwitchElse }, |
| 1432 | .token = token_index, | 1460 | .token = token_index, |
| 1433 | }); | 1461 | }; |
| 1434 | try switch_case.items.push(&else_node.base); | 1462 | try switch_case.items.push(&else_node.base); |
| 1435 | | 1463 | |
| 1436 | try stack.append(State{ | 1464 | try stack.append(State{ |
| ... | @@ -1537,7 +1565,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1537,7 +1565,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1537 | | 1565 | |
| 1538 | State.ExternType => |ctx| { | 1566 | State.ExternType => |ctx| { |
| 1539 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| { | 1567 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| { |
| 1540 | const fn_proto = try arena.create(ast.Node.FnProto{ | 1568 | const fn_proto = try arena.create(ast.Node.FnProto); |
| | 1569 | fn_proto.* = ast.Node.FnProto{ |
| 1541 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, | 1570 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 1542 | .doc_comments = ctx.comments, | 1571 | .doc_comments = ctx.comments, |
| 1543 | .visib_token = null, | 1572 | .visib_token = null, |
| ... | @@ -1553,7 +1582,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1553,7 +1582,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1553 | .lib_name = null, | 1582 | .lib_name = null, |
| 1554 | .align_expr = null, | 1583 | .align_expr = null, |
| 1555 | .section_expr = null, | 1584 | .section_expr = null, |
| 1556 | }); | 1585 | }; |
| 1557 | ctx.opt_ctx.store(&fn_proto.base); | 1586 | ctx.opt_ctx.store(&fn_proto.base); |
| 1558 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; | 1587 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 1559 | continue; | 1588 | continue; |
| ... | @@ -1711,12 +1740,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1711,12 +1740,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1711 | continue; | 1740 | continue; |
| 1712 | } | 1741 | } |
| 1713 | | 1742 | |
| 1714 | const node = try arena.create(ast.Node.Payload{ | 1743 | const node = try arena.create(ast.Node.Payload); |
| | 1744 | node.* = ast.Node.Payload{ |
| 1715 | .base = ast.Node{ .id = ast.Node.Id.Payload }, | 1745 | .base = ast.Node{ .id = ast.Node.Id.Payload }, |
| 1716 | .lpipe = token_index, | 1746 | .lpipe = token_index, |
| 1717 | .error_symbol = undefined, | 1747 | .error_symbol = undefined, |
| 1718 | .rpipe = undefined, | 1748 | .rpipe = undefined, |
| 1719 | }); | 1749 | }; |
| 1720 | opt_ctx.store(&node.base); | 1750 | opt_ctx.store(&node.base); |
| 1721 | | 1751 | |
| 1722 | stack.append(State{ | 1752 | stack.append(State{ |
| ... | @@ -1747,13 +1777,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1747,13 +1777,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1747 | continue; | 1777 | continue; |
| 1748 | } | 1778 | } |
| 1749 | | 1779 | |
| 1750 | const node = try arena.create(ast.Node.PointerPayload{ | 1780 | const node = try arena.create(ast.Node.PointerPayload); |
| | 1781 | node.* = ast.Node.PointerPayload{ |
| 1751 | .base = ast.Node{ .id = ast.Node.Id.PointerPayload }, | 1782 | .base = ast.Node{ .id = ast.Node.Id.PointerPayload }, |
| 1752 | .lpipe = token_index, | 1783 | .lpipe = token_index, |
| 1753 | .ptr_token = null, | 1784 | .ptr_token = null, |
| 1754 | .value_symbol = undefined, | 1785 | .value_symbol = undefined, |
| 1755 | .rpipe = undefined, | 1786 | .rpipe = undefined, |
| 1756 | }); | 1787 | }; |
| 1757 | opt_ctx.store(&node.base); | 1788 | opt_ctx.store(&node.base); |
| 1758 | | 1789 | |
| 1759 | try stack.append(State{ | 1790 | try stack.append(State{ |
| ... | @@ -1790,14 +1821,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1790,14 +1821,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1790 | continue; | 1821 | continue; |
| 1791 | } | 1822 | } |
| 1792 | | 1823 | |
| 1793 | const node = try arena.create(ast.Node.PointerIndexPayload{ | 1824 | const node = try arena.create(ast.Node.PointerIndexPayload); |
| | 1825 | node.* = ast.Node.PointerIndexPayload{ |
| 1794 | .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload }, | 1826 | .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload }, |
| 1795 | .lpipe = token_index, | 1827 | .lpipe = token_index, |
| 1796 | .ptr_token = null, | 1828 | .ptr_token = null, |
| 1797 | .value_symbol = undefined, | 1829 | .value_symbol = undefined, |
| 1798 | .index_symbol = null, | 1830 | .index_symbol = null, |
| 1799 | .rpipe = undefined, | 1831 | .rpipe = undefined, |
| 1800 | }); | 1832 | }; |
| 1801 | opt_ctx.store(&node.base); | 1833 | opt_ctx.store(&node.base); |
| 1802 | | 1834 | |
| 1803 | stack.append(State{ | 1835 | stack.append(State{ |
| ... | @@ -1824,12 +1856,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1824,12 +1856,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1824 | const token_ptr = token.ptr; | 1856 | const token_ptr = token.ptr; |
| 1825 | switch (token_ptr.id) { | 1857 | switch (token_ptr.id) { |
| 1826 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { | 1858 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { |
| 1827 | const node = try arena.create(ast.Node.ControlFlowExpression{ | 1859 | const node = try arena.create(ast.Node.ControlFlowExpression); |
| | 1860 | node.* = ast.Node.ControlFlowExpression{ |
| 1828 | .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression }, | 1861 | .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression }, |
| 1829 | .ltoken = token_index, | 1862 | .ltoken = token_index, |
| 1830 | .kind = undefined, | 1863 | .kind = undefined, |
| 1831 | .rhs = null, | 1864 | .rhs = null, |
| 1832 | }); | 1865 | }; |
| 1833 | opt_ctx.store(&node.base); | 1866 | opt_ctx.store(&node.base); |
| 1834 | | 1867 | |
| 1835 | stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.rhs } }) catch unreachable; | 1868 | stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.rhs } }) catch unreachable; |
| ... | @@ -1853,7 +1886,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1853,7 +1886,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1853 | continue; | 1886 | continue; |
| 1854 | }, | 1887 | }, |
| 1855 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { | 1888 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { |
| 1856 | const node = try arena.create(ast.Node.PrefixOp{ | 1889 | const node = try arena.create(ast.Node.PrefixOp); |
| | 1890 | node.* = ast.Node.PrefixOp{ |
| 1857 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, | 1891 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 1858 | .op_token = token_index, | 1892 | .op_token = token_index, |
| 1859 | .op = switch (token_ptr.id) { | 1893 | .op = switch (token_ptr.id) { |
| ... | @@ -1863,7 +1897,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1863,7 +1897,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1863 | else => unreachable, | 1897 | else => unreachable, |
| 1864 | }, | 1898 | }, |
| 1865 | .rhs = undefined, | 1899 | .rhs = undefined, |
| 1866 | }); | 1900 | }; |
| 1867 | opt_ctx.store(&node.base); | 1901 | opt_ctx.store(&node.base); |
| 1868 | | 1902 | |
| 1869 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; | 1903 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| ... | @@ -1887,13 +1921,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1887,13 +1921,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1887 | const lhs = opt_ctx.get() orelse continue; | 1921 | const lhs = opt_ctx.get() orelse continue; |
| 1888 | | 1922 | |
| 1889 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { | 1923 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 1890 | const node = try arena.create(ast.Node.InfixOp{ | 1924 | const node = try arena.create(ast.Node.InfixOp); |
| | 1925 | node.* = ast.Node.InfixOp{ |
| 1891 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 1926 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1892 | .lhs = lhs, | 1927 | .lhs = lhs, |
| 1893 | .op_token = ellipsis3, | 1928 | .op_token = ellipsis3, |
| 1894 | .op = ast.Node.InfixOp.Op.Range, | 1929 | .op = ast.Node.InfixOp.Op.Range, |
| 1895 | .rhs = undefined, | 1930 | .rhs = undefined, |
| 1896 | }); | 1931 | }; |
| 1897 | opt_ctx.store(&node.base); | 1932 | opt_ctx.store(&node.base); |
| 1898 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; | 1933 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 1899 | continue; | 1934 | continue; |
| ... | @@ -1912,13 +1947,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1912,13 +1947,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1912 | const token_index = token.index; | 1947 | const token_index = token.index; |
| 1913 | const token_ptr = token.ptr; | 1948 | const token_ptr = token.ptr; |
| 1914 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { | 1949 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { |
| 1915 | const node = try arena.create(ast.Node.InfixOp{ | 1950 | const node = try arena.create(ast.Node.InfixOp); |
| | 1951 | node.* = ast.Node.InfixOp{ |
| 1916 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 1952 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1917 | .lhs = lhs, | 1953 | .lhs = lhs, |
| 1918 | .op_token = token_index, | 1954 | .op_token = token_index, |
| 1919 | .op = ass_id, | 1955 | .op = ass_id, |
| 1920 | .rhs = undefined, | 1956 | .rhs = undefined, |
| 1921 | }); | 1957 | }; |
| 1922 | opt_ctx.store(&node.base); | 1958 | opt_ctx.store(&node.base); |
| 1923 | stack.append(State{ .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1959 | stack.append(State{ .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1924 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }); | 1960 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -1942,13 +1978,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1942,13 +1978,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1942 | const token_index = token.index; | 1978 | const token_index = token.index; |
| 1943 | const token_ptr = token.ptr; | 1979 | const token_ptr = token.ptr; |
| 1944 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { | 1980 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { |
| 1945 | const node = try arena.create(ast.Node.InfixOp{ | 1981 | const node = try arena.create(ast.Node.InfixOp); |
| | 1982 | node.* = ast.Node.InfixOp{ |
| 1946 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 1983 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1947 | .lhs = lhs, | 1984 | .lhs = lhs, |
| 1948 | .op_token = token_index, | 1985 | .op_token = token_index, |
| 1949 | .op = unwrap_id, | 1986 | .op = unwrap_id, |
| 1950 | .rhs = undefined, | 1987 | .rhs = undefined, |
| 1951 | }); | 1988 | }; |
| 1952 | opt_ctx.store(&node.base); | 1989 | opt_ctx.store(&node.base); |
| 1953 | | 1990 | |
| 1954 | stack.append(State{ .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1991 | stack.append(State{ .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | @@ -1974,13 +2011,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1974,13 +2011,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1974 | const lhs = opt_ctx.get() orelse continue; | 2011 | const lhs = opt_ctx.get() orelse continue; |
| 1975 | | 2012 | |
| 1976 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { | 2013 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 1977 | const node = try arena.create(ast.Node.InfixOp{ | 2014 | const node = try arena.create(ast.Node.InfixOp); |
| | 2015 | node.* = ast.Node.InfixOp{ |
| 1978 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2016 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1979 | .lhs = lhs, | 2017 | .lhs = lhs, |
| 1980 | .op_token = or_token, | 2018 | .op_token = or_token, |
| 1981 | .op = ast.Node.InfixOp.Op.BoolOr, | 2019 | .op = ast.Node.InfixOp.Op.BoolOr, |
| 1982 | .rhs = undefined, | 2020 | .rhs = undefined, |
| 1983 | }); | 2021 | }; |
| 1984 | opt_ctx.store(&node.base); | 2022 | opt_ctx.store(&node.base); |
| 1985 | stack.append(State{ .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2023 | stack.append(State{ .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1986 | try stack.append(State{ .BoolAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2024 | try stack.append(State{ .BoolAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -1998,13 +2036,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1998,13 +2036,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1998 | const lhs = opt_ctx.get() orelse continue; | 2036 | const lhs = opt_ctx.get() orelse continue; |
| 1999 | | 2037 | |
| 2000 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { | 2038 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 2001 | const node = try arena.create(ast.Node.InfixOp{ | 2039 | const node = try arena.create(ast.Node.InfixOp); |
| | 2040 | node.* = ast.Node.InfixOp{ |
| 2002 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2041 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2003 | .lhs = lhs, | 2042 | .lhs = lhs, |
| 2004 | .op_token = and_token, | 2043 | .op_token = and_token, |
| 2005 | .op = ast.Node.InfixOp.Op.BoolAnd, | 2044 | .op = ast.Node.InfixOp.Op.BoolAnd, |
| 2006 | .rhs = undefined, | 2045 | .rhs = undefined, |
| 2007 | }); | 2046 | }; |
| 2008 | opt_ctx.store(&node.base); | 2047 | opt_ctx.store(&node.base); |
| 2009 | stack.append(State{ .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2048 | stack.append(State{ .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2010 | try stack.append(State{ .ComparisonExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2049 | try stack.append(State{ .ComparisonExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2025,13 +2064,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2025,13 +2064,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2025 | const token_index = token.index; | 2064 | const token_index = token.index; |
| 2026 | const token_ptr = token.ptr; | 2065 | const token_ptr = token.ptr; |
| 2027 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { | 2066 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { |
| 2028 | const node = try arena.create(ast.Node.InfixOp{ | 2067 | const node = try arena.create(ast.Node.InfixOp); |
| | 2068 | node.* = ast.Node.InfixOp{ |
| 2029 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2069 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2030 | .lhs = lhs, | 2070 | .lhs = lhs, |
| 2031 | .op_token = token_index, | 2071 | .op_token = token_index, |
| 2032 | .op = comp_id, | 2072 | .op = comp_id, |
| 2033 | .rhs = undefined, | 2073 | .rhs = undefined, |
| 2034 | }); | 2074 | }; |
| 2035 | opt_ctx.store(&node.base); | 2075 | opt_ctx.store(&node.base); |
| 2036 | stack.append(State{ .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2076 | stack.append(State{ .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2037 | try stack.append(State{ .BinaryOrExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2077 | try stack.append(State{ .BinaryOrExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2052,13 +2092,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2052,13 +2092,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2052 | const lhs = opt_ctx.get() orelse continue; | 2092 | const lhs = opt_ctx.get() orelse continue; |
| 2053 | | 2093 | |
| 2054 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { | 2094 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 2055 | const node = try arena.create(ast.Node.InfixOp{ | 2095 | const node = try arena.create(ast.Node.InfixOp); |
| | 2096 | node.* = ast.Node.InfixOp{ |
| 2056 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2097 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2057 | .lhs = lhs, | 2098 | .lhs = lhs, |
| 2058 | .op_token = pipe, | 2099 | .op_token = pipe, |
| 2059 | .op = ast.Node.InfixOp.Op.BitOr, | 2100 | .op = ast.Node.InfixOp.Op.BitOr, |
| 2060 | .rhs = undefined, | 2101 | .rhs = undefined, |
| 2061 | }); | 2102 | }; |
| 2062 | opt_ctx.store(&node.base); | 2103 | opt_ctx.store(&node.base); |
| 2063 | stack.append(State{ .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2104 | stack.append(State{ .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2064 | try stack.append(State{ .BinaryXorExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2105 | try stack.append(State{ .BinaryXorExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2076,13 +2117,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2076,13 +2117,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2076 | const lhs = opt_ctx.get() orelse continue; | 2117 | const lhs = opt_ctx.get() orelse continue; |
| 2077 | | 2118 | |
| 2078 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { | 2119 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2079 | const node = try arena.create(ast.Node.InfixOp{ | 2120 | const node = try arena.create(ast.Node.InfixOp); |
| | 2121 | node.* = ast.Node.InfixOp{ |
| 2080 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2122 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2081 | .lhs = lhs, | 2123 | .lhs = lhs, |
| 2082 | .op_token = caret, | 2124 | .op_token = caret, |
| 2083 | .op = ast.Node.InfixOp.Op.BitXor, | 2125 | .op = ast.Node.InfixOp.Op.BitXor, |
| 2084 | .rhs = undefined, | 2126 | .rhs = undefined, |
| 2085 | }); | 2127 | }; |
| 2086 | opt_ctx.store(&node.base); | 2128 | opt_ctx.store(&node.base); |
| 2087 | stack.append(State{ .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2129 | stack.append(State{ .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2088 | try stack.append(State{ .BinaryAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2130 | try stack.append(State{ .BinaryAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2100,13 +2142,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2100,13 +2142,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2100 | const lhs = opt_ctx.get() orelse continue; | 2142 | const lhs = opt_ctx.get() orelse continue; |
| 2101 | | 2143 | |
| 2102 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { | 2144 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2103 | const node = try arena.create(ast.Node.InfixOp{ | 2145 | const node = try arena.create(ast.Node.InfixOp); |
| | 2146 | node.* = ast.Node.InfixOp{ |
| 2104 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2147 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2105 | .lhs = lhs, | 2148 | .lhs = lhs, |
| 2106 | .op_token = ampersand, | 2149 | .op_token = ampersand, |
| 2107 | .op = ast.Node.InfixOp.Op.BitAnd, | 2150 | .op = ast.Node.InfixOp.Op.BitAnd, |
| 2108 | .rhs = undefined, | 2151 | .rhs = undefined, |
| 2109 | }); | 2152 | }; |
| 2110 | opt_ctx.store(&node.base); | 2153 | opt_ctx.store(&node.base); |
| 2111 | stack.append(State{ .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2154 | stack.append(State{ .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2112 | try stack.append(State{ .BitShiftExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2155 | try stack.append(State{ .BitShiftExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2127,13 +2170,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2127,13 +2170,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2127 | const token_index = token.index; | 2170 | const token_index = token.index; |
| 2128 | const token_ptr = token.ptr; | 2171 | const token_ptr = token.ptr; |
| 2129 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { | 2172 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { |
| 2130 | const node = try arena.create(ast.Node.InfixOp{ | 2173 | const node = try arena.create(ast.Node.InfixOp); |
| | 2174 | node.* = ast.Node.InfixOp{ |
| 2131 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2175 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2132 | .lhs = lhs, | 2176 | .lhs = lhs, |
| 2133 | .op_token = token_index, | 2177 | .op_token = token_index, |
| 2134 | .op = bitshift_id, | 2178 | .op = bitshift_id, |
| 2135 | .rhs = undefined, | 2179 | .rhs = undefined, |
| 2136 | }); | 2180 | }; |
| 2137 | opt_ctx.store(&node.base); | 2181 | opt_ctx.store(&node.base); |
| 2138 | stack.append(State{ .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2182 | stack.append(State{ .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2139 | try stack.append(State{ .AdditionExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2183 | try stack.append(State{ .AdditionExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2157,13 +2201,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2157,13 +2201,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2157 | const token_index = token.index; | 2201 | const token_index = token.index; |
| 2158 | const token_ptr = token.ptr; | 2202 | const token_ptr = token.ptr; |
| 2159 | if (tokenIdToAddition(token_ptr.id)) |add_id| { | 2203 | if (tokenIdToAddition(token_ptr.id)) |add_id| { |
| 2160 | const node = try arena.create(ast.Node.InfixOp{ | 2204 | const node = try arena.create(ast.Node.InfixOp); |
| | 2205 | node.* = ast.Node.InfixOp{ |
| 2161 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2206 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2162 | .lhs = lhs, | 2207 | .lhs = lhs, |
| 2163 | .op_token = token_index, | 2208 | .op_token = token_index, |
| 2164 | .op = add_id, | 2209 | .op = add_id, |
| 2165 | .rhs = undefined, | 2210 | .rhs = undefined, |
| 2166 | }); | 2211 | }; |
| 2167 | opt_ctx.store(&node.base); | 2212 | opt_ctx.store(&node.base); |
| 2168 | stack.append(State{ .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2213 | stack.append(State{ .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2169 | try stack.append(State{ .MultiplyExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2214 | try stack.append(State{ .MultiplyExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2187,13 +2232,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2187,13 +2232,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2187 | const token_index = token.index; | 2232 | const token_index = token.index; |
| 2188 | const token_ptr = token.ptr; | 2233 | const token_ptr = token.ptr; |
| 2189 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { | 2234 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { |
| 2190 | const node = try arena.create(ast.Node.InfixOp{ | 2235 | const node = try arena.create(ast.Node.InfixOp); |
| | 2236 | node.* = ast.Node.InfixOp{ |
| 2191 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2237 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2192 | .lhs = lhs, | 2238 | .lhs = lhs, |
| 2193 | .op_token = token_index, | 2239 | .op_token = token_index, |
| 2194 | .op = mult_id, | 2240 | .op = mult_id, |
| 2195 | .rhs = undefined, | 2241 | .rhs = undefined, |
| 2196 | }); | 2242 | }; |
| 2197 | opt_ctx.store(&node.base); | 2243 | opt_ctx.store(&node.base); |
| 2198 | stack.append(State{ .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2244 | stack.append(State{ .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2199 | try stack.append(State{ .CurlySuffixExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); | 2245 | try stack.append(State{ .CurlySuffixExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2215,12 +2261,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2215,12 +2261,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2215 | const lhs = opt_ctx.get() orelse continue; | 2261 | const lhs = opt_ctx.get() orelse continue; |
| 2216 | | 2262 | |
| 2217 | if (tok_it.peek().?.id == Token.Id.Period) { | 2263 | if (tok_it.peek().?.id == Token.Id.Period) { |
| 2218 | const node = try arena.create(ast.Node.SuffixOp{ | 2264 | const node = try arena.create(ast.Node.SuffixOp); |
| | 2265 | node.* = ast.Node.SuffixOp{ |
| 2219 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, | 2266 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2220 | .lhs = lhs, | 2267 | .lhs = lhs, |
| 2221 | .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, | 2268 | .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| 2222 | .rtoken = undefined, | 2269 | .rtoken = undefined, |
| 2223 | }); | 2270 | }; |
| 2224 | opt_ctx.store(&node.base); | 2271 | opt_ctx.store(&node.base); |
| 2225 | | 2272 | |
| 2226 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2273 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | @@ -2234,12 +2281,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2234,12 +2281,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2234 | continue; | 2281 | continue; |
| 2235 | } | 2282 | } |
| 2236 | | 2283 | |
| 2237 | const node = try arena.create(ast.Node.SuffixOp{ | 2284 | const node = try arena.create(ast.Node.SuffixOp); |
| | 2285 | node.* = ast.Node.SuffixOp{ |
| 2238 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, | 2286 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2239 | .lhs = lhs, | 2287 | .lhs = lhs, |
| 2240 | .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, | 2288 | .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| 2241 | .rtoken = undefined, | 2289 | .rtoken = undefined, |
| 2242 | }); | 2290 | }; |
| 2243 | opt_ctx.store(&node.base); | 2291 | opt_ctx.store(&node.base); |
| 2244 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2292 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2245 | try stack.append(State{ .IfToken = Token.Id.LBrace }); | 2293 | try stack.append(State{ .IfToken = Token.Id.LBrace }); |
| ... | @@ -2263,13 +2311,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2263,13 +2311,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2263 | const lhs = opt_ctx.get() orelse continue; | 2311 | const lhs = opt_ctx.get() orelse continue; |
| 2264 | | 2312 | |
| 2265 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { | 2313 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2266 | const node = try arena.create(ast.Node.InfixOp{ | 2314 | const node = try arena.create(ast.Node.InfixOp); |
| | 2315 | node.* = ast.Node.InfixOp{ |
| 2267 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2316 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2268 | .lhs = lhs, | 2317 | .lhs = lhs, |
| 2269 | .op_token = bang, | 2318 | .op_token = bang, |
| 2270 | .op = ast.Node.InfixOp.Op.ErrorUnion, | 2319 | .op = ast.Node.InfixOp.Op.ErrorUnion, |
| 2271 | .rhs = undefined, | 2320 | .rhs = undefined, |
| 2272 | }); | 2321 | }; |
| 2273 | opt_ctx.store(&node.base); | 2322 | opt_ctx.store(&node.base); |
| 2274 | stack.append(State{ .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; | 2323 | stack.append(State{ .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2275 | try stack.append(State{ .PrefixOpExpression = OptionalCtx{ .Required = &node.rhs } }); | 2324 | try stack.append(State{ .PrefixOpExpression = OptionalCtx{ .Required = &node.rhs } }); |
| ... | @@ -2282,22 +2331,24 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2282,22 +2331,24 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2282 | const token_index = token.index; | 2331 | const token_index = token.index; |
| 2283 | const token_ptr = token.ptr; | 2332 | const token_ptr = token.ptr; |
| 2284 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { | 2333 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { |
| 2285 | var node = try arena.create(ast.Node.PrefixOp{ | 2334 | var node = try arena.create(ast.Node.PrefixOp); |
| | 2335 | node.* = ast.Node.PrefixOp{ |
| 2286 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, | 2336 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2287 | .op_token = token_index, | 2337 | .op_token = token_index, |
| 2288 | .op = prefix_id, | 2338 | .op = prefix_id, |
| 2289 | .rhs = undefined, | 2339 | .rhs = undefined, |
| 2290 | }); | 2340 | }; |
| 2291 | opt_ctx.store(&node.base); | 2341 | opt_ctx.store(&node.base); |
| 2292 | | 2342 | |
| 2293 | // Treat '**' token as two pointer types | 2343 | // Treat '**' token as two pointer types |
| 2294 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { | 2344 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { |
| 2295 | const child = try arena.create(ast.Node.PrefixOp{ | 2345 | const child = try arena.create(ast.Node.PrefixOp); |
| | 2346 | child.* = ast.Node.PrefixOp{ |
| 2296 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, | 2347 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2297 | .op_token = token_index, | 2348 | .op_token = token_index, |
| 2298 | .op = prefix_id, | 2349 | .op = prefix_id, |
| 2299 | .rhs = undefined, | 2350 | .rhs = undefined, |
| 2300 | }); | 2351 | }; |
| 2301 | node.rhs = &child.base; | 2352 | node.rhs = &child.base; |
| 2302 | node = child; | 2353 | node = child; |
| 2303 | } | 2354 | } |
| ... | @@ -2316,12 +2367,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2316,12 +2367,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2316 | | 2367 | |
| 2317 | State.SuffixOpExpressionBegin => |opt_ctx| { | 2368 | State.SuffixOpExpressionBegin => |opt_ctx| { |
| 2318 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { | 2369 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { |
| 2319 | const async_node = try arena.create(ast.Node.AsyncAttribute{ | 2370 | const async_node = try arena.create(ast.Node.AsyncAttribute); |
| | 2371 | async_node.* = ast.Node.AsyncAttribute{ |
| 2320 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, | 2372 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 2321 | .async_token = async_token, | 2373 | .async_token = async_token, |
| 2322 | .allocator_type = null, | 2374 | .allocator_type = null, |
| 2323 | .rangle_bracket = null, | 2375 | .rangle_bracket = null, |
| 2324 | }); | 2376 | }; |
| 2325 | stack.append(State{ | 2377 | stack.append(State{ |
| 2326 | .AsyncEnd = AsyncEndCtx{ | 2378 | .AsyncEnd = AsyncEndCtx{ |
| 2327 | .ctx = opt_ctx, | 2379 | .ctx = opt_ctx, |
| ... | @@ -2347,7 +2399,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2347,7 +2399,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2347 | const token_ptr = token.ptr; | 2399 | const token_ptr = token.ptr; |
| 2348 | switch (token_ptr.id) { | 2400 | switch (token_ptr.id) { |
| 2349 | Token.Id.LParen => { | 2401 | Token.Id.LParen => { |
| 2350 | const node = try arena.create(ast.Node.SuffixOp{ | 2402 | const node = try arena.create(ast.Node.SuffixOp); |
| | 2403 | node.* = ast.Node.SuffixOp{ |
| 2351 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, | 2404 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2352 | .lhs = lhs, | 2405 | .lhs = lhs, |
| 2353 | .op = ast.Node.SuffixOp.Op{ | 2406 | .op = ast.Node.SuffixOp.Op{ |
| ... | @@ -2357,7 +2410,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2357,7 +2410,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2357 | }, | 2410 | }, |
| 2358 | }, | 2411 | }, |
| 2359 | .rtoken = undefined, | 2412 | .rtoken = undefined, |
| 2360 | }); | 2413 | }; |
| 2361 | opt_ctx.store(&node.base); | 2414 | opt_ctx.store(&node.base); |
| 2362 | | 2415 | |
| 2363 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2416 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | @@ -2371,12 +2424,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2371,12 +2424,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2371 | continue; | 2424 | continue; |
| 2372 | }, | 2425 | }, |
| 2373 | Token.Id.LBracket => { | 2426 | Token.Id.LBracket => { |
| 2374 | const node = try arena.create(ast.Node.SuffixOp{ | 2427 | const node = try arena.create(ast.Node.SuffixOp); |
| | 2428 | node.* = ast.Node.SuffixOp{ |
| 2375 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, | 2429 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2376 | .lhs = lhs, | 2430 | .lhs = lhs, |
| 2377 | .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined }, | 2431 | .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined }, |
| 2378 | .rtoken = undefined, | 2432 | .rtoken = undefined, |
| 2379 | }); | 2433 | }; |
| 2380 | opt_ctx.store(&node.base); | 2434 | opt_ctx.store(&node.base); |
| 2381 | | 2435 | |
| 2382 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2436 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | @@ -2386,34 +2440,37 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2386,34 +2440,37 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2386 | }, | 2440 | }, |
| 2387 | Token.Id.Period => { | 2441 | Token.Id.Period => { |
| 2388 | if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| { | 2442 | if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| { |
| 2389 | const node = try arena.create(ast.Node.SuffixOp{ | 2443 | const node = try arena.create(ast.Node.SuffixOp); |
| | 2444 | node.* = ast.Node.SuffixOp{ |
| 2390 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, | 2445 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2391 | .lhs = lhs, | 2446 | .lhs = lhs, |
| 2392 | .op = ast.Node.SuffixOp.Op.Deref, | 2447 | .op = ast.Node.SuffixOp.Op.Deref, |
| 2393 | .rtoken = asterisk_token, | 2448 | .rtoken = asterisk_token, |
| 2394 | }); | 2449 | }; |
| 2395 | opt_ctx.store(&node.base); | 2450 | opt_ctx.store(&node.base); |
| 2396 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2451 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2397 | continue; | 2452 | continue; |
| 2398 | } | 2453 | } |
| 2399 | if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| { | 2454 | if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| { |
| 2400 | const node = try arena.create(ast.Node.SuffixOp{ | 2455 | const node = try arena.create(ast.Node.SuffixOp); |
| | 2456 | node.* = ast.Node.SuffixOp{ |
| 2401 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, | 2457 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2402 | .lhs = lhs, | 2458 | .lhs = lhs, |
| 2403 | .op = ast.Node.SuffixOp.Op.UnwrapOptional, | 2459 | .op = ast.Node.SuffixOp.Op.UnwrapOptional, |
| 2404 | .rtoken = question_token, | 2460 | .rtoken = question_token, |
| 2405 | }); | 2461 | }; |
| 2406 | opt_ctx.store(&node.base); | 2462 | opt_ctx.store(&node.base); |
| 2407 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2463 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2408 | continue; | 2464 | continue; |
| 2409 | } | 2465 | } |
| 2410 | const node = try arena.create(ast.Node.InfixOp{ | 2466 | const node = try arena.create(ast.Node.InfixOp); |
| | 2467 | node.* = ast.Node.InfixOp{ |
| 2411 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2468 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2412 | .lhs = lhs, | 2469 | .lhs = lhs, |
| 2413 | .op_token = token_index, | 2470 | .op_token = token_index, |
| 2414 | .op = ast.Node.InfixOp.Op.Period, | 2471 | .op = ast.Node.InfixOp.Op.Period, |
| 2415 | .rhs = undefined, | 2472 | .rhs = undefined, |
| 2416 | }); | 2473 | }; |
| 2417 | opt_ctx.store(&node.base); | 2474 | opt_ctx.store(&node.base); |
| 2418 | | 2475 | |
| 2419 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2476 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | @@ -2467,11 +2524,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2467,11 +2524,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2467 | continue; | 2524 | continue; |
| 2468 | }, | 2525 | }, |
| 2469 | Token.Id.Keyword_promise => { | 2526 | Token.Id.Keyword_promise => { |
| 2470 | const node = try arena.create(ast.Node.PromiseType{ | 2527 | const node = try arena.create(ast.Node.PromiseType); |
| | 2528 | node.* = ast.Node.PromiseType{ |
| 2471 | .base = ast.Node{ .id = ast.Node.Id.PromiseType }, | 2529 | .base = ast.Node{ .id = ast.Node.Id.PromiseType }, |
| 2472 | .promise_token = token.index, | 2530 | .promise_token = token.index, |
| 2473 | .result = null, | 2531 | .result = null, |
| 2474 | }); | 2532 | }; |
| 2475 | opt_ctx.store(&node.base); | 2533 | opt_ctx.store(&node.base); |
| 2476 | const next_token = nextToken(&tok_it, &tree); | 2534 | const next_token = nextToken(&tok_it, &tree); |
| 2477 | const next_token_index = next_token.index; | 2535 | const next_token_index = next_token.index; |
| ... | @@ -2493,12 +2551,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2493,12 +2551,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2493 | continue; | 2551 | continue; |
| 2494 | }, | 2552 | }, |
| 2495 | Token.Id.LParen => { | 2553 | Token.Id.LParen => { |
| 2496 | const node = try arena.create(ast.Node.GroupedExpression{ | 2554 | const node = try arena.create(ast.Node.GroupedExpression); |
| | 2555 | node.* = ast.Node.GroupedExpression{ |
| 2497 | .base = ast.Node{ .id = ast.Node.Id.GroupedExpression }, | 2556 | .base = ast.Node{ .id = ast.Node.Id.GroupedExpression }, |
| 2498 | .lparen = token.index, | 2557 | .lparen = token.index, |
| 2499 | .expr = undefined, | 2558 | .expr = undefined, |
| 2500 | .rparen = undefined, | 2559 | .rparen = undefined, |
| 2501 | }); | 2560 | }; |
| 2502 | opt_ctx.store(&node.base); | 2561 | opt_ctx.store(&node.base); |
| 2503 | | 2562 | |
| 2504 | stack.append(State{ | 2563 | stack.append(State{ |
| ... | @@ -2511,12 +2570,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2511,12 +2570,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2511 | continue; | 2570 | continue; |
| 2512 | }, | 2571 | }, |
| 2513 | Token.Id.Builtin => { | 2572 | Token.Id.Builtin => { |
| 2514 | const node = try arena.create(ast.Node.BuiltinCall{ | 2573 | const node = try arena.create(ast.Node.BuiltinCall); |
| | 2574 | node.* = ast.Node.BuiltinCall{ |
| 2515 | .base = ast.Node{ .id = ast.Node.Id.BuiltinCall }, | 2575 | .base = ast.Node{ .id = ast.Node.Id.BuiltinCall }, |
| 2516 | .builtin_token = token.index, | 2576 | .builtin_token = token.index, |
| 2517 | .params = ast.Node.BuiltinCall.ParamList.init(arena), | 2577 | .params = ast.Node.BuiltinCall.ParamList.init(arena), |
| 2518 | .rparen_token = undefined, | 2578 | .rparen_token = undefined, |
| 2519 | }); | 2579 | }; |
| 2520 | opt_ctx.store(&node.base); | 2580 | opt_ctx.store(&node.base); |
| 2521 | | 2581 | |
| 2522 | stack.append(State{ | 2582 | stack.append(State{ |
| ... | @@ -2530,12 +2590,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2530,12 +2590,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2530 | continue; | 2590 | continue; |
| 2531 | }, | 2591 | }, |
| 2532 | Token.Id.LBracket => { | 2592 | Token.Id.LBracket => { |
| 2533 | const node = try arena.create(ast.Node.PrefixOp{ | 2593 | const node = try arena.create(ast.Node.PrefixOp); |
| | 2594 | node.* = ast.Node.PrefixOp{ |
| 2534 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, | 2595 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2535 | .op_token = token.index, | 2596 | .op_token = token.index, |
| 2536 | .op = undefined, | 2597 | .op = undefined, |
| 2537 | .rhs = undefined, | 2598 | .rhs = undefined, |
| 2538 | }); | 2599 | }; |
| 2539 | opt_ctx.store(&node.base); | 2600 | opt_ctx.store(&node.base); |
| 2540 | | 2601 | |
| 2541 | stack.append(State{ .SliceOrArrayType = node }) catch unreachable; | 2602 | stack.append(State{ .SliceOrArrayType = node }) catch unreachable; |
| ... | @@ -2593,7 +2654,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2593,7 +2654,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2593 | continue; | 2654 | continue; |
| 2594 | }, | 2655 | }, |
| 2595 | Token.Id.Keyword_fn => { | 2656 | Token.Id.Keyword_fn => { |
| 2596 | const fn_proto = try arena.create(ast.Node.FnProto{ | 2657 | const fn_proto = try arena.create(ast.Node.FnProto); |
| | 2658 | fn_proto.* = ast.Node.FnProto{ |
| 2597 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, | 2659 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2598 | .doc_comments = null, | 2660 | .doc_comments = null, |
| 2599 | .visib_token = null, | 2661 | .visib_token = null, |
| ... | @@ -2609,13 +2671,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2609,13 +2671,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2609 | .lib_name = null, | 2671 | .lib_name = null, |
| 2610 | .align_expr = null, | 2672 | .align_expr = null, |
| 2611 | .section_expr = null, | 2673 | .section_expr = null, |
| 2612 | }); | 2674 | }; |
| 2613 | opt_ctx.store(&fn_proto.base); | 2675 | opt_ctx.store(&fn_proto.base); |
| 2614 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; | 2676 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 2615 | continue; | 2677 | continue; |
| 2616 | }, | 2678 | }, |
| 2617 | Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { | 2679 | Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { |
| 2618 | const fn_proto = try arena.create(ast.Node.FnProto{ | 2680 | const fn_proto = try arena.create(ast.Node.FnProto); |
| | 2681 | fn_proto.* = ast.Node.FnProto{ |
| 2619 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, | 2682 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2620 | .doc_comments = null, | 2683 | .doc_comments = null, |
| 2621 | .visib_token = null, | 2684 | .visib_token = null, |
| ... | @@ -2631,7 +2694,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2631,7 +2694,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2631 | .lib_name = null, | 2694 | .lib_name = null, |
| 2632 | .align_expr = null, | 2695 | .align_expr = null, |
| 2633 | .section_expr = null, | 2696 | .section_expr = null, |
| 2634 | }); | 2697 | }; |
| 2635 | opt_ctx.store(&fn_proto.base); | 2698 | opt_ctx.store(&fn_proto.base); |
| 2636 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; | 2699 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 2637 | try stack.append(State{ | 2700 | try stack.append(State{ |
| ... | @@ -2643,7 +2706,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2643,7 +2706,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2643 | continue; | 2706 | continue; |
| 2644 | }, | 2707 | }, |
| 2645 | Token.Id.Keyword_asm => { | 2708 | Token.Id.Keyword_asm => { |
| 2646 | const node = try arena.create(ast.Node.Asm{ | 2709 | const node = try arena.create(ast.Node.Asm); |
| | 2710 | node.* = ast.Node.Asm{ |
| 2647 | .base = ast.Node{ .id = ast.Node.Id.Asm }, | 2711 | .base = ast.Node{ .id = ast.Node.Id.Asm }, |
| 2648 | .asm_token = token.index, | 2712 | .asm_token = token.index, |
| 2649 | .volatile_token = null, | 2713 | .volatile_token = null, |
| ... | @@ -2652,7 +2716,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2652,7 +2716,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2652 | .inputs = ast.Node.Asm.InputList.init(arena), | 2716 | .inputs = ast.Node.Asm.InputList.init(arena), |
| 2653 | .clobbers = ast.Node.Asm.ClobberList.init(arena), | 2717 | .clobbers = ast.Node.Asm.ClobberList.init(arena), |
| 2654 | .rparen = undefined, | 2718 | .rparen = undefined, |
| 2655 | }); | 2719 | }; |
| 2656 | opt_ctx.store(&node.base); | 2720 | opt_ctx.store(&node.base); |
| 2657 | | 2721 | |
| 2658 | stack.append(State{ | 2722 | stack.append(State{ |
| ... | @@ -2701,13 +2765,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2701,13 +2765,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2701 | | 2765 | |
| 2702 | State.ErrorTypeOrSetDecl => |ctx| { | 2766 | State.ErrorTypeOrSetDecl => |ctx| { |
| 2703 | if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) { | 2767 | if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) { |
| 2704 | const node = try arena.create(ast.Node.InfixOp{ | 2768 | const node = try arena.create(ast.Node.InfixOp); |
| | 2769 | node.* = ast.Node.InfixOp{ |
| 2705 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, | 2770 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2706 | .lhs = &(try createLiteral(arena, ast.Node.ErrorType, ctx.error_token)).base, | 2771 | .lhs = &(try createLiteral(arena, ast.Node.ErrorType, ctx.error_token)).base, |
| 2707 | .op_token = undefined, | 2772 | .op_token = undefined, |
| 2708 | .op = ast.Node.InfixOp.Op.Period, | 2773 | .op = ast.Node.InfixOp.Op.Period, |
| 2709 | .rhs = undefined, | 2774 | .rhs = undefined, |
| 2710 | }); | 2775 | }; |
| 2711 | ctx.opt_ctx.store(&node.base); | 2776 | ctx.opt_ctx.store(&node.base); |
| 2712 | stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; | 2777 | stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 2713 | try stack.append(State{ | 2778 | try stack.append(State{ |
| ... | @@ -2719,12 +2784,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2719,12 +2784,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2719 | continue; | 2784 | continue; |
| 2720 | } | 2785 | } |
| 2721 | | 2786 | |
| 2722 | const node = try arena.create(ast.Node.ErrorSetDecl{ | 2787 | const node = try arena.create(ast.Node.ErrorSetDecl); |
| | 2788 | node.* = ast.Node.ErrorSetDecl{ |
| 2723 | .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl }, | 2789 | .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl }, |
| 2724 | .error_token = ctx.error_token, | 2790 | .error_token = ctx.error_token, |
| 2725 | .decls = ast.Node.ErrorSetDecl.DeclList.init(arena), | 2791 | .decls = ast.Node.ErrorSetDecl.DeclList.init(arena), |
| 2726 | .rbrace_token = undefined, | 2792 | .rbrace_token = undefined, |
| 2727 | }); | 2793 | }; |
| 2728 | ctx.opt_ctx.store(&node.base); | 2794 | ctx.opt_ctx.store(&node.base); |
| 2729 | | 2795 | |
| 2730 | stack.append(State{ | 2796 | stack.append(State{ |
| ... | @@ -2785,11 +2851,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2785,11 +2851,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2785 | return tree; | 2851 | return tree; |
| 2786 | } | 2852 | } |
| 2787 | | 2853 | |
| 2788 | const node = try arena.create(ast.Node.ErrorTag{ | 2854 | const node = try arena.create(ast.Node.ErrorTag); |
| | 2855 | node.* = ast.Node.ErrorTag{ |
| 2789 | .base = ast.Node{ .id = ast.Node.Id.ErrorTag }, | 2856 | .base = ast.Node{ .id = ast.Node.Id.ErrorTag }, |
| 2790 | .doc_comments = comments, | 2857 | .doc_comments = comments, |
| 2791 | .name_token = ident_token_index, | 2858 | .name_token = ident_token_index, |
| 2792 | }); | 2859 | }; |
| 2793 | node_ptr.* = &node.base; | 2860 | node_ptr.* = &node.base; |
| 2794 | continue; | 2861 | continue; |
| 2795 | }, | 2862 | }, |
| ... | @@ -3129,10 +3196,11 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as | ... | @@ -3129,10 +3196,11 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as |
| 3129 | if (result.*) |comment_node| { | 3196 | if (result.*) |comment_node| { |
| 3130 | break :blk comment_node; | 3197 | break :blk comment_node; |
| 3131 | } else { | 3198 | } else { |
| 3132 | const comment_node = try arena.create(ast.Node.DocComment{ | 3199 | const comment_node = try arena.create(ast.Node.DocComment); |
| | 3200 | comment_node.* = ast.Node.DocComment{ |
| 3133 | .base = ast.Node{ .id = ast.Node.Id.DocComment }, | 3201 | .base = ast.Node{ .id = ast.Node.Id.DocComment }, |
| 3134 | .lines = ast.Node.DocComment.LineList.init(arena), | 3202 | .lines = ast.Node.DocComment.LineList.init(arena), |
| 3135 | }); | 3203 | }; |
| 3136 | result.* = comment_node; | 3204 | result.* = comment_node; |
| 3137 | break :blk comment_node; | 3205 | break :blk comment_node; |
| 3138 | } | 3206 | } |
| ... | @@ -3158,10 +3226,11 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato | ... | @@ -3158,10 +3226,11 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato |
| 3158 | return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base; | 3226 | return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base; |
| 3159 | }, | 3227 | }, |
| 3160 | Token.Id.MultilineStringLiteralLine => { | 3228 | Token.Id.MultilineStringLiteralLine => { |
| 3161 | const node = try arena.create(ast.Node.MultilineStringLiteral{ | 3229 | const node = try arena.create(ast.Node.MultilineStringLiteral); |
| | 3230 | node.* = ast.Node.MultilineStringLiteral{ |
| 3162 | .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral }, | 3231 | .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral }, |
| 3163 | .lines = ast.Node.MultilineStringLiteral.LineList.init(arena), | 3232 | .lines = ast.Node.MultilineStringLiteral.LineList.init(arena), |
| 3164 | }); | 3233 | }; |
| 3165 | try node.lines.push(token_index); | 3234 | try node.lines.push(token_index); |
| 3166 | while (true) { | 3235 | while (true) { |
| 3167 | const multiline_str = nextToken(tok_it, tree); | 3236 | const multiline_str = nextToken(tok_it, tree); |
| ... | @@ -3186,25 +3255,27 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato | ... | @@ -3186,25 +3255,27 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato |
| 3186 | fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: OptionalCtx, token_ptr: Token, token_index: TokenIndex) !bool { | 3255 | fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: OptionalCtx, token_ptr: Token, token_index: TokenIndex) !bool { |
| 3187 | switch (token_ptr.id) { | 3256 | switch (token_ptr.id) { |
| 3188 | Token.Id.Keyword_suspend => { | 3257 | Token.Id.Keyword_suspend => { |
| 3189 | const node = try arena.create(ast.Node.Suspend{ | 3258 | const node = try arena.create(ast.Node.Suspend); |
| | 3259 | node.* = ast.Node.Suspend{ |
| 3190 | .base = ast.Node{ .id = ast.Node.Id.Suspend }, | 3260 | .base = ast.Node{ .id = ast.Node.Id.Suspend }, |
| 3191 | .suspend_token = token_index, | 3261 | .suspend_token = token_index, |
| 3192 | .body = null, | 3262 | .body = null, |
| 3193 | }); | 3263 | }; |
| 3194 | ctx.store(&node.base); | 3264 | ctx.store(&node.base); |
| 3195 | | 3265 | |
| 3196 | stack.append(State{ .SuspendBody = node }) catch unreachable; | 3266 | stack.append(State{ .SuspendBody = node }) catch unreachable; |
| 3197 | return true; | 3267 | return true; |
| 3198 | }, | 3268 | }, |
| 3199 | Token.Id.Keyword_if => { | 3269 | Token.Id.Keyword_if => { |
| 3200 | const node = try arena.create(ast.Node.If{ | 3270 | const node = try arena.create(ast.Node.If); |
| | 3271 | node.* = ast.Node.If{ |
| 3201 | .base = ast.Node{ .id = ast.Node.Id.If }, | 3272 | .base = ast.Node{ .id = ast.Node.Id.If }, |
| 3202 | .if_token = token_index, | 3273 | .if_token = token_index, |
| 3203 | .condition = undefined, | 3274 | .condition = undefined, |
| 3204 | .payload = null, | 3275 | .payload = null, |
| 3205 | .body = undefined, | 3276 | .body = undefined, |
| 3206 | .@"else" = null, | 3277 | .@"else" = null, |
| 3207 | }); | 3278 | }; |
| 3208 | ctx.store(&node.base); | 3279 | ctx.store(&node.base); |
| 3209 | | 3280 | |
| 3210 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; | 3281 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| ... | @@ -3238,13 +3309,14 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: Opti | ... | @@ -3238,13 +3309,14 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: Opti |
| 3238 | return true; | 3309 | return true; |
| 3239 | }, | 3310 | }, |
| 3240 | Token.Id.Keyword_switch => { | 3311 | Token.Id.Keyword_switch => { |
| 3241 | const node = try arena.create(ast.Node.Switch{ | 3312 | const node = try arena.create(ast.Node.Switch); |
| | 3313 | node.* = ast.Node.Switch{ |
| 3242 | .base = ast.Node{ .id = ast.Node.Id.Switch }, | 3314 | .base = ast.Node{ .id = ast.Node.Id.Switch }, |
| 3243 | .switch_token = token_index, | 3315 | .switch_token = token_index, |
| 3244 | .expr = undefined, | 3316 | .expr = undefined, |
| 3245 | .cases = ast.Node.Switch.CaseList.init(arena), | 3317 | .cases = ast.Node.Switch.CaseList.init(arena), |
| 3246 | .rbrace = undefined, | 3318 | .rbrace = undefined, |
| 3247 | }); | 3319 | }; |
| 3248 | ctx.store(&node.base); | 3320 | ctx.store(&node.base); |
| 3249 | | 3321 | |
| 3250 | stack.append(State{ | 3322 | stack.append(State{ |
| ... | @@ -3260,25 +3332,27 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: Opti | ... | @@ -3260,25 +3332,27 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: Opti |
| 3260 | return true; | 3332 | return true; |
| 3261 | }, | 3333 | }, |
| 3262 | Token.Id.Keyword_comptime => { | 3334 | Token.Id.Keyword_comptime => { |
| 3263 | const node = try arena.create(ast.Node.Comptime{ | 3335 | const node = try arena.create(ast.Node.Comptime); |
| | 3336 | node.* = ast.Node.Comptime{ |
| 3264 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, | 3337 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 3265 | .comptime_token = token_index, | 3338 | .comptime_token = token_index, |
| 3266 | .expr = undefined, | 3339 | .expr = undefined, |
| 3267 | .doc_comments = null, | 3340 | .doc_comments = null, |
| 3268 | }); | 3341 | }; |
| 3269 | ctx.store(&node.base); | 3342 | ctx.store(&node.base); |
| 3270 | | 3343 | |
| 3271 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); | 3344 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 3272 | return true; | 3345 | return true; |
| 3273 | }, | 3346 | }, |
| 3274 | Token.Id.LBrace => { | 3347 | Token.Id.LBrace => { |
| 3275 | const block = try arena.create(ast.Node.Block{ | 3348 | const block = try arena.create(ast.Node.Block); |
| | 3349 | block.* = ast.Node.Block{ |
| 3276 | .base = ast.Node{ .id = ast.Node.Id.Block }, | 3350 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 3277 | .label = null, | 3351 | .label = null, |
| 3278 | .lbrace = token_index, | 3352 | .lbrace = token_index, |
| 3279 | .statements = ast.Node.Block.StatementList.init(arena), | 3353 | .statements = ast.Node.Block.StatementList.init(arena), |
| 3280 | .rbrace = undefined, | 3354 | .rbrace = undefined, |
| 3281 | }); | 3355 | }; |
| 3282 | ctx.store(&block.base); | 3356 | ctx.store(&block.base); |
| 3283 | stack.append(State{ .Block = block }) catch unreachable; | 3357 | stack.append(State{ .Block = block }) catch unreachable; |
| 3284 | return true; | 3358 | return true; |
| ... | @@ -3412,10 +3486,12 @@ fn tokenIdToPrefixOp(id: Token.Id) ?ast.Node.PrefixOp.Op { | ... | @@ -3412,10 +3486,12 @@ fn tokenIdToPrefixOp(id: Token.Id) ?ast.Node.PrefixOp.Op { |
| 3412 | } | 3486 | } |
| 3413 | | 3487 | |
| 3414 | fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T { | 3488 | fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T { |
| 3415 | return arena.create(T{ | 3489 | const result = try arena.create(T); |
| | 3490 | result.* = T{ |
| 3416 | .base = ast.Node{ .id = ast.Node.typeToId(T) }, | 3491 | .base = ast.Node{ .id = ast.Node.typeToId(T) }, |
| 3417 | .token = token_index, | 3492 | .token = token_index, |
| 3418 | }); | 3493 | }; |
| | 3494 | return result; |
| 3419 | } | 3495 | } |
| 3420 | | 3496 | |
| 3421 | fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: OptionalCtx, comptime T: type, token_index: TokenIndex) !*T { | 3497 | fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: OptionalCtx, comptime T: type, token_index: TokenIndex) !*T { |