MCPcopy Create free account
hub / github.com/Koihik/LuaFormatter / visitNextNameAndArgs

Method visitNextNameAndArgs

src/FormatVisitor.cpp:1300–1355  ·  view source on GitHub ↗

visit next NameAndArgsContext of VarSuffixContext

Source from the content-addressed store, hash-verified

1298
1299// visit next NameAndArgsContext of VarSuffixContext
1300void FormatVisitor::visitNextNameAndArgs(LuaParser::VarSuffixContext* ctx) {
1301 // find args of NAME
1302 auto* varCtx = dynamic_cast<LuaParser::VarContext*>(ctx->parent);
1303 const std::vector<LuaParser::VarSuffixContext*>& arr = varCtx->varSuffix();
1304 unsigned int index = find(arr.begin(), arr.end(), ctx) - arr.begin();
1305 if (index + 1 < arr.size()) {
1306 for (auto* na : arr[index + 1]->nameAndArgs()) {
1307 // if next NameAndArgs's COLON is not null
1308 // then formatter can place a break before COLON.
1309 // So do not need to calc column length for current NAME, break the loop.
1310 // example:
1311 // self.xxx.yyy:foo()
1312 // the 'xxx' and 'yyy' is a 'Variable', and 'foo' is a 'Method'
1313 // It better break before 'foo' than break before 'yyy'
1314 if (na->COLON() != nullptr) {
1315 break;
1316 }
1317 visitNameAndArgs(na);
1318 if (na != arr[index + 1]->nameAndArgs().back()) {
1319 cur_writer() << commentAfter(na, "");
1320 }
1321 }
1322 } else {
1323 auto* varOrExpCtx = dynamic_cast<LuaParser::VarOrExpContext*>(varCtx->parent);
1324 // parent maybe VarlistContext
1325 if (varOrExpCtx != nullptr) {
1326 tree::ParseTree* parent = varOrExpCtx->parent;
1327
1328 auto* peCtx = dynamic_cast<LuaParser::PrefixexpContext*>(parent);
1329 if (peCtx != nullptr) {
1330 for (auto* na : peCtx->nameAndArgs()) {
1331 if (na->COLON() != nullptr) {
1332 break;
1333 }
1334 visitNameAndArgs(na);
1335 if (na != peCtx->nameAndArgs().back()) {
1336 cur_writer() << commentAfter(na, "");
1337 }
1338 }
1339 }
1340
1341 auto* fcCtx = dynamic_cast<LuaParser::FunctioncallContext*>(parent);
1342 if (fcCtx != nullptr) {
1343 for (auto* na : fcCtx->nameAndArgs()) {
1344 if (na->COLON() != nullptr) {
1345 break;
1346 }
1347 visitNameAndArgs(na);
1348 if (na != fcCtx->nameAndArgs().back()) {
1349 cur_writer() << commentAfter(na, "");
1350 }
1351 }
1352 }
1353 }
1354 }
1355}
1356
1357// (COLON NAME)? args;

Callers

nothing calls this directly

Calls 3

varSuffixMethod · 0.80
nameAndArgsMethod · 0.80
COLONMethod · 0.80

Tested by

no test coverage detected