MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / ReformatSingleFile

Method ReformatSingleFile

CodeFormat/src/LuaFormat.cpp:33–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33bool LuaFormat::ReformatSingleFile(const FormatContext &context, std::string_view outPath, std::string &&sourceText, LuaStyle style) {
34 auto file = LuaSource::From(std::move(sourceText));
35 LuaLexer luaLexer(file);
36 if (context.IsNonStandardLua()) {
37 luaLexer.SupportNonStandardSymbol();
38 }
39 if (context.IsCLikeCommentsSupport()) {
40 luaLexer.SupportCLikeComments();
41 }
42
43 luaLexer.Parse();
44
45 LuaParser p(file, std::move(luaLexer.GetTokens()));
46 p.Parse();
47
48 if (p.HasError()) {
49 std::cerr << "Exist Syntax Errors" << std::endl;
50 return false;
51 }
52
53 LuaSyntaxTree t;
54 t.BuildTree(p);
55
56 if (outPath.empty()) {
57 style.detect_end_of_line = false;
58 style.end_of_line = EndOfLine::LF;
59 }
60
61 FormatBuilder f(style);
62 auto formattedText = f.GetFormatResult(t);
63
64 if (!outPath.empty()) {
65 std::fstream fout(std::string(outPath), std::ios::out | std::ios::binary);
66 fout.write(formattedText.data(), formattedText.size());
67 fout.close();
68 } else {
69 std::cout.write(formattedText.data(), formattedText.size());
70 }
71 return true;
72}
73
74bool LuaFormat::RangeReformat(const FormatContext &context) {
75 auto text = context.GetInputText();

Callers

nothing calls this directly

Calls 14

stringFunction · 0.85
IsNonStandardLuaMethod · 0.80
GetTokensMethod · 0.80
BuildTreeMethod · 0.80
SupportCLikeCommentsMethod · 0.45
ParseMethod · 0.45
HasErrorMethod · 0.45
emptyMethod · 0.45
GetFormatResultMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected