@@ -1618,21 +1618,21 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableField(std::shared_ptr<Lu
16181618 }
16191619 case LuaAstNodeType::IndexOperator:
16201620 {
1621- if (child->GetTokenType () == ' [' )
1621+ if (child->GetTokenType () == ' [' )
16221622 {
16231623 auto nextNode = NextNode (it, children);
1624- if (nextNode && nextNode->GetType () == LuaAstNodeType::Expression)
1624+ if (nextNode && nextNode->GetType () == LuaAstNodeType::Expression
1625+ && (StringUtil::StartWith (nextNode->GetText (), " [" )
1626+ || StringUtil::EndWith (nextNode->GetText (), " ]" ))
1627+ )
16251628 {
1626- auto stringExpr = nextNode->FindFirstOf (LuaAstNodeType::StringLiteralExpression);
1627- if (stringExpr && StringUtil::StartWith (stringExpr->GetText (), " [" )) {
1628- isIndexExprLongString = true ;
1629- env->Add <TextElement>(child);
1630- env->Add <KeepElement>(1 );
1631- continue ;
1632- }
1629+ isIndexExprLongString = true ;
1630+ env->Add <TextElement>(child);
1631+ env->Add <KeepElement>(1 );
1632+ continue ;
16331633 }
16341634 }
1635- else if (child->GetTokenType () == ' ]' && isIndexExprLongString)
1635+ else if (child->GetTokenType () == ' ]' && isIndexExprLongString)
16361636 {
16371637 env->Add <KeepElement>(1 );
16381638 }
@@ -2226,23 +2226,22 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatIndexExpression(std::shared_p
22262226 {
22272227 expressionAfterIndexOperator = true ;
22282228 auto nextNode = NextNode (it, children);
2229- if (nextNode && nextNode->GetType () == LuaAstNodeType::Expression)
2229+ if (nextNode && nextNode->GetType () == LuaAstNodeType::Expression
2230+ && (StringUtil::StartWith (nextNode->GetText (), " [" )
2231+ || StringUtil::EndWith (nextNode->GetText (), " ]" )))
22302232 {
2231- auto stringExpr = nextNode->FindFirstOf (LuaAstNodeType::StringLiteralExpression);
2232- if (stringExpr && StringUtil::StartWith (stringExpr->GetText (), " [" )) {
2233- isIndexExprLongString = true ;
2234- env->Add <TextElement>(child);
2235- env->Add <KeepElement>(1 );
2236- continue ;
2237- }
2233+ isIndexExprLongString = true ;
2234+ env->Add <TextElement>(child);
2235+ env->Add <KeepElement>(1 );
2236+ continue ;
22382237 }
22392238
22402239 env->Add <TextElement>(child);
22412240 env->Add <KeepElement>(0 );
22422241 }
2243- else if (child->GetTokenType () == ' ]' )
2242+ else if (child->GetTokenType () == ' ]' )
22442243 {
2245- env->Add <KeepElement>(isIndexExprLongString? 1 : 0 );
2244+ env->Add <KeepElement>(isIndexExprLongString ? 1 : 0 );
22462245 env->Add <TextElement>(child);
22472246 env->Add <KeepElement>(0 );
22482247 }
0 commit comments