| 58 | } |
| 59 | |
| 60 | char *CodeFormat::Reformat(const std::string &uri, std::string &&text, FormattingOptions options) { |
| 61 | auto file = LuaSource::From(std::move(text)); |
| 62 | LuaLexer luaLexer(file); |
| 63 | if (_supportNonStandardSymbol || options.non_standard_symbol) { |
| 64 | luaLexer.SupportNonStandardSymbol(); |
| 65 | } |
| 66 | if (_supportCLikeComments || options.non_standard_symbol) { |
| 67 | luaLexer.SupportCLikeComments(); |
| 68 | } |
| 69 | |
| 70 | luaLexer.Parse(); |
| 71 | |
| 72 | LuaParser p(file, std::move(luaLexer.GetTokens())); |
| 73 | p.Parse(); |
| 74 | |
| 75 | if (p.HasError()) { |
| 76 | return nullptr; |
| 77 | } |
| 78 | |
| 79 | LuaSyntaxTree t; |
| 80 | t.BuildTree(p); |
| 81 | |
| 82 | LuaStyle style = GetStyle(uri); |
| 83 | SetupStyle(style, options); |
| 84 | FormatBuilder f(style); |
| 85 | |
| 86 | auto result = f.GetFormatResult(t); |
| 87 | auto length = result.size(); |
| 88 | char *ptr = new char[length + 1]; |
| 89 | std::copy(result.begin(), result.end(), ptr); |
| 90 | ptr[length] = '\0'; |
| 91 | return ptr; |
| 92 | } |
| 93 | |
| 94 | Result<RangeFormatResult> CodeFormat::RangeFormat(const std::string &uri, FormatRange &range, |
| 95 | std::string &&text, FormattingOptions options) { |
no test coverage detected