Skip to content

Commit 865bad4

Browse files
committed
Add: Show location and file for parse error
1 parent 2f9cebf commit 865bad4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/luaumb.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main(int argc, char** argv) {
3232
const char* in_name = argv[1];
3333
const char* out_name = argv[2];
3434

35-
std::vector<Luau::ParseError> errors;
35+
std::map<const std::string, std::vector<Luau::ParseError>> parse_errors;
3636
std::map<std::string, Luau::Config> configs;
3737
RelativePathModule main_path(in_name);
3838
LuauModuleBundle lmb(main_path);
@@ -90,7 +90,7 @@ int main(int argc, char** argv) {
9090
const Luau::Config& config = configs[module_path.relative.parent_path().string()];
9191

9292
RequireFunctionLocalizerResult result = require_function_localizer(*file);
93-
errors.insert(errors.end(), result.parse_errors.begin(), result.parse_errors.end());
93+
if (result.parse_errors.size() != 0) parse_errors[module_path.path.string()] = result.parse_errors;
9494

9595
for (ExprCallRequire& require : result.list) {
9696
std::filesystem::path path;
@@ -123,10 +123,13 @@ int main(int argc, char** argv) {
123123
}
124124
}
125125

126-
if (errors.size() > 0) {
126+
if (parse_errors.size() > 0) {
127127
std::cout << "Parse errors were encountered:" << std::endl;
128-
for (const Luau::ParseError& error : errors) {
129-
std::cout << " " << toString(error.getLocation()) << " - " << error.getMessage() << std::endl;
128+
for (const auto& [file, errors] : parse_errors) {
129+
for (const Luau::ParseError& error : errors) {
130+
Luau::Location error_location = error.getLocation();
131+
std::cout << " " << file << ":" << (error_location.begin.line + 1) << ":" << (error_location.begin.column + 1) << " - " << error.getMessage() << std::endl;
132+
}
130133
}
131134
}
132135

@@ -139,5 +142,5 @@ int main(int argc, char** argv) {
139142
out_file << out;
140143
out_file.close();
141144

142-
return errors.size() > 0 ? 1 : 0;
145+
return parse_errors.size() > 0 ? 1 : 0;
143146
}

0 commit comments

Comments
 (0)