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

Function __format

src/lua-format.cpp:10–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8using namespace antlr4;
9
10static 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
30static const std::string DISABLE_FORMAT_BEGIN = "-- LuaFormatter off";
31static const std::string DISABLE_FORMAT_END = "-- LuaFormatter on";

Callers 1

lua_formatFunction · 0.85

Calls 2

chunkMethod · 0.80
acceptMethod · 0.80

Tested by

no test coverage detected