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

Method visitBlock

src/FormatVisitor.cpp:297–338  ·  view source on GitHub ↗

stat* retstat?

Source from the content-addressed store, hash-verified

295
296// stat* retstat?
297antlrcpp::Any FormatVisitor::visitBlock(LuaParser::BlockContext* ctx) {
298 LOG_FUNCTION_BEGIN();
299 auto stats = ctx->stat();
300 int n = stats.size();
301 for (int i = 0; i < n; i++) {
302 bool isSemi = stats[i]->SEMI() != nullptr;
303 bool needComment = i < n - 1 || ctx->retstat() != nullptr;
304 bool isNextSemi = i + 1 < n && stats[i + 1]->SEMI() != nullptr;
305 if (!isSemi) {
306 visitStat(stats[i]);
307 }
308 bool previousWhiteSpace = isSemi || cur_writer().isLastCharWhiteSpace();
309 if (needComment) {
310 if (isNextSemi) {
311 std::string comment = commentAfter(stats[i], "");
312 if (previousWhiteSpace && !comment.empty() && comment[0] == ' ') {
313 cur_writer() << comment.substr(1, comment.size() - 1);
314 } else {
315 cur_writer() << comment;
316 }
317 } else {
318 std::string comment = commentAfterNewLine(stats[i], NONE_INDENT);
319 if (previousWhiteSpace && !comment.empty() && comment[0] == ' ') {
320 cur_writer() << comment.substr(1, comment.size() - 1);
321 } else {
322 cur_writer() << comment;
323 }
324 }
325 }
326 }
327 if (ctx->retstat() != nullptr) {
328 visitRetstat(ctx->retstat());
329 }
330 if (ctx->retstat() == nullptr && cur_writer().isLastCharWhiteSpace()) {
331 std::string blockComment = commentAfter(ctx, "");
332 if (!blockComment.empty() && blockComment[0] == ' ') {
333 cur_writer().ss().seekp(-1, std::ios::end);
334 }
335 }
336 LOG_FUNCTION_END();
337 return nullptr;
338}
339
340antlrcpp::Any FormatVisitor::visitStat(LuaParser::StatContext* ctx) {
341 LOG_FUNCTION_BEGIN();

Callers

nothing calls this directly

Calls 4

statMethod · 0.80
SEMIMethod · 0.80
retstatMethod · 0.80
isLastCharWhiteSpaceMethod · 0.80

Tested by

no test coverage detected