aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-02-20 17:34:52 +0800
committerLi Jin <dragon-fly@qq.com>2021-02-20 17:34:52 +0800
commitc44cab60b7b6cf0a36e1dd011c2fe483e8d87b38 (patch)
tree9fcf8a06e63991a27b8f73b4e5040788338d115f /src
parent3ea3f9b1c42eae103c370a986f539a0f1550db9f (diff)
downloadyuescript-c44cab60b7b6cf0a36e1dd011c2fe483e8d87b38.tar.gz
yuescript-c44cab60b7b6cf0a36e1dd011c2fe483e8d87b38.tar.bz2
yuescript-c44cab60b7b6cf0a36e1dd011c2fe483e8d87b38.zip
fix issue in destructure syntax.
Diffstat (limited to 'src')
-rw-r--r--src/yuescript/yue_compiler.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 7be0c84..ebc2b3f 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -58,7 +58,7 @@ inline std::string s(std::string_view sv) {
58 return std::string(sv); 58 return std::string(sv);
59} 59}
60 60
61const std::string_view version = "0.6.7"sv; 61const std::string_view version = "0.6.8"sv;
62const std::string_view extension = "yue"sv; 62const std::string_view extension = "yue"sv;
63 63
64class YueCompilerImpl { 64class YueCompilerImpl {
@@ -1237,7 +1237,7 @@ private:
1237 if (pair.isVariable && !isDefined(pair.name)) { 1237 if (pair.isVariable && !isDefined(pair.name)) {
1238 _buf << s("local "sv); 1238 _buf << s("local "sv);
1239 } 1239 }
1240 _buf << pair.name << " = "sv << info.first.front().value << pair.structure << nll(assignment); 1240 _buf << pair.name << " = "sv << destruct.value << pair.structure << nll(assignment);
1241 addToScope(pair.name); 1241 addToScope(pair.name);
1242 temp.push_back(clearBuf()); 1242 temp.push_back(clearBuf());
1243 } else if (_parser.match<Name_t>(destruct.value)) { 1243 } else if (_parser.match<Name_t>(destruct.value)) {
@@ -1451,6 +1451,13 @@ private:
1451 auto value = singleValueFrom(expr); 1451 auto value = singleValueFrom(expr);
1452 ast_node* destructNode = value->getByPath<SimpleValue_t, TableLit_t>(); 1452 ast_node* destructNode = value->getByPath<SimpleValue_t, TableLit_t>();
1453 if (destructNode || (destructNode = value->item.as<simple_table_t>())) { 1453 if (destructNode || (destructNode = value->item.as<simple_table_t>())) {
1454 if (*j != nullNode) {
1455 if (auto ssVal = simpleSingleValueFrom(*j)) {
1456 if (ssVal->value.is<const_value_t>()) {
1457 throw std::logic_error(_info.errorMessage("can not destruct a const value"sv, ssVal->value));
1458 }
1459 }
1460 }
1454 destructPairs.push_back({i,j}); 1461 destructPairs.push_back({i,j});
1455 auto& destruct = destructs.emplace_back(); 1462 auto& destruct = destructs.emplace_back();
1456 if (!varDefOnly) { 1463 if (!varDefOnly) {
@@ -1462,7 +1469,11 @@ private:
1462 } 1469 }
1463 auto pairs = destructFromExp(expr); 1470 auto pairs = destructFromExp(expr);
1464 destruct.items = std::move(pairs); 1471 destruct.items = std::move(pairs);
1465 if (destruct.items.size() == 1 && !singleValueFrom(*j)) { 1472 if (*j == nullNode) {
1473 for (auto& item : destruct.items) {
1474 item.structure.clear();
1475 }
1476 } else if (destruct.items.size() == 1 && !singleValueFrom(*j)) {
1466 destruct.value.insert(0, "("sv); 1477 destruct.value.insert(0, "("sv);
1467 destruct.value.append(")"sv); 1478 destruct.value.append(")"sv);
1468 } 1479 }