aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-05-23 15:57:49 +0800
committerLi Jin <dragon-fly@qq.com>2023-05-23 15:57:49 +0800
commit122599e78752581905dad6b1b7896534d48911fa (patch)
treeab8dd4b2f5c24113a6ef5951bec3e3827114b204
parent78433df36c5b492f366ba57d852f5393b786cfff (diff)
downloadyuescript-122599e78752581905dad6b1b7896534d48911fa.tar.gz
yuescript-122599e78752581905dad6b1b7896534d48911fa.tar.bz2
yuescript-122599e78752581905dad6b1b7896534d48911fa.zip
fix lineOffset option not working.
-rw-r--r--src/yuescript/yue_compiler.cpp17
-rw-r--r--src/yuescript/yue_parser.cpp4
-rw-r--r--src/yuescript/yue_parser.h2
3 files changed, 13 insertions, 10 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 918ae2a..b623425 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -72,7 +72,7 @@ static std::unordered_set<std::string> Metamethods = {
72 "close"s // Lua 5.4 72 "close"s // Lua 5.4
73}; 73};
74 74
75const std::string_view version = "0.16.6"sv; 75const std::string_view version = "0.16.7"sv;
76const std::string_view extension = "yue"sv; 76const std::string_view extension = "yue"sv;
77 77
78class CompileError : public std::logic_error { 78class CompileError : public std::logic_error {
@@ -250,7 +250,7 @@ public:
250 for (const auto& var : _globals) { 250 for (const auto& var : _globals) {
251 int line, col; 251 int line, col;
252 std::tie(line, col) = var.second; 252 std::tie(line, col) = var.second;
253 globals->push_back({var.first, line, col}); 253 globals->push_back({var.first, line + _config.lineOffset, col});
254 } 254 }
255 std::sort(globals->begin(), globals->end(), [](const GlobalVar& varA, const GlobalVar& varB) { 255 std::sort(globals->begin(), globals->end(), [](const GlobalVar& varA, const GlobalVar& varB) {
256 if (varA.line < varB.line) { 256 if (varA.line < varB.line) {
@@ -284,12 +284,13 @@ public:
284#endif // YUE_NO_MACRO 284#endif // YUE_NO_MACRO
285 return {std::move(out.back()), std::nullopt, std::move(globals), std::move(options), parseTime, compileTime}; 285 return {std::move(out.back()), std::nullopt, std::move(globals), std::move(options), parseTime, compileTime};
286 } catch (const CompileError& error) { 286 } catch (const CompileError& error) {
287 auto displayMessage = _info.errorMessage(error.what(), error.line, error.col); 287 auto displayMessage = _info.errorMessage(error.what(), error.line, error.col, _config.lineOffset);
288 return { 288 return {
289 std::string(), 289 std::string(),
290 CompileInfo::Error{ 290 CompileInfo::Error{
291 error.what(), 291 error.what(),
292 error.line, error.col, 292 error.line + _config.lineOffset,
293 error.col,
293 displayMessage}, 294 displayMessage},
294 std::move(globals), 295 std::move(globals),
295 std::move(options), 296 std::move(options),
@@ -302,18 +303,20 @@ public:
302 std::string(), 303 std::string(),
303 CompileInfo::Error{ 304 CompileInfo::Error{
304 error.msg, 305 error.msg,
305 error.line, error.col, 306 error.line + _config.lineOffset,
307 error.col,
306 ""}, 308 ""},
307 std::move(globals), 309 std::move(globals),
308 std::move(options), 310 std::move(options),
309 parseTime, compileTime}; 311 parseTime, compileTime};
310 } 312 }
311 auto displayMessage = _info.errorMessage(error.msg, error.line, error.col); 313 auto displayMessage = _info.errorMessage(error.msg, error.line, error.col, _config.lineOffset);
312 return { 314 return {
313 std::string(), 315 std::string(),
314 CompileInfo::Error{ 316 CompileInfo::Error{
315 error.msg, 317 error.msg,
316 error.line, error.col, 318 error.line + _config.lineOffset,
319 error.col,
317 displayMessage}, 320 displayMessage},
318 std::move(globals), 321 std::move(globals),
319 std::move(options), 322 std::move(options),
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 99fea0a..dffdbe1 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -976,7 +976,7 @@ void trim(std::string& str) {
976} 976}
977} // namespace Utils 977} // namespace Utils
978 978
979std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCol) const { 979std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCol, int lineOffset) const {
980 const int ASCII = 255; 980 const int ASCII = 255;
981 int length = errLine; 981 int length = errLine;
982 auto begin = codes->begin(); 982 auto begin = codes->begin();
@@ -1009,7 +1009,7 @@ std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCo
1009 } 1009 }
1010 Utils::replace(line, "\t"sv, " "sv); 1010 Utils::replace(line, "\t"sv, " "sv);
1011 std::ostringstream buf; 1011 std::ostringstream buf;
1012 buf << errLine << ": "sv << msg << '\n' 1012 buf << errLine + lineOffset << ": "sv << msg << '\n'
1013 << line << '\n' 1013 << line << '\n'
1014 << std::string(col, ' ') << "^"sv; 1014 << std::string(col, ' ') << "^"sv;
1015 return buf.str(); 1015 return buf.str();
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h
index 59a16a8..3be50a7 100644
--- a/src/yuescript/yue_parser.h
+++ b/src/yuescript/yue_parser.h
@@ -39,7 +39,7 @@ struct ParseInfo {
39 bool exportMacro = false; 39 bool exportMacro = false;
40 bool exportMetatable = false; 40 bool exportMetatable = false;
41 std::string moduleName; 41 std::string moduleName;
42 std::string errorMessage(std::string_view msg, int errLine, int errCol) const; 42 std::string errorMessage(std::string_view msg, int errLine, int errCol, int lineOffset = 0) const;
43}; 43};
44 44
45template <typename T> 45template <typename T>