authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-04-08 17:05:08+02:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-04-08 17:05:08+02:00
loge4d0b46c0c07f3151b4959c5e2e0d4c304981ead
tree881f8a0f7da63c5486a8851c9029e210fc4ea2e2
parentbdff5bfa3e9f6ab490771b54109cb200b180b4da

std.zig.parser WIP generalizing parsing of payloads

* Note, it doesn't work :)

2 files changed, 161 insertions(+), 51 deletions(-)

std/zig/ast.zig+98-10
...@@ -20,9 +20,11 @@ pub const Node = struct {...@@ -20,9 +20,11 @@ pub const Node = struct {
20 FnProto,20 FnProto,
21 ParamDecl,21 ParamDecl,
22 Block,22 Block,
23 Payload,
23 Switch,24 Switch,
24 SwitchCase,25 SwitchCase,
25 SwitchElse,26 SwitchElse,
27 While,
26 InfixOp,28 InfixOp,
27 PrefixOp,29 PrefixOp,
28 SuffixOp,30 SuffixOp,
...@@ -58,9 +60,11 @@ pub const Node = struct {...@@ -58,9 +60,11 @@ pub const Node = struct {
58 Id.FnProto => @fieldParentPtr(NodeFnProto, "base", base).iterate(index),60 Id.FnProto => @fieldParentPtr(NodeFnProto, "base", base).iterate(index),
59 Id.ParamDecl => @fieldParentPtr(NodeParamDecl, "base", base).iterate(index),61 Id.ParamDecl => @fieldParentPtr(NodeParamDecl, "base", base).iterate(index),
60 Id.Block => @fieldParentPtr(NodeBlock, "base", base).iterate(index),62 Id.Block => @fieldParentPtr(NodeBlock, "base", base).iterate(index),
63 Id.Payload => @fieldParentPtr(NodePayload, "base", base).iterate(index),
61 Id.Switch => @fieldParentPtr(NodeSwitch, "base", base).iterate(index),64 Id.Switch => @fieldParentPtr(NodeSwitch, "base", base).iterate(index),
62 Id.SwitchCase => @fieldParentPtr(NodeSwitchCase, "base", base).iterate(index),65 Id.SwitchCase => @fieldParentPtr(NodeSwitchCase, "base", base).iterate(index),
63 Id.SwitchElse => @fieldParentPtr(NodeSwitchElse, "base", base).iterate(index),66 Id.SwitchElse => @fieldParentPtr(NodeSwitchElse, "base", base).iterate(index),
67 Id.While => @fieldParentPtr(NodeWhile, "base", base).iterate(index),
64 Id.InfixOp => @fieldParentPtr(NodeInfixOp, "base", base).iterate(index),68 Id.InfixOp => @fieldParentPtr(NodeInfixOp, "base", base).iterate(index),
65 Id.PrefixOp => @fieldParentPtr(NodePrefixOp, "base", base).iterate(index),69 Id.PrefixOp => @fieldParentPtr(NodePrefixOp, "base", base).iterate(index),
66 Id.SuffixOp => @fieldParentPtr(NodeSuffixOp, "base", base).iterate(index),70 Id.SuffixOp => @fieldParentPtr(NodeSuffixOp, "base", base).iterate(index),
...@@ -97,9 +101,11 @@ pub const Node = struct {...@@ -97,9 +101,11 @@ pub const Node = struct {
97 Id.FnProto => @fieldParentPtr(NodeFnProto, "base", base).firstToken(),101 Id.FnProto => @fieldParentPtr(NodeFnProto, "base", base).firstToken(),
98 Id.ParamDecl => @fieldParentPtr(NodeParamDecl, "base", base).firstToken(),102 Id.ParamDecl => @fieldParentPtr(NodeParamDecl, "base", base).firstToken(),
99 Id.Block => @fieldParentPtr(NodeBlock, "base", base).firstToken(),103 Id.Block => @fieldParentPtr(NodeBlock, "base", base).firstToken(),
104 Id.Payload => @fieldParentPtr(NodePayload, "base", base).firstToken(),
100 Id.Switch => @fieldParentPtr(NodeSwitch, "base", base).firstToken(),105 Id.Switch => @fieldParentPtr(NodeSwitch, "base", base).firstToken(),
101 Id.SwitchCase => @fieldParentPtr(NodeSwitchCase, "base", base).firstToken(),106 Id.SwitchCase => @fieldParentPtr(NodeSwitchCase, "base", base).firstToken(),
102 Id.SwitchElse => @fieldParentPtr(NodeSwitchElse, "base", base).firstToken(),107 Id.SwitchElse => @fieldParentPtr(NodeSwitchElse, "base", base).firstToken(),
108 Id.While => @fieldParentPtr(NodeWhile, "base", base).firstToken(),
103 Id.InfixOp => @fieldParentPtr(NodeInfixOp, "base", base).firstToken(),109 Id.InfixOp => @fieldParentPtr(NodeInfixOp, "base", base).firstToken(),
104 Id.PrefixOp => @fieldParentPtr(NodePrefixOp, "base", base).firstToken(),110 Id.PrefixOp => @fieldParentPtr(NodePrefixOp, "base", base).firstToken(),
105 Id.SuffixOp => @fieldParentPtr(NodeSuffixOp, "base", base).firstToken(),111 Id.SuffixOp => @fieldParentPtr(NodeSuffixOp, "base", base).firstToken(),
...@@ -136,9 +142,11 @@ pub const Node = struct {...@@ -136,9 +142,11 @@ pub const Node = struct {
136 Id.FnProto => @fieldParentPtr(NodeFnProto, "base", base).lastToken(),142 Id.FnProto => @fieldParentPtr(NodeFnProto, "base", base).lastToken(),
137 Id.ParamDecl => @fieldParentPtr(NodeParamDecl, "base", base).lastToken(),143 Id.ParamDecl => @fieldParentPtr(NodeParamDecl, "base", base).lastToken(),
138 Id.Block => @fieldParentPtr(NodeBlock, "base", base).lastToken(),144 Id.Block => @fieldParentPtr(NodeBlock, "base", base).lastToken(),
145 Id.Payload => @fieldParentPtr(NodePayload, "base", base).lastToken(),
139 Id.Switch => @fieldParentPtr(NodeSwitch, "base", base).lastToken(),146 Id.Switch => @fieldParentPtr(NodeSwitch, "base", base).lastToken(),
140 Id.SwitchCase => @fieldParentPtr(NodeSwitchCase, "base", base).lastToken(),147 Id.SwitchCase => @fieldParentPtr(NodeSwitchCase, "base", base).lastToken(),
141 Id.SwitchElse => @fieldParentPtr(NodeSwitchElse, "base", base).firstToken(),148 Id.SwitchElse => @fieldParentPtr(NodeSwitchElse, "base", base).lastToken(),
149 Id.While => @fieldParentPtr(NodeWhile, "base", base).lastToken(),
142 Id.InfixOp => @fieldParentPtr(NodeInfixOp, "base", base).lastToken(),150 Id.InfixOp => @fieldParentPtr(NodeInfixOp, "base", base).lastToken(),
143 Id.PrefixOp => @fieldParentPtr(NodePrefixOp, "base", base).lastToken(),151 Id.PrefixOp => @fieldParentPtr(NodePrefixOp, "base", base).lastToken(),
144 Id.SuffixOp => @fieldParentPtr(NodeSuffixOp, "base", base).lastToken(),152 Id.SuffixOp => @fieldParentPtr(NodeSuffixOp, "base", base).lastToken(),
...@@ -545,6 +553,31 @@ pub const NodeBlock = struct {...@@ -545,6 +553,31 @@ pub const NodeBlock = struct {
545 }553 }
546};554};
547555
556pub const NodePayload = struct {
557 base: Node,
558 lpipe: Token,
559 is_ptr: bool,
560 symbol: &NodeIdentifier,
561 rpipe: Token,
562
563 pub fn iterate(self: &NodePayload, index: usize) ?&Node {
564 var i = index;
565
566 if (i < 1) return &self.symbol.base;
567 i -= 1;
568
569 return null;
570 }
571
572 pub fn firstToken(self: &NodePayload) Token {
573 return self.lpipe;
574 }
575
576 pub fn lastToken(self: &NodePayload) Token {
577 return self.rpipe;
578 }
579};
580
548pub const NodeSwitch = struct {581pub const NodeSwitch = struct {
549 base: Node,582 base: Node,
550 switch_token: Token,583 switch_token: Token,
...@@ -576,22 +609,17 @@ pub const NodeSwitch = struct {...@@ -576,22 +609,17 @@ pub const NodeSwitch = struct {
576pub const NodeSwitchCase = struct {609pub const NodeSwitchCase = struct {
577 base: Node,610 base: Node,
578 items: ArrayList(&Node),611 items: ArrayList(&Node),
579 capture: ?Capture,612 payload: ?&Node,
580 expr: &Node,613 expr: &Node,
581614
582 const Capture = struct {
583 symbol: &NodeIdentifier,
584 is_ptr: bool,
585 };
586
587 pub fn iterate(self: &NodeSwitchCase, index: usize) ?&Node {615 pub fn iterate(self: &NodeSwitchCase, index: usize) ?&Node {
588 var i = index;616 var i = index;
589617
590 if (i < self.items.len) return self.items.at(i);618 if (i < self.items.len) return self.items.at(i);
591 i -= self.items.len;619 i -= self.items.len;
592620
593 if (self.capture) |capture| {621 if (self.payload) |payload| {
594 if (i < 1) return &capture.base;622 if (i < 1) return payload;
595 i -= 1;623 i -= 1;
596 }624 }
597625
...@@ -627,6 +655,66 @@ pub const NodeSwitchElse = struct {...@@ -627,6 +655,66 @@ pub const NodeSwitchElse = struct {
627 }655 }
628};656};
629657
658pub const NodeWhile = struct {
659 base: Node,
660 while_token: Token,
661 condition: &Node,
662 payload: ?&NodePayload,
663 continue_expr: ?&Node,
664 body: &Node,
665 @"else": ?Else,
666
667 const Else = struct {
668 capture: ?&NodeIdentifier,
669 body: &Node,
670 };
671
672
673 pub fn iterate(self: &NodeWhile, index: usize) ?&Node {
674 var i = index;
675
676 if (i < 1) return self.condition;
677 i -= 1;
678
679 if (self.payload) |payload| {
680 if (i < 1) return &payload.base;
681 i -= 1;
682 }
683
684 if (self.continue_expr) |continue_expr| {
685 if (i < 1) return continue_expr;
686 i -= 1;
687 }
688
689 if (i < 1) return self.body;
690 i -= 1;
691
692 if (self.@"else") |@"else"| {
693 if (@"else".capture) |capture| {
694 if (i < 1) return &capture.base;
695 i -= 1;
696 }
697
698 if (i < 1) return @"else".body;
699 i -= 1;
700 }
701
702 return null;
703 }
704
705 pub fn firstToken(self: &NodeWhile) Token {
706 return self.while_token;
707 }
708
709 pub fn lastToken(self: &NodeWhile) Token {
710 if (self.@"else") |@"else"| {
711 return @"else".body.lastToken();
712 }
713
714 return self.body.lastToken();
715 }
716};
717
630pub const NodeInfixOp = struct {718pub const NodeInfixOp = struct {
631 base: Node,719 base: Node,
632 op_token: Token,720 op_token: Token,
...@@ -661,7 +749,7 @@ pub const NodeInfixOp = struct {...@@ -661,7 +749,7 @@ pub const NodeInfixOp = struct {
661 BitXor,749 BitXor,
662 BoolAnd,750 BoolAnd,
663 BoolOr,751 BoolOr,
664 Catch: ?&NodeIdentifier,752 Catch: ?&Node,
665 Div,753 Div,
666 EqualEqual,754 EqualEqual,
667 ErrorUnion,755 ErrorUnion,
std/zig/parser.zig+63-41
...@@ -104,6 +104,11 @@ pub const Parser = struct {...@@ -104,6 +104,11 @@ pub const Parser = struct {
104 ptr: &Token,104 ptr: &Token,
105 };105 };
106106
107 const ElseCtx = struct {
108 payload: ?DestPtr,
109 body: DestPtr,
110 };
111
107 fn ListSave(comptime T: type) type {112 fn ListSave(comptime T: type) type {
108 return struct {113 return struct {
109 list: &ArrayList(T),114 list: &ArrayList(T),
...@@ -140,7 +145,7 @@ pub const Parser = struct {...@@ -140,7 +145,7 @@ pub const Parser = struct {
140 FieldInitListCommaOrEnd: ListSave(&ast.NodeFieldInitializer),145 FieldInitListCommaOrEnd: ListSave(&ast.NodeFieldInitializer),
141 FieldListCommaOrEnd: &ast.NodeContainerDecl,146 FieldListCommaOrEnd: &ast.NodeContainerDecl,
142 SwitchCaseOrEnd: ListSave(&ast.NodeSwitchCase),147 SwitchCaseOrEnd: ListSave(&ast.NodeSwitchCase),
143 SwitchCaseCapture: &?ast.NodeSwitchCase.Capture,148 Payload: DestPtr,
144 SwitchCaseCommaOrEnd: ListSave(&ast.NodeSwitchCase),149 SwitchCaseCommaOrEnd: ListSave(&ast.NodeSwitchCase),
145 SwitchCaseItem: &ArrayList(&ast.Node),150 SwitchCaseItem: &ArrayList(&ast.Node),
146 SwitchCaseItemCommaOrEnd: &ArrayList(&ast.Node),151 SwitchCaseItemCommaOrEnd: &ArrayList(&ast.Node),
...@@ -635,9 +640,6 @@ pub const Parser = struct {...@@ -635,9 +640,6 @@ pub const Parser = struct {
635 Token.Id.Keyword_await => {640 Token.Id.Keyword_await => {
636 @panic("TODO: await");641 @panic("TODO: await");
637 },642 },
638 Token.Id.Keyword_suspend => {
639 @panic("TODO: suspend");
640 },
641 else => {643 else => {
642 self.putBackToken(token);644 self.putBackToken(token);
643 stack.append(State { .AssignmentExpressionBegin = dest_ptr }) catch unreachable;645 stack.append(State { .AssignmentExpressionBegin = dest_ptr }) catch unreachable;
...@@ -705,21 +707,14 @@ pub const Parser = struct {...@@ -705,21 +707,14 @@ pub const Parser = struct {
705707
706 stack.append(State { .UnwrapExpressionEnd = dest_ptr }) catch unreachable;708 stack.append(State { .UnwrapExpressionEnd = dest_ptr }) catch unreachable;
707 try stack.append(State { .Expression = DestPtr { .Field = &node.rhs } });709 try stack.append(State { .Expression = DestPtr { .Field = &node.rhs } });
708
709 const next = self.getNextToken();
710 if (next.id != Token.Id.Pipe) {
711 self.putBackToken(next);
712 continue;
713 }
714
715 node.op.Catch = try self.createIdentifier(arena, Token(undefined));
716 try stack.append(State { .ExpectToken = Token.Id.Pipe });
717 try stack.append(State {710 try stack.append(State {
718 .ExpectTokenSave = ExpectTokenSave {711 .Optional = RevertState {
719 .id = Token.Id.Identifier,712 .tokenizer = *self.tokenizer,
720 .ptr = &(??node.op.Catch).name_token713 .parser = *self,
714 .ptr = &node.op.Catch,
721 }715 }
722 });716 });
717 try stack.append(State { .Payload = DestPtr { .NullableField = &node.op.Catch } });
723 continue;718 continue;
724 },719 },
725 Token.Id.QuestionMarkQuestionMark => {720 Token.Id.QuestionMarkQuestionMark => {
...@@ -1404,12 +1399,25 @@ pub const Parser = struct {...@@ -1404,12 +1399,25 @@ pub const Parser = struct {
1404 @panic("TODO: inline if");1399 @panic("TODO: inline if");
1405 },1400 },
1406 Token.Id.Keyword_while => {1401 Token.Id.Keyword_while => {
1402 const node = try arena.create(ast.NodeWhile);
1403 *node = ast.NodeWhile {
1404 .base = self.initNode(ast.Node.Id.While),
1405 .while_token = token,
1406 .condition = undefined,
1407 .payload = null,
1408 .continue_expr = null,
1409 .body = undefined,
1410 .@"else" = null,
1411 };
1412 dest_ptr.store(&node.base);
1413
1407 @panic("TODO: inline while");1414 @panic("TODO: inline while");
1408 },1415 },
1409 Token.Id.Keyword_for => {1416 Token.Id.Keyword_for => {
1410 @panic("TODO: inline for");1417 @panic("TODO: inline for");
1411 },1418 },
1412 Token.Id.Keyword_switch => {1419 Token.Id.Keyword_switch => {
1420 @breakpoint();
1413 const node = try arena.create(ast.NodeSwitch);1421 const node = try arena.create(ast.NodeSwitch);
1414 *node = ast.NodeSwitch {1422 *node = ast.NodeSwitch {
1415 .base = self.initNode(ast.Node.Id.Switch),1423 .base = self.initNode(ast.Node.Id.Switch),
...@@ -1434,9 +1442,6 @@ pub const Parser = struct {...@@ -1434,9 +1442,6 @@ pub const Parser = struct {
1434 Token.Id.Keyword_comptime => {1442 Token.Id.Keyword_comptime => {
1435 @panic("TODO: inline comptime");1443 @panic("TODO: inline comptime");
1436 },1444 },
1437 Token.Id.Keyword_suspend => {
1438 @panic("TODO: inline suspend");
1439 },
1440 else => {1445 else => {
1441 try self.parseError(&stack, token, "expected primary expression, found {}", @tagName(token.id));1446 try self.parseError(&stack, token, "expected primary expression, found {}", @tagName(token.id));
1442 continue;1447 continue;
...@@ -1547,13 +1552,21 @@ pub const Parser = struct {...@@ -1547,13 +1552,21 @@ pub const Parser = struct {
1547 *node = ast.NodeSwitchCase {1552 *node = ast.NodeSwitchCase {
1548 .base = self.initNode(ast.Node.Id.SwitchCase),1553 .base = self.initNode(ast.Node.Id.SwitchCase),
1549 .items = ArrayList(&ast.Node).init(arena),1554 .items = ArrayList(&ast.Node).init(arena),
1550 .capture = null,1555 .payload = null,
1551 .expr = undefined,1556 .expr = undefined,
1552 };1557 };
1553 try list_state.list.append(node);1558 try list_state.list.append(node);
1554 stack.append(State { .SwitchCaseCommaOrEnd = list_state }) catch unreachable;1559 stack.append(State { .SwitchCaseCommaOrEnd = list_state }) catch unreachable;
1555 try stack.append(State { .Expression = DestPtr{ .Field = &node.expr } });1560 try stack.append(State { .Expression = DestPtr{ .Field = &node.expr } });
1556 try stack.append(State { .SwitchCaseCapture = &node.capture });1561 try stack.append(State {
1562 .Optional = RevertState {
1563 .tokenizer = *self.tokenizer,
1564 .parser = *self,
1565 .ptr = &node.payload,
1566 }
1567 });
1568 try stack.append(State { .Payload = DestPtr { .NullableField = &node.payload } });
1569 try stack.append(State.Required);
15571570
1558 const maybe_else = self.getNextToken();1571 const maybe_else = self.getNextToken();
1559 if (maybe_else.id == Token.Id.Keyword_else) {1572 if (maybe_else.id == Token.Id.Keyword_else) {
...@@ -1572,12 +1585,8 @@ pub const Parser = struct {...@@ -1572,12 +1585,8 @@ pub const Parser = struct {
1572 }1585 }
1573 },1586 },
15741587
1575 State.SwitchCaseCapture => |capture| {1588 State.Payload => |dest_ptr| {
1576 const token = self.getNextToken();1589 const lpipe = (try self.eatToken(&stack, Token.Id.Pipe)) ?? continue;
1577 if (token.id != Token.Id.Pipe) {
1578 self.putBackToken(token);
1579 continue;
1580 }
15811590
1582 const is_ptr = blk: {1591 const is_ptr = blk: {
1583 const asterik = self.getNextToken();1592 const asterik = self.getNextToken();
...@@ -1590,11 +1599,16 @@ pub const Parser = struct {...@@ -1590,11 +1599,16 @@ pub const Parser = struct {
1590 };1599 };
15911600
1592 const ident = (try self.eatToken(&stack, Token.Id.Identifier)) ?? continue;1601 const ident = (try self.eatToken(&stack, Token.Id.Identifier)) ?? continue;
1593 _ = (try self.eatToken(&stack, Token.Id.Pipe)) ?? continue;1602 const rpipe = (try self.eatToken(&stack, Token.Id.Pipe)) ?? continue;
1594 *capture = ast.NodeSwitchCase.Capture {1603 const node = try arena.create(ast.NodePayload);
1604 *node = ast.NodePayload {
1605 .base = self.initNode(ast.Node.Id.Payload),
1606 .lpipe = lpipe,
1607 .is_ptr = is_ptr,
1595 .symbol = try self.createIdentifier(arena, ident),1608 .symbol = try self.createIdentifier(arena, ident),
1596 .is_ptr = is_ptr1609 .rpipe = rpipe
1597 };1610 };
1611 dest_ptr.store(&node.base);
1598 },1612 },
15991613
1600 State.SwitchCaseItem => |case_items| {1614 State.SwitchCaseItem => |case_items| {
...@@ -1856,6 +1870,8 @@ pub const Parser = struct {...@@ -1856,6 +1870,8 @@ pub const Parser = struct {
1856 stack.append(State { .Block = inner_block }) catch unreachable;1870 stack.append(State { .Block = inner_block }) catch unreachable;
1857 continue;1871 continue;
1858 },1872 },
1873 Token.Id.Keyword_suspend, Token.Id.Keyword_if,
1874 Token.Id.Keyword_while, Token.Id.Keyword_for,
1859 Token.Id.Keyword_switch => {1875 Token.Id.Keyword_switch => {
1860 self.putBackToken(next);1876 self.putBackToken(next);
1861 stack.append(State { .Expression = DestPtr{.Field = try block.statements.addOne() } }) catch unreachable;1877 stack.append(State { .Expression = DestPtr{.Field = try block.statements.addOne() } }) catch unreachable;
...@@ -2572,9 +2588,8 @@ pub const Parser = struct {...@@ -2572,9 +2588,8 @@ pub const Parser = struct {
25722588
2573 if (prefix_op_node.op == ast.NodeInfixOp.InfixOp.Catch) {2589 if (prefix_op_node.op == ast.NodeInfixOp.InfixOp.Catch) {
2574 if (prefix_op_node.op.Catch) |payload| {2590 if (prefix_op_node.op.Catch) |payload| {
2575 try stack.append(RenderState { .Text = "| " });2591 try stack.append(RenderState { .Text = " " });
2576 try stack.append(RenderState { .Expression = &payload.base });2592 try stack.append(RenderState { .Expression = payload });
2577 try stack.append(RenderState { .Text = "|" });
2578 }2593 }
2579 try stack.append(RenderState { .Text = " catch " });2594 try stack.append(RenderState { .Text = " catch " });
2580 } else {2595 } else {
...@@ -2764,6 +2779,17 @@ pub const Parser = struct {...@@ -2764,6 +2779,17 @@ pub const Parser = struct {
2764 try stack.append(RenderState { .Expression = rhs });2779 try stack.append(RenderState { .Expression = rhs });
2765 }2780 }
2766 },2781 },
2782 ast.Node.Id.Payload => {
2783 const payload = @fieldParentPtr(ast.NodePayload, "base", base);
2784 try stack.append(RenderState { .Text = "|"});
2785 try stack.append(RenderState { .Expression = &payload.symbol.base });
2786
2787 if (payload.is_ptr) {
2788 try stack.append(RenderState { .Text = "*"});
2789 }
2790
2791 try stack.append(RenderState { .Text = "|"});
2792 },
2767 ast.Node.Id.GroupedExpression => {2793 ast.Node.Id.GroupedExpression => {
2768 const grouped_expr = @fieldParentPtr(ast.NodeGroupedExpression, "base", base);2794 const grouped_expr = @fieldParentPtr(ast.NodeGroupedExpression, "base", base);
2769 try stack.append(RenderState { .Text = ")"});2795 try stack.append(RenderState { .Text = ")"});
...@@ -2985,14 +3011,9 @@ pub const Parser = struct {...@@ -2985,14 +3011,9 @@ pub const Parser = struct {
2985 const switch_case = @fieldParentPtr(ast.NodeSwitchCase, "base", base);3011 const switch_case = @fieldParentPtr(ast.NodeSwitchCase, "base", base);
29863012
2987 try stack.append(RenderState { .Expression = switch_case.expr });3013 try stack.append(RenderState { .Expression = switch_case.expr });
2988 if (switch_case.capture) |capture| {3014 if (switch_case.payload) |payload| {
2989 try stack.append(RenderState { .Text = "| "});3015 try stack.append(RenderState { .Text = " " });
2990 try stack.append(RenderState { .Expression = &capture.symbol.base });3016 try stack.append(RenderState { .Expression = payload });
2991
2992 if (capture.is_ptr) {
2993 try stack.append(RenderState { .Text = "*"});
2994 }
2995 try stack.append(RenderState { .Text = "|"});
2996 }3017 }
2997 try stack.append(RenderState { .Text = " => "});3018 try stack.append(RenderState { .Text = " => "});
29983019
...@@ -3011,6 +3032,7 @@ pub const Parser = struct {...@@ -3011,6 +3032,7 @@ pub const Parser = struct {
3011 const switch_else = @fieldParentPtr(ast.NodeSwitchElse, "base", base);3032 const switch_else = @fieldParentPtr(ast.NodeSwitchElse, "base", base);
3012 try stream.print("{}", self.tokenizer.getTokenSlice(switch_else.token));3033 try stream.print("{}", self.tokenizer.getTokenSlice(switch_else.token));
3013 },3034 },
3035 ast.Node.Id.While => @panic("TODO: Render while"),
30143036
3015 ast.Node.Id.StructField,3037 ast.Node.Id.StructField,
3016 ast.Node.Id.UnionTag,3038 ast.Node.Id.UnionTag,