@@ -460,7 +460,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatLocalStatement(std::shared_pt
460460 }
461461 case LuaAstNodeType::Comment:
462462 {
463- env->AddChild (FormatNode (node));
463+ env->AddChild (FormatComment (node));
464464 env->Add <KeepElement>(1 );
465465 break ;
466466 }
@@ -563,7 +563,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatNameDefList(std::shared_ptr<L
563563 }
564564 case LuaAstNodeType::Comment:
565565 {
566- env->AddChild (FormatNode (node));
566+ env->AddChild (FormatComment (node));
567567 env->Add <KeepElement>(1 );
568568 break ;
569569 }
@@ -662,10 +662,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAssignLeftExpressionList(std:
662662
663663std::shared_ptr<FormatElement> LuaFormatter::FormatComment (std::shared_ptr<LuaAstNode> comment)
664664{
665- auto env = std::make_shared<ExpressionElement>();
666- env->Add <TextElement>(comment);
667-
668- return env;
665+ return std::make_shared<TextElement>(comment);
669666}
670667
671668std::shared_ptr<FormatElement> LuaFormatter::FormatBreakStatement (std::shared_ptr<LuaAstNode> breakNode)
@@ -712,7 +709,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatReturnStatement(std::shared_p
712709 }
713710 case LuaAstNodeType::Comment:
714711 {
715- env->AddChild (FormatNode (child));
712+ env->AddChild (FormatComment (child));
716713 env->Add <KeepElement>(1 );
717714 break ;
718715 }
@@ -1330,7 +1327,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatParamList(std::shared_ptr<Lua
13301327 }
13311328 case LuaAstNodeType::Comment:
13321329 {
1333- paramListLayoutEnv->Add <TextElement>( child);
1330+ paramListLayoutEnv->AddChild ( FormatComment ( child) );
13341331 paramListLayoutEnv->Add <KeepElement>(1 );
13351332 break ;
13361333 }
@@ -1532,7 +1529,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableField(std::shared_ptr<Lu
15321529 }
15331530 case LuaAstNodeType::Comment:
15341531 {
1535- env->AddChild (FormatNode (child));
1532+ env->AddChild (FormatComment (child));
15361533 env->Add <KeepElement>(1 );
15371534 break ;
15381535 }
@@ -1630,7 +1627,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAlignStatement(LuaAstNode::Ch
16301627 if (lastStatementEnv)
16311628 {
16321629 lastStatementEnv->Add <KeepBlankElement>(1 );
1633- lastStatementEnv->Add <TextElement>( nextChild);
1630+ lastStatementEnv->AddChild ( FormatNode ( nextChild) );
16341631 }
16351632 // else 应该不存在这种情况
16361633 }
@@ -1648,7 +1645,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAlignStatement(LuaAstNode::Ch
16481645
16491646 if (nextChild->GetType () == LuaAstNodeType::Comment)
16501647 {
1651- auto comment = FormatNode (nextChild);
1648+ auto comment = FormatComment (nextChild);
16521649 auto commentStatement = std::make_shared<StatementElement>();
16531650 commentStatement->AddChild (comment);
16541651 env->AddChild (commentStatement);
@@ -1789,7 +1786,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatNodeAndBlockOrEnd(LuaAstNode:
17891786 if (nextLine == currentLine)
17901787 {
17911788 env->Add <KeepBlankElement>(1 );
1792- env->Add <TextElement>( comment);
1789+ env->AddChild ( FormatComment ( comment) );
17931790 ++it;
17941791 }
17951792 }
@@ -1889,7 +1886,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatBlockFromParent(LuaAstNode::C
18891886 for (auto comment : comments)
18901887 {
18911888 auto commentStatement = std::make_shared<StatementElement>();
1892- commentStatement->Add <TextElement>( comment);
1889+ commentStatement->AddChild ( FormatComment ( comment) );
18931890 indentElement->AddChild (commentStatement);
18941891 indentElement->Add <KeepLineElement>();
18951892 }
@@ -2084,7 +2081,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIndexExpression(std::shared_p
20842081 }
20852082 case LuaAstNodeType::Comment:
20862083 {
2087- env->Add <TextElement>( child);
2084+ env->AddChild ( FormatComment ( child) );
20882085 env->Add <KeepElement>(1 );
20892086 break ;
20902087 }
@@ -2357,7 +2354,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatRangeBlock(std::shared_ptr<Lu
23572354 }
23582355 case LuaAstNodeType::Comment:
23592356 {
2360- auto comment = FormatNode (statement);
2357+ auto comment = FormatComment (statement);
23612358 auto commentStatement = std::make_shared<StatementElement>();
23622359 commentStatement->AddChild (comment);
23632360 indentEnv->AddChild (commentStatement);
@@ -2380,7 +2377,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatRangeBlock(std::shared_ptr<Lu
23802377 if (currentLine == nextLine)
23812378 {
23822379 statEnv->Add <KeepBlankElement>(1 );
2383- statEnv->Add <TextElement>( next);
2380+ statEnv->AddChild ( FormatComment ( next) );
23842381 ++it;
23852382 }
23862383 }
0 commit comments