diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-05-16 09:45:04 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-05-16 09:45:27 +0800 |
| commit | a9fe6a5c4c17cf7e8305c1d614939ce510fb1103 (patch) | |
| tree | 404509931668656356cce49493f10e27d1cc32e6 /src | |
| parent | c4935826eea8df7a161b2b4ba9262dce66d9d366 (diff) | |
| download | yuescript-a9fe6a5c4c17cf7e8305c1d614939ce510fb1103.tar.gz yuescript-a9fe6a5c4c17cf7e8305c1d614939ce510fb1103.tar.bz2 yuescript-a9fe6a5c4c17cf7e8305c1d614939ce510fb1103.zip | |
fix issue #97 by line decorator.
Diffstat (limited to '')
| -rwxr-xr-x | src/yuescript/yue_compiler.cpp | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 6f641d9..6d90d24 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.20"sv; | 63 | const std::string_view version = "0.10.21"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 { |
| @@ -925,6 +925,66 @@ private: | |||
| 925 | local->defined = true; | 925 | local->defined = true; |
| 926 | transformLocalDef(local, out); | 926 | transformLocalDef(local, out); |
| 927 | } | 927 | } |
| 928 | } else if (auto attrib = statement->content.as<LocalAttrib_t>()) { | ||
| 929 | auto appendix = statement->appendix.get(); | ||
| 930 | switch (appendix->item->getId()) { | ||
| 931 | case id<if_line_t>(): { | ||
| 932 | auto if_line = static_cast<if_line_t*>(appendix->item.get()); | ||
| 933 | auto ifNode = x->new_ptr<If_t>(); | ||
| 934 | ifNode->type.set(if_line->type); | ||
| 935 | ifNode->nodes.push_back(if_line->condition); | ||
| 936 | |||
| 937 | auto expList = x->new_ptr<ExpList_t>(); | ||
| 938 | for (auto val : attrib->assign->values.objects()) { | ||
| 939 | switch (val->getId()) { | ||
| 940 | case id<If_t>(): | ||
| 941 | case id<Switch_t>(): | ||
| 942 | case id<With_t>(): { | ||
| 943 | auto simpleValue = x->new_ptr<SimpleValue_t>(); | ||
| 944 | simpleValue->value.set(val); | ||
| 945 | auto value = x->new_ptr<Value_t>(); | ||
| 946 | value->item.set(simpleValue); | ||
| 947 | auto exp = newExp(value, x); | ||
| 948 | expList->exprs.push_back(exp); | ||
| 949 | break; | ||
| 950 | } | ||
| 951 | case id<TableBlock_t>(): { | ||
| 952 | auto tableBlock = static_cast<TableBlock_t*>(val); | ||
| 953 | auto tabLit = x->new_ptr<TableLit_t>(); | ||
| 954 | tabLit->values.dup(tableBlock->values); | ||
| 955 | auto simpleValue = x->new_ptr<SimpleValue_t>(); | ||
| 956 | simpleValue->value.set(tabLit); | ||
| 957 | auto value = x->new_ptr<Value_t>(); | ||
| 958 | value->item.set(simpleValue); | ||
| 959 | auto exp = newExp(value, x); | ||
| 960 | expList->exprs.push_back(exp); | ||
| 961 | break; | ||
| 962 | } | ||
| 963 | case id<Exp_t>(): { | ||
| 964 | expList->exprs.push_back(val); | ||
| 965 | break; | ||
| 966 | } | ||
| 967 | default: YUEE("AST node mismatch", val); break; | ||
| 968 | } | ||
| 969 | } | ||
| 970 | auto expListAssign = x->new_ptr<ExpListAssign_t>(); | ||
| 971 | expListAssign->expList.set(expList); | ||
| 972 | auto stmt = x->new_ptr<Statement_t>(); | ||
| 973 | stmt->content.set(expListAssign); | ||
| 974 | ifNode->nodes.push_back(stmt); | ||
| 975 | |||
| 976 | statement->appendix.set(nullptr); | ||
| 977 | attrib->assign->values.clear(); | ||
| 978 | attrib->assign->values.push_back(ifNode); | ||
| 979 | transformStatement(statement, out); | ||
| 980 | return; | ||
| 981 | } | ||
| 982 | case id<CompInner_t>(): { | ||
| 983 | throw std::logic_error(_info.errorMessage("for-loop line decorator is not supported here"sv, appendix->item.get())); | ||
| 984 | break; | ||
| 985 | } | ||
| 986 | default: YUEE("AST node mismatch", appendix->item.get()); break; | ||
| 987 | } | ||
| 928 | } | 988 | } |
| 929 | auto appendix = statement->appendix.get(); | 989 | auto appendix = statement->appendix.get(); |
| 930 | switch (appendix->item->getId()) { | 990 | switch (appendix->item->getId()) { |
| @@ -5345,7 +5405,7 @@ private: | |||
| 5345 | auto continueVar = getUnusedName("_continue_"sv); | 5405 | auto continueVar = getUnusedName("_continue_"sv); |
| 5346 | forceAddToScope(continueVar); | 5406 | forceAddToScope(continueVar); |
| 5347 | _continueVars.push(continueVar); | 5407 | _continueVars.push(continueVar); |
| 5348 | _buf << indent() << "local "sv << conditionVar << nll(body); | 5408 | _buf << indent() << "local "sv << conditionVar << " = false"sv << nll(body); |
| 5349 | _buf << indent() << "local "sv << continueVar << " = false"sv << nll(body); | 5409 | _buf << indent() << "local "sv << continueVar << " = false"sv << nll(body); |
| 5350 | _buf << indent() << "repeat"sv << nll(body); | 5410 | _buf << indent() << "repeat"sv << nll(body); |
| 5351 | pushScope(); | 5411 | pushScope(); |
