| 9 | } |
| 10 | |
| 11 | void SpaceAnalyzer::Analyze(FormatState &f, const LuaSyntaxTree &t) { |
| 12 | for (auto syntaxNode: t.GetSyntaxNodes()) { |
| 13 | if (syntaxNode.IsToken(t)) { |
| 14 | switch (syntaxNode.GetTokenKind(t)) { |
| 15 | // math operator |
| 16 | case '+': |
| 17 | case '*': |
| 18 | case '/': |
| 19 | case '%': |
| 20 | case '&': |
| 21 | case TK_SHL: |
| 22 | case TK_SHR: |
| 23 | case TK_IDIV: { |
| 24 | SpaceAround(syntaxNode, t, f.GetStyle().space_around_math_operator.other ? 1 : 0); |
| 25 | break; |
| 26 | } |
| 27 | case '^': { |
| 28 | SpaceAround(syntaxNode, t, f.GetStyle().space_around_math_operator.exponent ? 1 : 0); |
| 29 | break; |
| 30 | } |
| 31 | case TK_CONCAT: { |
| 32 | switch (f.GetStyle().space_around_concat_operator) { |
| 33 | case SpaceAroundStyle::Always: { |
| 34 | SpaceAround(syntaxNode, t, 1); |
| 35 | break; |
| 36 | } |
| 37 | case SpaceAroundStyle::None: { |
| 38 | if (syntaxNode.GetPrevToken(t).GetTokenKind(t) == TK_NUMBER) { |
| 39 | SpaceAround(syntaxNode, t, 1); |
| 40 | } else { |
| 41 | SpaceAround(syntaxNode, t, 0); |
| 42 | } |
| 43 | break; |
| 44 | } |
| 45 | case SpaceAroundStyle::NoSpaceAsym: { |
| 46 | if (syntaxNode.GetPrevToken(t).GetTokenKind(t) == TK_NUMBER) { |
| 47 | SpaceLeft(syntaxNode, t, 1); |
| 48 | SpaceRight(syntaxNode, t, 0); |
| 49 | } else { |
| 50 | SpaceAround(syntaxNode, t, 0); |
| 51 | } |
| 52 | break; |
| 53 | } |
| 54 | default: { |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | break; |
| 59 | } |
| 60 | case '=': { |
| 61 | switch (f.GetStyle().space_around_assign_operator) { |
| 62 | case SpaceAroundStyle::Always: { |
| 63 | SpaceAround(syntaxNode, t, 1); |
| 64 | break; |
| 65 | } |
| 66 | case SpaceAroundStyle::None: { |
| 67 | if (syntaxNode.GetPrevToken(t).GetTokenKind(t) == '>') { |
| 68 | SpaceAround(syntaxNode, t, 1); |
nothing calls this directly
no test coverage detected