| ... | @@ -242,6 +242,7 @@ pub const Parser = struct { | ... | @@ -242,6 +242,7 @@ pub const Parser = struct { |
| 242 | FieldInitListItemOrEnd: ListSave(&ast.Node.FieldInitializer), | 242 | FieldInitListItemOrEnd: ListSave(&ast.Node.FieldInitializer), |
| 243 | FieldInitListCommaOrEnd: ListSave(&ast.Node.FieldInitializer), | 243 | FieldInitListCommaOrEnd: ListSave(&ast.Node.FieldInitializer), |
| 244 | FieldListCommaOrEnd: &ast.Node.ContainerDecl, | 244 | FieldListCommaOrEnd: &ast.Node.ContainerDecl, |
| | 245 | FieldInitValue: OptionalCtx, |
| 245 | IdentifierListItemOrEnd: ListSave(&ast.Node), | 246 | IdentifierListItemOrEnd: ListSave(&ast.Node), |
| 246 | IdentifierListCommaOrEnd: ListSave(&ast.Node), | 247 | IdentifierListCommaOrEnd: ListSave(&ast.Node), |
| 247 | SwitchCaseOrEnd: ListSave(&ast.Node), | 248 | SwitchCaseOrEnd: ListSave(&ast.Node), |
| ... | @@ -653,6 +654,15 @@ pub const Parser = struct { | ... | @@ -653,6 +654,15 @@ pub const Parser = struct { |
| 653 | continue; | 654 | continue; |
| 654 | }, | 655 | }, |
| 655 | | 656 | |
| | 657 | State.FieldInitValue => |ctx| { |
| | 658 | const eq_tok = self.getNextToken(); |
| | 659 | if (eq_tok.id != Token.Id.Equal) { |
| | 660 | self.putBackToken(eq_tok); |
| | 661 | continue; |
| | 662 | } |
| | 663 | stack.append(State { .Expression = ctx }) catch unreachable; |
| | 664 | continue; |
| | 665 | }, |
| 656 | | 666 | |
| 657 | State.ContainerKind => |ctx| { | 667 | State.ContainerKind => |ctx| { |
| 658 | const token = self.getNextToken(); | 668 | const token = self.getNextToken(); |
| ... | @@ -699,7 +709,16 @@ pub const Parser = struct { | ... | @@ -699,7 +709,16 @@ pub const Parser = struct { |
| 699 | const init_arg_token = self.getNextToken(); | 709 | const init_arg_token = self.getNextToken(); |
| 700 | switch (init_arg_token.id) { | 710 | switch (init_arg_token.id) { |
| 701 | Token.Id.Keyword_enum => { | 711 | Token.Id.Keyword_enum => { |
| 702 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg.Enum; | 712 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg {.Enum = null}; |
| | 713 | const lparen_tok = self.getNextToken(); |
| | 714 | if (lparen_tok.id == Token.Id.LParen) { |
| | 715 | try stack.append(State { .ExpectToken = Token.Id.RParen } ); |
| | 716 | try stack.append(State { .Expression = OptionalCtx { |
| | 717 | .RequiredNull = &container_decl.init_arg_expr.Enum, |
| | 718 | } }); |
| | 719 | } else { |
| | 720 | self.putBackToken(lparen_tok); |
| | 721 | } |
| 703 | }, | 722 | }, |
| 704 | else => { | 723 | else => { |
| 705 | self.putBackToken(init_arg_token); | 724 | self.putBackToken(init_arg_token); |
| ... | @@ -709,6 +728,7 @@ pub const Parser = struct { | ... | @@ -709,6 +728,7 @@ pub const Parser = struct { |
| 709 | } | 728 | } |
| 710 | continue; | 729 | continue; |
| 711 | }, | 730 | }, |
| | 731 | |
| 712 | State.ContainerDecl => |container_decl| { | 732 | State.ContainerDecl => |container_decl| { |
| 713 | while (try self.eatLineComment(arena)) |line_comment| { | 733 | while (try self.eatLineComment(arena)) |line_comment| { |
| 714 | try container_decl.fields_and_decls.append(&line_comment.base); | 734 | try container_decl.fields_and_decls.append(&line_comment.base); |
| ... | @@ -744,10 +764,12 @@ pub const Parser = struct { | ... | @@ -744,10 +764,12 @@ pub const Parser = struct { |
| 744 | .base = undefined, | 764 | .base = undefined, |
| 745 | .name_token = token, | 765 | .name_token = token, |
| 746 | .type_expr = null, | 766 | .type_expr = null, |
| | 767 | .value_expr = null, |
| 747 | } | 768 | } |
| 748 | ); | 769 | ); |
| 749 | | 770 | |
| 750 | stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable; | 771 | stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable; |
| | 772 | try stack.append(State { .FieldInitValue = OptionalCtx { .RequiredNull = &node.value_expr } }); |
| 751 | try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &node.type_expr } }); | 773 | try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &node.type_expr } }); |
| 752 | try stack.append(State { .IfToken = Token.Id.Colon }); | 774 | try stack.append(State { .IfToken = Token.Id.Colon }); |
| 753 | continue; | 775 | continue; |
| ... | @@ -3515,6 +3537,12 @@ pub const Parser = struct { | ... | @@ -3515,6 +3537,12 @@ pub const Parser = struct { |
| 3515 | try stream.print("{}", self.tokenizer.getTokenSlice(tag.name_token)); | 3537 | try stream.print("{}", self.tokenizer.getTokenSlice(tag.name_token)); |
| 3516 | | 3538 | |
| 3517 | try stack.append(RenderState { .Text = "," }); | 3539 | try stack.append(RenderState { .Text = "," }); |
| | 3540 | |
| | 3541 | if (tag.value_expr) |value_expr| { |
| | 3542 | try stack.append(RenderState { .Expression = value_expr }); |
| | 3543 | try stack.append(RenderState { .Text = " = " }); |
| | 3544 | } |
| | 3545 | |
| 3518 | if (tag.type_expr) |type_expr| { | 3546 | if (tag.type_expr) |type_expr| { |
| 3519 | try stream.print(": "); | 3547 | try stream.print(": "); |
| 3520 | try stack.append(RenderState { .Expression = type_expr}); | 3548 | try stack.append(RenderState { .Expression = type_expr}); |
| ... | @@ -4055,7 +4083,15 @@ pub const Parser = struct { | ... | @@ -4055,7 +4083,15 @@ pub const Parser = struct { |
| 4055 | | 4083 | |
| 4056 | switch (container_decl.init_arg_expr) { | 4084 | switch (container_decl.init_arg_expr) { |
| 4057 | ast.Node.ContainerDecl.InitArg.None => try stack.append(RenderState { .Text = " "}), | 4085 | ast.Node.ContainerDecl.InitArg.None => try stack.append(RenderState { .Text = " "}), |
| 4058 | ast.Node.ContainerDecl.InitArg.Enum => try stack.append(RenderState { .Text = "(enum) "}), | 4086 | ast.Node.ContainerDecl.InitArg.Enum => |enum_tag_type| { |
| | 4087 | if (enum_tag_type) |expr| { |
| | 4088 | try stack.append(RenderState { .Text = ")) "}); |
| | 4089 | try stack.append(RenderState { .Expression = expr}); |
| | 4090 | try stack.append(RenderState { .Text = "(enum("}); |
| | 4091 | } else { |
| | 4092 | try stack.append(RenderState { .Text = "(enum) "}); |
| | 4093 | } |
| | 4094 | }, |
| 4059 | ast.Node.ContainerDecl.InitArg.Type => |type_expr| { | 4095 | ast.Node.ContainerDecl.InitArg.Type => |type_expr| { |
| 4060 | try stack.append(RenderState { .Text = ") "}); | 4096 | try stack.append(RenderState { .Text = ") "}); |
| 4061 | try stack.append(RenderState { .Expression = type_expr}); | 4097 | try stack.append(RenderState { .Expression = type_expr}); |