diff options
author | Li Jin <dragon-fly@qq.com> | 2022-04-29 08:57:42 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-04-29 08:57:42 +0800 |
commit | 70d8bc6d5396799c71ee97a7f98791779c8f1a37 (patch) | |
tree | 279cd18072b324734f704f6eb15f067cbbdd441b | |
parent | d6f413ebbb1972dc2acf0565b749c32cf7699e39 (diff) | |
download | yuescript-70d8bc6d5396799c71ee97a7f98791779c8f1a37.tar.gz yuescript-70d8bc6d5396799c71ee97a7f98791779c8f1a37.tar.bz2 yuescript-70d8bc6d5396799c71ee97a7f98791779c8f1a37.zip |
prevent text mode macro from inserting line numbers in generated codes.
-rwxr-xr-x | doc/docs/doc/README.md | 6 | ||||
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 21 |
2 files changed, 15 insertions, 12 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index cc98538..abff593 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
@@ -417,7 +417,7 @@ merge = {...a, ...b} | |||
417 | 417 | ||
418 | The **#** operator can be used as a shortcut for metatable manipulation. | 418 | The **#** operator can be used as a shortcut for metatable manipulation. |
419 | 419 | ||
420 | * **Metatable Creation** | 420 | * **Metatable Creation** |
421 | Create normal table with key **#** or metamethod key that ends with **#**. | 421 | Create normal table with key **#** or metamethod key that ends with **#**. |
422 | 422 | ||
423 | ```moonscript | 423 | ```moonscript |
@@ -453,7 +453,7 @@ close _ = close#: -> print "out of scope" | |||
453 | </pre> | 453 | </pre> |
454 | </YueDisplay> | 454 | </YueDisplay> |
455 | 455 | ||
456 | * **Metatable Accessing** | 456 | * **Metatable Accessing** |
457 | Accessing metatable with key **#** or metamethod key that ends with **#**. | 457 | Accessing metatable with key **#** or metamethod key that ends with **#**. |
458 | 458 | ||
459 | ```moonscript | 459 | ```moonscript |
@@ -476,7 +476,7 @@ print tb.item | |||
476 | </pre> | 476 | </pre> |
477 | </YueDisplay> | 477 | </YueDisplay> |
478 | 478 | ||
479 | * **Metatable Destructure** | 479 | * **Metatable Destructure** |
480 | Destruct metatable with metamethod key that ends with **#**. | 480 | Destruct metatable with metamethod key that ends with **#**. |
481 | 481 | ||
482 | ```moonscript | 482 | ```moonscript |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 476494e..1546b85 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -60,7 +60,7 @@ using namespace parserlib; | |||
60 | 60 | ||
61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
62 | 62 | ||
63 | const std::string_view version = "0.10.15"sv; | 63 | const std::string_view version = "0.10.16"sv; |
64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
65 | 65 | ||
66 | class YueCompilerImpl { | 66 | class YueCompilerImpl { |
@@ -4244,6 +4244,8 @@ private: | |||
4244 | } else { | 4244 | } else { |
4245 | codes = lua_tostring(L, -1); | 4245 | codes = lua_tostring(L, -1); |
4246 | } | 4246 | } |
4247 | Utils::trim(codes); | ||
4248 | Utils::replace(codes, "\r\n"sv, "\n"sv); | ||
4247 | return {type, codes, std::move(localVars)}; | 4249 | return {type, codes, std::move(localVars)}; |
4248 | } | 4250 | } |
4249 | 4251 | ||
@@ -4266,11 +4268,20 @@ private: | |||
4266 | std::string err = lua_tostring(L, -1); | 4268 | std::string err = lua_tostring(L, -1); |
4267 | throw std::logic_error(_info.errorMessage(err, x)); | 4269 | throw std::logic_error(_info.errorMessage(err, x)); |
4268 | } | 4270 | } |
4271 | if (!codes.empty()) { | ||
4272 | if (_config.reserveLineNumber) { | ||
4273 | codes.insert(0, nll(chainValue).substr(1)); | ||
4274 | } | ||
4275 | codes.append(nlr(chainValue)); | ||
4276 | } | ||
4269 | return {nullptr, nullptr, std::move(codes), std::move(localVars)}; | 4277 | return {nullptr, nullptr, std::move(codes), std::move(localVars)}; |
4270 | } else if (type == "text"sv) { | 4278 | } else if (type == "text"sv) { |
4271 | if (!isBlock) { | 4279 | if (!isBlock) { |
4272 | throw std::logic_error(_info.errorMessage("text macro can only be placed where block macro is allowed"sv, x)); | 4280 | throw std::logic_error(_info.errorMessage("text macro can only be placed where block macro is allowed"sv, x)); |
4273 | } | 4281 | } |
4282 | if (!codes.empty()) { | ||
4283 | codes.append(_newLine); | ||
4284 | } | ||
4274 | return {nullptr, nullptr, std::move(codes), std::move(localVars)}; | 4285 | return {nullptr, nullptr, std::move(codes), std::move(localVars)}; |
4275 | } else { | 4286 | } else { |
4276 | if (!codes.empty()) { | 4287 | if (!codes.empty()) { |
@@ -4370,15 +4381,7 @@ private: | |||
4370 | std::string luaCodes; | 4381 | std::string luaCodes; |
4371 | str_list localVars; | 4382 | str_list localVars; |
4372 | std::tie(node, codes, luaCodes, localVars) = expandMacro(chainValue, usage, allowBlockMacroReturn); | 4383 | std::tie(node, codes, luaCodes, localVars) = expandMacro(chainValue, usage, allowBlockMacroReturn); |
4373 | Utils::replace(luaCodes, "\r\n"sv, "\n"sv); | ||
4374 | Utils::trim(luaCodes); | ||
4375 | if (!node) { | 4384 | if (!node) { |
4376 | if (!luaCodes.empty()) { | ||
4377 | if (_config.reserveLineNumber) { | ||
4378 | luaCodes.insert(0, nll(chainValue).substr(1)); | ||
4379 | } | ||
4380 | luaCodes.append(nlr(chainValue)); | ||
4381 | } | ||
4382 | out.push_back(luaCodes); | 4385 | out.push_back(luaCodes); |
4383 | if (!localVars.empty()) { | 4386 | if (!localVars.empty()) { |
4384 | for (const auto& var : localVars) { | 4387 | for (const auto& var : localVars) { |