@@ -48,9 +48,10 @@ void SpaceAnalyzer::Analyze(FormatState &f, const LuaSyntaxTree &t) {
4848 case ' ~' : {
4949 auto p = syntaxNode.GetParent (t);
5050 if (p.IsNode (t) && p.GetSyntaxKind (t) == LuaSyntaxNodeKind::BinaryExpression) {
51- SpaceAround (syntaxNode, t);
51+ SpaceAround (syntaxNode, t, f. GetStyle (). space_around_math_operator ? 1 : 0 );
5252 } else {
5353 SpaceLeft (syntaxNode, t);
54+ SpaceRight (syntaxNode, t, 0 );
5455 }
5556 break ;
5657 }
@@ -304,28 +305,15 @@ void SpaceAnalyzer::SpaceAround(LuaSyntaxNode &n, const LuaSyntaxTree &t, std::s
304305}
305306
306307void SpaceAnalyzer::SpaceLeft (LuaSyntaxNode &n, const LuaSyntaxTree &t, std::size_t space) {
307- auto token = n.GetFirstToken (t);
308-
309- _leftSpaces[token.GetIndex ()] = space;
308+ auto token = n.GetPrevToken (t);
309+ _rightSpaces[token.GetIndex ()] = space;
310310}
311311
312312void SpaceAnalyzer::SpaceRight (LuaSyntaxNode &n, const LuaSyntaxTree &t, std::size_t space) {
313313 auto token = n.GetLastToken (t);
314314 _rightSpaces[token.GetIndex ()] = space;
315315}
316316
317- std::optional<std::size_t > SpaceAnalyzer::GetLeftSpace (LuaSyntaxNode &n) const {
318- if (_ignoreSpace.count (n.GetIndex ())) {
319- return {};
320- }
321-
322- auto it = _leftSpaces.find (n.GetIndex ());
323- if (it == _leftSpaces.end ()) {
324- return {};
325- }
326- return it->second ;
327- }
328-
329317std::optional<std::size_t > SpaceAnalyzer::GetRightSpace (LuaSyntaxNode &n) const {
330318 if (_ignoreSpace.count (n.GetIndex ())) {
331319 return {};
@@ -341,17 +329,8 @@ std::optional<std::size_t> SpaceAnalyzer::GetRightSpace(LuaSyntaxNode &n) const
341329std::size_t
342330SpaceAnalyzer::ProcessSpace (const LuaSyntaxTree &t, LuaSyntaxNode &left, LuaSyntaxNode &right) {
343331 auto rightSpaceOfLeftToken = GetRightSpace (left);
344- auto leftSpaceOfRightToken = GetLeftSpace (right);
345- std::optional<std::size_t > distance;
346- if (!rightSpaceOfLeftToken.has_value ()) {
347- distance = leftSpaceOfRightToken;
348- } else if (!leftSpaceOfRightToken.has_value ()) {
349- distance = rightSpaceOfLeftToken;
350- } else {
351- distance = leftSpaceOfRightToken;
352- }
353- if (distance.has_value ()) {
354- return distance.value ();
332+ if (rightSpaceOfLeftToken.has_value ()) {
333+ return rightSpaceOfLeftToken.value ();
355334 }
356335 if (!right.IsNull (t)) {
357336 return t.GetStartOffset (right.GetIndex ()) - t.GetEndOffset (left.GetIndex ()) - 1 ;
0 commit comments