2424#include " CodeService/FormatElement/CallArgsListLayoutElement.h"
2525#include " Util/StringUtil.h"
2626#include " CodeService/AstUtil.h"
27+ #include " LuaParser/LuaTokenTypeDetail.h"
2728
2829bool NextMatch (LuaAstNode::ChildIterator it, LuaAstNodeType type, const LuaAstNode::ChildrenContainer& container)
2930{
@@ -411,7 +412,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatLocalStatement(std::shared_pt
411412 case LuaAstNodeType::GeneralOperator:
412413 {
413414 // 基于这样的考虑 可能local 语句没有等号所以nameDefList的空格移上来
414- if (node->GetText () == " = " )
415+ if (node->GetTokenType () == ' = ' )
415416 {
416417 env->Add <KeepBlankElement>(1 );
417418 }
@@ -1012,7 +1013,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatForBody(std::shared_ptr<LuaAs
10121013 {
10131014 case LuaAstNodeType::KeyWord:
10141015 {
1015- if (child->GetText () == " do " )
1016+ if (child->GetTokenType () == TK_DO )
10161017 {
10171018 bool singleLine = false ;
10181019 env->AddChild (FormatNodeAndBlockOrEnd (it, singleLine, children));
@@ -1064,7 +1065,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatRepeatStatement(std::shared_p
10641065 {
10651066 case LuaAstNodeType::KeyWord:
10661067 {
1067- if (child->GetText () == " repeat " )
1068+ if (child->GetTokenType () == TK_REPEAT )
10681069 {
10691070 bool singleLine = false ;
10701071 env->AddChild (FormatNodeAndBlockOrEnd (it, singleLine, children));
@@ -1110,13 +1111,13 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIfStatement(std::shared_ptr<L
11101111 {
11111112 case LuaAstNodeType::KeyWord:
11121113 {
1113- if (child->GetText () == " then " || child->GetText () == " else " )
1114+ if (child->GetTokenType () == TK_THEN || child->GetTokenType () == TK_ELSE )
11141115 {
11151116 bool singleLine = false ;
11161117 env->AddChild (FormatNodeAndBlockOrEnd (it, singleLine, children));
11171118 env->Add <KeepElement>(1 , !singleLine);
11181119 }
1119- else if (child->GetText () == " if " || child->GetText () == " elseif " )
1120+ else if (child->GetTokenType () == TK_IF || child->GetTokenType () == TK_ELSEIF )
11201121 {
11211122 env->Add <TextElement>(child);
11221123 env->Add <KeepBlankElement>(1 );
@@ -1183,7 +1184,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatExpressionStatement(std::shar
11831184 if (indexExpression)
11841185 {
11851186 auto indexOp = indexExpression->FindFirstOf (LuaAstNodeType::IndexOperator);
1186- if (indexOp->GetText () == " . " || indexOp->GetText () == " : " )
1187+ if (indexOp->GetTokenType () == ' . ' || indexOp->GetTokenType () == ' : ' )
11871188 {
11881189 auto continuationIndent = _parser->GetColumn (indexOp->GetTextRange ().StartOffset )
11891190 - _parser->GetColumn (child->GetTextRange ().StartOffset );
@@ -1366,17 +1367,17 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatParamList(std::shared_ptr<Lua
13661367 {
13671368 case LuaAstNodeType::GeneralOperator:
13681369 {
1369- if (child->GetText () == " , " )
1370+ if (child->GetTokenType () == ' , ' )
13701371 {
1371- if (_options.remove_expression_list_finish_comma
1372+ if (_options.remove_expression_list_finish_comma
13721373 && NextMatch (it, LuaAstNodeType::GeneralOperator, children))
13731374 {
13741375 break ;
13751376 }
13761377 paramListLayoutEnv->Add <TextElement>(child);
13771378 paramListLayoutEnv->Add <KeepElement>(1 );
13781379 }
1379- else if (child->GetText () == " ) " )
1380+ else if (child->GetTokenType () == ' ) ' )
13801381 {
13811382 env->AddChild (paramListLayoutEnv);
13821383 if (!paramListLayoutEnv->GetChildren ().empty ())
@@ -1541,12 +1542,12 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableExpression(std::shared_p
15411542 {
15421543 case LuaAstNodeType::GeneralOperator:
15431544 {
1544- if (child->GetText () == " { " )
1545+ if (child->GetTokenType () == ' { ' )
15451546 {
15461547 env->Add <TextElement>(child);
15471548 leftBraceLine = _parser->GetLine (child->GetTextRange ().EndOffset );
15481549 }
1549- else if (child->GetText () == " } " )
1550+ else if (child->GetTokenType () == ' } ' )
15501551 {
15511552 if (tableFieldLayout->GetChildren ().empty ())
15521553 {
@@ -1591,7 +1592,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableField(std::shared_ptr<Lu
15911592 {
15921593 case LuaAstNodeType::GeneralOperator:
15931594 {
1594- if (child->GetText () == " = " )
1595+ if (child->GetTokenType () == ' = ' )
15951596 {
15961597 eqSignFounded = true ;
15971598 env->Add <KeepBlankElement>(1 );
@@ -1672,7 +1673,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAlignStatement(LuaAstNode::Ch
16721673 std::shared_ptr<FormatElement> env = nullptr ;
16731674 if (_options.continuous_assign_statement_align_to_equal_sign )
16741675 {
1675- env = std::make_shared<AlignmentLayoutElement>(" = " );
1676+ env = std::make_shared<AlignmentLayoutElement>(' = ' );
16761677 }
16771678 else
16781679 {
@@ -1842,7 +1843,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAlignTableField(LuaAstNode::C
18421843
18431844 if (canAlign && _options.continuous_assign_table_field_align_to_equal_sign && layout->GetChildren ().size () > 1 )
18441845 {
1845- auto alignmentLayoutElement = std::make_shared<AlignmentLayoutElement>(" = " );
1846+ auto alignmentLayoutElement = std::make_shared<AlignmentLayoutElement>(' = ' );
18461847 alignmentLayoutElement->CopyFrom (layout);
18471848 layout = alignmentLayoutElement;
18481849 }
@@ -1920,7 +1921,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatNodeAndBlockOrEnd(LuaAstNode:
19201921 if (NextMatch (it, LuaAstNodeType::KeyWord, children))
19211922 {
19221923 auto next = NextNode (it, children);
1923- if (next->GetText () == " end " )
1924+ if (next->GetTokenType () == TK_END )
19241925 {
19251926 env->Add <TextElement>(next);
19261927 ++it;
@@ -1983,7 +1984,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatBlockFromParent(LuaAstNode::C
19831984 auto nextKey = NextNode (it, siblings);
19841985 if (_options.if_branch_comments_after_block_no_indent
19851986 && nextKey && nextKey->GetType () == LuaAstNodeType::KeyWord
1986- && (nextKey->GetText () == " elseif " || nextKey->GetText () == " else " ))
1987+ && (nextKey->GetTokenType () == TK_ELSEIF || nextKey->GetTokenType () == TK_ELSE ))
19871988 {
19881989 auto blockEnv = FormatBlock (copyBlock);
19891990 auto noIndentEnv = std::make_shared<NoIndentElement>();
@@ -2113,7 +2114,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatUnaryExpression(std::shared_p
21132114 case LuaAstNodeType::UnaryOperator:
21142115 {
21152116 env->Add <TextElement>(child);
2116- if (child->GetText () == " not " )
2117+ if (child->GetTokenType () == TK_NOT )
21172118 {
21182119 env->Add <KeepElement>(1 );
21192120 }
@@ -2185,7 +2186,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIndexExpression(std::shared_p
21852186 {
21862187 if (_options.table_append_expression_no_space )
21872188 {
2188- if (child->GetText () == " [ " )
2189+ if (child->GetTokenType () == ' [ ' )
21892190 {
21902191 expressionAfterIndexOperator = true ;
21912192 }
@@ -2194,7 +2195,7 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIndexExpression(std::shared_p
21942195 env->Add <TextElement>(child);
21952196 if (_options.long_chain_expression_allow_one_space_after_colon )
21962197 {
2197- if (child->GetText () == " : " && _parser->GetLuaFile ()->OnlyEmptyCharBefore (
2198+ if (child->GetTokenType () == ' : ' && _parser->GetLuaFile ()->OnlyEmptyCharBefore (
21982199 child->GetTextRange ().StartOffset ))
21992200 {
22002201 env->Add <MaxSpaceElement>(1 );
0 commit comments