| ... | @@ -693,39 +693,27 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -693,39 +693,27 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 693 | return renderToken(r, datas[node].rhs, space); | 693 | return renderToken(r, datas[node].rhs, space); |
| 694 | }, | 694 | }, |
| 695 | | 695 | |
| 696 | .@"break" => { | 696 | .@"break", .@"continue" => { |
| 697 | const main_token = main_tokens[node]; | 697 | const main_token = main_tokens[node]; |
| 698 | const label_token = datas[node].lhs; | 698 | const label_token = datas[node].lhs; |
| 699 | const target = datas[node].rhs; | 699 | const target = datas[node].rhs; |
| 700 | if (label_token == 0 and target == 0) { | 700 | if (label_token == 0 and target == 0) { |
| 701 | try renderToken(r, main_token, space); // break keyword | 701 | try renderToken(r, main_token, space); // break/continue |
| 702 | } else if (label_token == 0 and target != 0) { | 702 | } else if (label_token == 0 and target != 0) { |
| 703 | try renderToken(r, main_token, .space); // break keyword | 703 | try renderToken(r, main_token, .space); // break/continue |
| 704 | try renderExpression(r, target, space); | 704 | try renderExpression(r, target, space); |
| 705 | } else if (label_token != 0 and target == 0) { | 705 | } else if (label_token != 0 and target == 0) { |
| 706 | try renderToken(r, main_token, .space); // break keyword | 706 | try renderToken(r, main_token, .space); // break/continue |
| 707 | try renderToken(r, label_token - 1, .none); // colon | 707 | try renderToken(r, label_token - 1, .none); // : |
| 708 | try renderIdentifier(r, label_token, space, .eagerly_unquote); // identifier | 708 | try renderIdentifier(r, label_token, space, .eagerly_unquote); // identifier |
| 709 | } else if (label_token != 0 and target != 0) { | 709 | } else if (label_token != 0 and target != 0) { |
| 710 | try renderToken(r, main_token, .space); // break keyword | 710 | try renderToken(r, main_token, .space); // break/continue |
| 711 | try renderToken(r, label_token - 1, .none); // colon | 711 | try renderToken(r, label_token - 1, .none); // : |
| 712 | try renderIdentifier(r, label_token, .space, .eagerly_unquote); // identifier | 712 | try renderIdentifier(r, label_token, .space, .eagerly_unquote); // identifier |
| 713 | try renderExpression(r, target, space); | 713 | try renderExpression(r, target, space); |
| 714 | } | 714 | } |
| 715 | }, | 715 | }, |
| 716 | | 716 | |
| 717 | .@"continue" => { | | |
| 718 | const main_token = main_tokens[node]; | | |
| 719 | const label = datas[node].lhs; | | |
| 720 | if (label != 0) { | | |
| 721 | try renderToken(r, main_token, .space); // continue | | |
| 722 | try renderToken(r, label - 1, .none); // : | | |
| 723 | return renderIdentifier(r, label, space, .eagerly_unquote); // label | | |
| 724 | } else { | | |
| 725 | return renderToken(r, main_token, space); // continue | | |
| 726 | } | | |
| 727 | }, | | |
| 728 | | | |
| 729 | .@"return" => { | 717 | .@"return" => { |
| 730 | if (datas[node].lhs != 0) { | 718 | if (datas[node].lhs != 0) { |
| 731 | try renderToken(r, main_tokens[node], .space); | 719 | try renderToken(r, main_tokens[node], .space); |
| ... | @@ -845,26 +833,29 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -845,26 +833,29 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 845 | .@"switch", | 833 | .@"switch", |
| 846 | .switch_comma, | 834 | .switch_comma, |
| 847 | => { | 835 | => { |
| 848 | const switch_token = main_tokens[node]; | 836 | const full = tree.switchFull(node); |
| 849 | const condition = datas[node].lhs; | | |
| 850 | const extra = tree.extraData(datas[node].rhs, Ast.Node.SubRange); | | |
| 851 | const cases = tree.extra_data[extra.start..extra.end]; | | |
| 852 | const rparen = tree.lastToken(condition) + 1; | | |
| 853 | | 837 | |
| 854 | try renderToken(r, switch_token, .space); // switch keyword | 838 | if (full.label_token) |label_token| { |
| 855 | try renderToken(r, switch_token + 1, .none); // lparen | 839 | try renderIdentifier(r, label_token, .none, .eagerly_unquote); // label |
| 856 | try renderExpression(r, condition, .none); // condition expression | 840 | try renderToken(r, label_token + 1, .space); // : |
| 857 | try renderToken(r, rparen, .space); // rparen | 841 | } |
| | 842 | |
| | 843 | const rparen = tree.lastToken(full.ast.condition) + 1; |
| | 844 | |
| | 845 | try renderToken(r, full.ast.switch_token, .space); // switch |
| | 846 | try renderToken(r, full.ast.switch_token + 1, .none); // ( |
| | 847 | try renderExpression(r, full.ast.condition, .none); // condition expression |
| | 848 | try renderToken(r, rparen, .space); // ) |
| 858 | | 849 | |
| 859 | ais.pushIndentNextLine(); | 850 | ais.pushIndentNextLine(); |
| 860 | if (cases.len == 0) { | 851 | if (full.ast.cases.len == 0) { |
| 861 | try renderToken(r, rparen + 1, .none); // lbrace | 852 | try renderToken(r, rparen + 1, .none); // { |
| 862 | } else { | 853 | } else { |
| 863 | try renderToken(r, rparen + 1, .newline); // lbrace | 854 | try renderToken(r, rparen + 1, .newline); // { |
| 864 | try renderExpressions(r, cases, .comma); | 855 | try renderExpressions(r, full.ast.cases, .comma); |
| 865 | } | 856 | } |
| 866 | ais.popIndent(); | 857 | ais.popIndent(); |
| 867 | return renderToken(r, tree.lastToken(node), space); // rbrace | 858 | return renderToken(r, tree.lastToken(node), space); // } |
| 868 | }, | 859 | }, |
| 869 | | 860 | |
| 870 | .switch_case_one, | 861 | .switch_case_one, |