MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / Analyze

Method Analyze

CodeFormatCore/src/Format/Analyzer/SpaceAnalyzer.cpp:11–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11void 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);

Callers

nothing calls this directly

Calls 13

GetStyleMethod · 0.80
GetSyntaxKindMethod · 0.80
GetEndLineMethod · 0.80
GetStartLineMethod · 0.80
GetStartColMethod · 0.80
GetEndColMethod · 0.80
IsTokenMethod · 0.45
GetTokenKindMethod · 0.45
GetPrevTokenMethod · 0.45
GetParentMethod · 0.45
IsNodeMethod · 0.45
GetNextSiblingMethod · 0.45

Tested by

no test coverage detected