@@ -262,7 +262,8 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatBlock(std::shared_ptr<LuaAstN
262262 }
263263 case LuaAstNodeType::RepeatStatement:
264264 {
265- indentEnv->AddChild (FormatNode (statement));
265+ auto child = FormatNode (statement);
266+ indentEnv->AddChild (child);
266267 indentEnv->AddChild (_options.keep_line_after_repeat_statement );
267268 break ;
268269 }
@@ -868,7 +869,14 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatRepeatStatement(std::shared_p
868869 {
869870 bool singleLine = false ;
870871 env->AddChild (FormatNodeAndBlockOrEnd (it, singleLine, children));
871- env->Add <KeepLineElement>();
872+ if (singleLine)
873+ {
874+ env->Add <KeepElement>(1 );
875+ }
876+ else
877+ {
878+ env->Add <KeepLineElement>();
879+ }
872880 }
873881 else
874882 {
@@ -1723,9 +1731,10 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatBinaryExpression(std::shared_
17231731std::shared_ptr<FormatElement> LuaFormatter::FormatUnaryExpression (std::shared_ptr<LuaAstNode> unaryExpression)
17241732{
17251733 auto env = std::make_shared<SubExpressionElement>();
1726-
1727- for (const auto & child : unaryExpression-> GetChildren () )
1734+ auto & children = unaryExpression-> GetChildren ();
1735+ for (auto it = children. begin (); it != children. end (); ++it )
17281736 {
1737+ auto child = *it;
17291738 switch (child->GetType ())
17301739 {
17311740 case LuaAstNodeType::UnaryOperator:
@@ -1737,6 +1746,13 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatUnaryExpression(std::shared_p
17371746 }
17381747 else
17391748 {
1749+ auto next = nextNode (it, children);
1750+ if (next && (next->GetType () == LuaAstNodeType::UnaryExpression || next->GetType () ==
1751+ LuaAstNodeType::Comment))
1752+ {
1753+ env->Add <KeepElement>(1 );
1754+ break ;
1755+ }
17401756 env->Add <KeepElement>(0 );
17411757 }
17421758 break ;
0 commit comments