LB fieldlist? RB;
| 1562 | |
| 1563 | // LB fieldlist? RB; |
| 1564 | antlrcpp::Any FormatVisitor::visitTableconstructor(LuaParser::TableconstructorContext* ctx) { |
| 1565 | LOG_FUNCTION_BEGIN(); |
| 1566 | cur_writer() << ctx->LB()->getText(); |
| 1567 | // disable indentForAlign_ in table |
| 1568 | int temp = indentForAlign_; |
| 1569 | indentForAlign_ = 0; |
| 1570 | if (ctx->fieldlist() != nullptr) { |
| 1571 | bool containsKv = false; |
| 1572 | bool chopDown = false; |
| 1573 | if (config_.get<bool>("chop_down_kv_table")) { |
| 1574 | for (auto* f : ctx->fieldlist()->field()) { |
| 1575 | if (f->EQL() != nullptr) { |
| 1576 | containsKv = true; |
| 1577 | break; |
| 1578 | } |
| 1579 | } |
| 1580 | } |
| 1581 | bool temp = chop_down_table_; |
| 1582 | bool beyondLimit = fastTestColumnLimit(ctx->fieldlist()); |
| 1583 | if (!beyondLimit) { |
| 1584 | pushWriter(); |
| 1585 | cur_writer() << commentAfter(ctx->LB(), ""); |
| 1586 | chop_down_table_ = false; |
| 1587 | visitFieldlist(ctx->fieldlist()); |
| 1588 | chop_down_table_ = temp; |
| 1589 | cur_writer() << commentAfter(ctx->fieldlist(), ""); |
| 1590 | cur_writer() << ctx->RB()->getText(); |
| 1591 | int length = cur_writer().firstLineColumn(); |
| 1592 | int lines = cur_writer().lines(); |
| 1593 | popWriter(); |
| 1594 | beyondLimit = cur_columns() + length > config_.get<int>("column_table_limit") || lines > 1; |
| 1595 | } |
| 1596 | bool breakAfterLb = false; |
| 1597 | if (beyondLimit) { |
| 1598 | breakAfterLb = config_.get<bool>("break_after_table_lb"); |
| 1599 | chopDown = config_.get<bool>("chop_down_table") || (config_.get<bool>("chop_down_kv_table") && containsKv); |
| 1600 | } |
| 1601 | if (chopDown) { |
| 1602 | cur_writer() << commentAfterNewLine(ctx->LB(), INC_INDENT); |
| 1603 | cur_writer() << indent(); |
| 1604 | chop_down_table_ = true; |
| 1605 | } else { |
| 1606 | if (breakAfterLb) { |
| 1607 | cur_writer() << commentAfterNewLine(ctx->LB(), INC_INDENT); |
| 1608 | cur_writer() << indent(); |
| 1609 | } else { |
| 1610 | if (config_.get<bool>("spaces_inside_table_braces") && !breakAfterLb) { |
| 1611 | cur_writer() << " "; |
| 1612 | } |
| 1613 | cur_writer() << commentAfter(ctx->LB(), ""); |
| 1614 | } |
| 1615 | chop_down_table_ = false; |
| 1616 | } |
| 1617 | visitFieldlist(ctx->fieldlist()); |
| 1618 | bool needExtraFieldSep = config_.get<bool>("extra_sep_at_table_end") && !ctx->fieldlist()->field().empty(); |
| 1619 | if (chopDown) { |
| 1620 | if (needExtraFieldSep) { |
| 1621 | cur_writer() << config_.get<std::string>("table_sep"); |