diff options
| author | Li Jin <dragon-fly@qq.com> | 2023-11-02 12:27:27 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2023-11-02 12:27:27 +0800 |
| commit | 5ad0f4daa8171460dc71332669c365bb8e07dab0 (patch) | |
| tree | da57ecdabf5fa54c324c023ac22c53041aaff143 /src | |
| parent | 2263cca3687bb5c6b9c51f42d59d2249c18941a0 (diff) | |
| download | yuescript-5ad0f4daa8171460dc71332669c365bb8e07dab0.tar.gz yuescript-5ad0f4daa8171460dc71332669c365bb8e07dab0.tar.bz2 yuescript-5ad0f4daa8171460dc71332669c365bb8e07dab0.zip | |
fix table matching syntax in switch statement with list table.v0.20.4
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 648dab2..1733967 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
| 75 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | const std::string_view version = "0.20.3"sv; | 78 | const std::string_view version = "0.20.4"sv; |
| 79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
| 80 | 80 | ||
| 81 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
| @@ -9155,8 +9155,15 @@ private: | |||
| 9155 | for (auto branch_ : branches) { | 9155 | for (auto branch_ : branches) { |
| 9156 | auto branch = static_cast<SwitchCase_t*>(branch_); | 9156 | auto branch = static_cast<SwitchCase_t*>(branch_); |
| 9157 | auto valueList = static_cast<SwitchList_t*>(branch->condition.get()); | 9157 | auto valueList = static_cast<SwitchList_t*>(branch->condition.get()); |
| 9158 | if (auto value = singleValueFrom(valueList); | 9158 | bool tableMatching = false; |
| 9159 | value && (value->item.is<SimpleTable_t>() || value->get_by_path<SimpleValue_t, TableLit_t>())) { | 9159 | if (auto value = singleValueFrom(valueList)) { |
| 9160 | if (value->item.is<SimpleTable_t>()) { | ||
| 9161 | tableMatching = true; | ||
| 9162 | } else if (auto sVal = value->item.as<SimpleValue_t>()){ | ||
| 9163 | tableMatching = ast_is<TableLit_t, Comprehension_t>(sVal->value); | ||
| 9164 | } | ||
| 9165 | } | ||
| 9166 | if (tableMatching) { | ||
| 9160 | if (!firstBranch) { | 9167 | if (!firstBranch) { |
| 9161 | temp.push_back(indent() + "else"s + nll(branch)); | 9168 | temp.push_back(indent() + "else"s + nll(branch)); |
| 9162 | pushScope(); | 9169 | pushScope(); |
