@@ -64,24 +64,33 @@ void TokenAnalyzer::Analyze(FormatState &f, const LuaSyntaxTree &t) {
6464
6565void TokenAnalyzer::Query (FormatState &f, LuaSyntaxNode syntaxNode, const LuaSyntaxTree &t, FormatResolve &resolve) {
6666 if (syntaxNode.IsToken (t)) {
67+ auto itPrev = _prevTokenStrategies.find (syntaxNode.GetIndex ());
68+ if (itPrev != _prevTokenStrategies.end ()) {
69+ resolve.SetPrevTokenStrategy (itPrev->second );
70+ }
71+
6772 auto it = _tokenStrategies.find (syntaxNode.GetIndex ());
6873 if (it != _tokenStrategies.end ()) {
6974 resolve.SetTokenStrategy (it->second );
7075 }
7176
72- auto it2 = _tokenAddStrategies .find (syntaxNode.GetIndex ());
73- if (it2 != _tokenAddStrategies .end ()) {
74- resolve.SetTokenAddStrategy (it2 ->second );
77+ auto itNext = _nextTokenStrategies .find (syntaxNode.GetIndex ());
78+ if (itNext != _nextTokenStrategies .end ()) {
79+ resolve.SetNextTokenStrategy (itNext ->second );
7580 }
7681 }
7782}
7883
84+ void TokenAnalyzer::MarkPrev (LuaSyntaxNode n, const LuaSyntaxTree &t, PrevTokenStrategy strategy) {
85+ _prevTokenStrategies[n.GetIndex ()] = strategy;
86+ }
87+
7988void TokenAnalyzer::Mark (LuaSyntaxNode n, const LuaSyntaxTree &t, TokenStrategy strategy) {
8089 _tokenStrategies[n.GetIndex ()] = strategy;
8190}
8291
83- void TokenAnalyzer::MarkAdd (LuaSyntaxNode n, const LuaSyntaxTree &t, TokenAddStrategy strategy) {
84- _tokenAddStrategies [n.GetIndex ()] = strategy;
92+ void TokenAnalyzer::MarkNext (LuaSyntaxNode n, const LuaSyntaxTree &t, NextTokenStrategy strategy) {
93+ _nextTokenStrategies [n.GetIndex ()] = strategy;
8594}
8695
8796bool TokenAnalyzer::IsRemove (LuaSyntaxNode n, const LuaSyntaxTree &t) const {
@@ -101,16 +110,16 @@ void TokenAnalyzer::TableFieldAddSep(FormatState &f, LuaSyntaxNode n, const LuaS
101110 }
102111 switch (f.GetStyle ().table_separator_style ) {
103112 case TableSeparatorStyle::Semicolon: {
104- return MarkAdd (lastToken, t, TokenAddStrategy ::TableAddColon);
113+ return MarkNext (lastToken, t, NextTokenStrategy ::TableAddColon);
105114 }
106115 case TableSeparatorStyle::OnlyKVColon: {
107116 if (n.GetChildToken (' =' , t).IsToken (t)) {
108- return MarkAdd (lastToken, t, TokenAddStrategy ::TableAddColon);
117+ return MarkNext (lastToken, t, NextTokenStrategy ::TableAddColon);
109118 }
110119 // fallthrough
111120 }
112121 default : {
113- return MarkAdd (lastToken, t, TokenAddStrategy ::TableAddComma);
122+ return MarkNext (lastToken, t, NextTokenStrategy ::TableAddComma);
114123 }
115124 }
116125 }
@@ -270,15 +279,18 @@ void TokenAnalyzer::AnalyzeCallExpression(FormatState &f, LuaSyntaxNode n, const
270279 if (!lbrace.IsToken (t) && spaceAnalyzer) {
271280 auto node = GetSingleArgStringOrTable (n, t);
272281 if (node.IsToken (t)) {
273- Mark (node, t, TokenStrategy::WithParentheses);
282+ MarkPrev (node, t, PrevTokenStrategy::LeftParentheses);
283+ MarkNext (node, t, NextTokenStrategy::RightParentheses);
274284 spaceAnalyzer->SpaceAround (node, t, 0 , SpaceAnalyzer::SpacePriority::First);
275285 } else if (node.GetSyntaxKind (t) == LuaSyntaxNodeKind::StringLiteralExpression) {
276- Mark (node.GetFirstToken (t), t, TokenStrategy::WithParentheses);
286+ auto firstToken = node.GetFirstToken (t);
287+ MarkPrev (firstToken, t, PrevTokenStrategy::LeftParentheses);
288+ MarkNext (firstToken, t, NextTokenStrategy::RightParentheses);
277289 spaceAnalyzer->SpaceLeft (node.GetFirstToken (t), t, 0 , SpaceAnalyzer::SpacePriority::First);
278290 } else {
279- Mark (node.GetFirstToken (t), t, TokenStrategy::WithLeftParentheses);
291+ MarkPrev (node.GetFirstToken (t), t, PrevTokenStrategy::LeftParentheses);
292+ MarkNext (node.GetLastToken (t), t, NextTokenStrategy::RightParentheses);
280293 spaceAnalyzer->SpaceLeft (node.GetFirstToken (t), t, 0 , SpaceAnalyzer::SpacePriority::First);
281- Mark (node.GetLastToken (t), t, TokenStrategy::WithRightParentheses);
282294 }
283295
284296 return ;
@@ -310,3 +322,5 @@ void TokenAnalyzer::AnalyzeComment(FormatState &f, LuaSyntaxNode n, const LuaSyn
310322 }
311323 }
312324}
325+
326+
0 commit comments