From 122599e78752581905dad6b1b7896534d48911fa Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 23 May 2023 15:57:49 +0800 Subject: fix lineOffset option not working. --- src/yuescript/yue_compiler.cpp | 17 ++++++++++------- src/yuescript/yue_parser.cpp | 4 ++-- src/yuescript/yue_parser.h | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') 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 Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.16.6"sv; +const std::string_view version = "0.16.7"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -250,7 +250,7 @@ public: for (const auto& var : _globals) { int line, col; std::tie(line, col) = var.second; - globals->push_back({var.first, line, col}); + globals->push_back({var.first, line + _config.lineOffset, col}); } std::sort(globals->begin(), globals->end(), [](const GlobalVar& varA, const GlobalVar& varB) { if (varA.line < varB.line) { @@ -284,12 +284,13 @@ public: #endif // YUE_NO_MACRO return {std::move(out.back()), std::nullopt, std::move(globals), std::move(options), parseTime, compileTime}; } catch (const CompileError& error) { - auto displayMessage = _info.errorMessage(error.what(), error.line, error.col); + auto displayMessage = _info.errorMessage(error.what(), error.line, error.col, _config.lineOffset); return { std::string(), CompileInfo::Error{ error.what(), - error.line, error.col, + error.line + _config.lineOffset, + error.col, displayMessage}, std::move(globals), std::move(options), @@ -302,18 +303,20 @@ public: std::string(), CompileInfo::Error{ error.msg, - error.line, error.col, + error.line + _config.lineOffset, + error.col, ""}, std::move(globals), std::move(options), parseTime, compileTime}; } - auto displayMessage = _info.errorMessage(error.msg, error.line, error.col); + auto displayMessage = _info.errorMessage(error.msg, error.line, error.col, _config.lineOffset); return { std::string(), CompileInfo::Error{ error.msg, - error.line, error.col, + error.line + _config.lineOffset, + error.col, displayMessage}, std::move(globals), 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) { } } // namespace Utils -std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCol) const { +std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCol, int lineOffset) const { const int ASCII = 255; int length = errLine; auto begin = codes->begin(); @@ -1009,7 +1009,7 @@ std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCo } Utils::replace(line, "\t"sv, " "sv); std::ostringstream buf; - buf << errLine << ": "sv << msg << '\n' + buf << errLine + lineOffset << ": "sv << msg << '\n' << line << '\n' << std::string(col, ' ') << "^"sv; 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 { bool exportMacro = false; bool exportMetatable = false; std::string moduleName; - std::string errorMessage(std::string_view msg, int errLine, int errCol) const; + std::string errorMessage(std::string_view msg, int errLine, int errCol, int lineOffset = 0) const; }; template -- cgit v1.2.3-55-g6feb