@@ -643,11 +643,23 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {
643643 n = datas [n ].lhs ;
644644 }
645645 },
646+ .switch_case_inline_one = > {
647+ if (datas [n ].lhs == 0 ) {
648+ return main_tokens [n ] - 2 - end_offset ; // else token
649+ } else {
650+ return firstToken (tree , datas [n ].lhs ) - 1 ;
651+ }
652+ },
646653 .switch_case = > {
647654 const extra = tree .extraData (datas [n ].lhs , Node .SubRange );
648655 assert (extra .end - extra .start > 0 );
649656 n = tree .extra_data [extra .start ];
650657 },
658+ .switch_case_inline = > {
659+ const extra = tree .extraData (datas [n ].lhs , Node .SubRange );
660+ assert (extra .end - extra .start > 0 );
661+ return firstToken (tree , tree .extra_data [extra .start ]) - 1 ;
662+ },
651663
652664 .asm_output , .asm_input = > {
653665 assert (token_tags [main_tokens [n ] - 1 ] == .l_bracket );
@@ -763,7 +775,9 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
763775 .ptr_type_bit_range ,
764776 .array_type ,
765777 .switch_case_one ,
778+ .switch_case_inline_one ,
766779 .switch_case ,
780+ .switch_case_inline ,
767781 .switch_range ,
768782 = > n = datas [n ].rhs ,
769783
@@ -1755,7 +1769,7 @@ pub fn switchCaseOne(tree: Ast, node: Node.Index) full.SwitchCase {
17551769 .values = if (data .lhs == 0 ) values [0.. 0] else values [0.. 1],
17561770 .arrow_token = tree .nodes .items (.main_token )[node ],
17571771 .target_expr = data .rhs ,
1758- });
1772+ }, node );
17591773}
17601774
17611775pub fn switchCase (tree : Ast , node : Node.Index ) full.SwitchCase {
@@ -1765,7 +1779,7 @@ pub fn switchCase(tree: Ast, node: Node.Index) full.SwitchCase {
17651779 .values = tree .extra_data [extra .start .. extra .end ],
17661780 .arrow_token = tree .nodes .items (.main_token )[node ],
17671781 .target_expr = data .rhs ,
1768- });
1782+ }, node );
17691783}
17701784
17711785pub fn asmSimple (tree : Ast , node : Node.Index ) full.Asm {
@@ -2038,15 +2052,21 @@ fn fullContainerDecl(tree: Ast, info: full.ContainerDecl.Components) full.Contai
20382052 return result ;
20392053}
20402054
2041- fn fullSwitchCase (tree : Ast , info : full.SwitchCase.Components ) full.SwitchCase {
2055+ fn fullSwitchCase (tree : Ast , info : full.SwitchCase.Components , node : Node.Index ) full.SwitchCase {
20422056 const token_tags = tree .tokens .items (.tag );
2057+ const node_tags = tree .nodes .items (.tag );
20432058 var result : full.SwitchCase = .{
20442059 .ast = info ,
20452060 .payload_token = null ,
2061+ .inline_token = null ,
20462062 };
20472063 if (token_tags [info .arrow_token + 1 ] == .pipe ) {
20482064 result .payload_token = info .arrow_token + 2 ;
20492065 }
2066+ switch (node_tags [node ]) {
2067+ .switch_case_inline , .switch_case_inline_one = > result .inline_token = firstToken (tree , node ),
2068+ else = > {},
2069+ }
20502070 return result ;
20512071}
20522072
@@ -2454,6 +2474,7 @@ pub const full = struct {
24542474 };
24552475
24562476 pub const SwitchCase = struct {
2477+ inline_token : ? TokenIndex ,
24572478 /// Points to the first token after the `|`. Will either be an identifier or
24582479 /// a `*` (with an identifier immediately after it).
24592480 payload_token : ? TokenIndex ,
@@ -2847,9 +2868,13 @@ pub const Node = struct {
28472868 /// `lhs => rhs`. If lhs is omitted it means `else`.
28482869 /// main_token is the `=>`
28492870 switch_case_one ,
2871+ /// Same ast `switch_case_one` but the case is inline
2872+ switch_case_inline_one ,
28502873 /// `a, b, c => rhs`. `SubRange[lhs]`.
28512874 /// main_token is the `=>`
28522875 switch_case ,
2876+ /// Same ast `switch_case` but the case is inline
2877+ switch_case_inline ,
28532878 /// `lhs...rhs`.
28542879 switch_range ,
28552880 /// `while (lhs) rhs`.
0 commit comments