| 8 | using namespace antlr4; |
| 9 | |
| 10 | static std::string __format(ANTLRInputStream& input, const Config& config) { |
| 11 | LuaLexer lexer(&input); |
| 12 | CommonTokenStream tokenstream(&lexer); |
| 13 | LuaParser parser(&tokenstream); |
| 14 | |
| 15 | LuaParser::ChunkContext* chunk = parser.chunk(); |
| 16 | |
| 17 | if (parser.getNumberOfSyntaxErrors() > 0) { |
| 18 | throw std::invalid_argument("Input contains syntax errors"); |
| 19 | } |
| 20 | |
| 21 | std::vector<antlr4::Token*> tokenVector; |
| 22 | for (auto* t : tokenstream.getTokens()) { |
| 23 | tokenVector.emplace_back(t); |
| 24 | } |
| 25 | |
| 26 | FormatVisitor visitor(tokenVector, config); |
| 27 | return chunk->accept(&visitor).as<std::string>(); |
| 28 | } |
| 29 | |
| 30 | static const std::string DISABLE_FORMAT_BEGIN = "-- LuaFormatter off"; |
| 31 | static const std::string DISABLE_FORMAT_END = "-- LuaFormatter on"; |
no test coverage detected