diff options
Diffstat (limited to '')
| -rw-r--r-- | src/MoonP/moon_compiler.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index ca0ab5b..020e561 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
| @@ -426,20 +426,31 @@ private: | |||
| 426 | return ast_is<InvokeArgs_t, Invoke_t>(chainValue->items.back()); | 426 | return ast_is<InvokeArgs_t, Invoke_t>(chainValue->items.back()); |
| 427 | } | 427 | } |
| 428 | 428 | ||
| 429 | bool isSpecialChainValue(ChainValue_t* chainValue) { | 429 | enum class ChainType { |
| 430 | Common, | ||
| 431 | EndWithColon, | ||
| 432 | EndWithEOP, | ||
| 433 | HasEOP, | ||
| 434 | HasKeyword | ||
| 435 | }; | ||
| 436 | |||
| 437 | ChainType specialChainValue(ChainValue_t* chainValue) { | ||
| 430 | if (ast_is<ColonChainItem_t>(chainValue->items.back())) { | 438 | if (ast_is<ColonChainItem_t>(chainValue->items.back())) { |
| 431 | return true; | 439 | return ChainType::EndWithColon; |
| 440 | } | ||
| 441 | if (ast_is<existential_op_t>(chainValue->items.back())) { | ||
| 442 | return ChainType::EndWithEOP; | ||
| 432 | } | 443 | } |
| 433 | for (auto item : chainValue->items.objects()) { | 444 | for (auto item : chainValue->items.objects()) { |
| 434 | if (auto colonChain = ast_cast<ColonChainItem_t>(item)) { | 445 | if (auto colonChain = ast_cast<ColonChainItem_t>(item)) { |
| 435 | if (ast_is<LuaKeyword_t>(colonChain->name)) { | 446 | if (ast_is<LuaKeyword_t>(colonChain->name)) { |
| 436 | return true; | 447 | return ChainType::HasKeyword; |
| 437 | } | 448 | } |
| 438 | } else if (ast_is<existential_op_t>(item) && item != chainValue->items.back()) { | 449 | } else if (ast_is<existential_op_t>(item) && item != chainValue->items.back()) { |
| 439 | return true; | 450 | return ChainType::HasEOP; |
| 440 | } | 451 | } |
| 441 | } | 452 | } |
| 442 | return false; | 453 | return ChainType::Common; |
| 443 | } | 454 | } |
| 444 | 455 | ||
| 445 | std::string singleVariableFrom(ChainValue_t* chainValue) { | 456 | std::string singleVariableFrom(ChainValue_t* chainValue) { |
| @@ -998,16 +1009,22 @@ private: | |||
| 998 | auto exp = ast_cast<Exp_t>(value); | 1009 | auto exp = ast_cast<Exp_t>(value); |
| 999 | BREAK_IF(!exp); | 1010 | BREAK_IF(!exp); |
| 1000 | if (auto chainValue = exp->value->item.as<ChainValue_t>()) { | 1011 | if (auto chainValue = exp->value->item.as<ChainValue_t>()) { |
| 1001 | if (isSpecialChainValue(chainValue)) { | 1012 | auto type = specialChainValue(chainValue); |
| 1002 | auto expList = assignment->expList.get(); | 1013 | auto expList = assignment->expList.get(); |
| 1003 | if (ast_is<ColonChainItem_t>(chainValue->items.back())) { | 1014 | switch (type) { |
| 1015 | case ChainType::HasEOP: | ||
| 1016 | case ChainType::EndWithColon: { | ||
| 1004 | std::string preDefine = getPredefine(assignment); | 1017 | std::string preDefine = getPredefine(assignment); |
| 1005 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList); | 1018 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList); |
| 1006 | out.back().insert(0, preDefine.empty() ? Empty : preDefine + nll(assignment)); | 1019 | out.back().insert(0, preDefine.empty() ? Empty : preDefine + nll(assignment)); |
| 1007 | } else { | 1020 | return; |
| 1008 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList); | ||
| 1009 | } | 1021 | } |
| 1010 | return; | 1022 | case ChainType::HasKeyword: |
| 1023 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList); | ||
| 1024 | return; | ||
| 1025 | case ChainType::Common: | ||
| 1026 | case ChainType::EndWithEOP: | ||
| 1027 | break; | ||
| 1011 | } | 1028 | } |
| 1012 | } | 1029 | } |
| 1013 | BLOCK_END | 1030 | BLOCK_END |
| @@ -1858,7 +1875,7 @@ private: | |||
| 1858 | } | 1875 | } |
| 1859 | } | 1876 | } |
| 1860 | if (auto chainValue = singleValue->item.as<ChainValue_t>()) { | 1877 | if (auto chainValue = singleValue->item.as<ChainValue_t>()) { |
| 1861 | if (isSpecialChainValue(chainValue)) { | 1878 | if (specialChainValue(chainValue) != ChainType::Common) { |
| 1862 | transformChainValue(chainValue, out, ExpUsage::Return); | 1879 | transformChainValue(chainValue, out, ExpUsage::Return); |
| 1863 | return; | 1880 | return; |
| 1864 | } | 1881 | } |
