diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-10-31 11:32:33 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-11-09 11:29:32 +0800 |
| commit | 417ec1a37922c6178900adfec70628cad46731ff (patch) | |
| tree | a5a2d74927ad2c41b5a16264a78409e1c0334b72 /src/yuescript/yue_compiler.cpp | |
| parent | 3dd607c8887d2fe0186668aabca31bb84a41e2da (diff) | |
| download | yuescript-417ec1a37922c6178900adfec70628cad46731ff.tar.gz yuescript-417ec1a37922c6178900adfec70628cad46731ff.tar.bz2 yuescript-417ec1a37922c6178900adfec70628cad46731ff.zip | |
fix issue #112 and issue #113.
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index ff55e0e..22a4a02 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -60,7 +60,7 @@ namespace yue { | |||
| 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.15.6"sv; | 63 | const std::string_view version = "0.15.7"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 { |
| @@ -1130,6 +1130,10 @@ private: | |||
| 1130 | transformStatement(statement, out); | 1130 | transformStatement(statement, out); |
| 1131 | return; | 1131 | return; |
| 1132 | } | 1132 | } |
| 1133 | case id<while_line_t>(): { | ||
| 1134 | throw std::logic_error(_info.errorMessage("while-loop line decorator is not supported here"sv, appendix->item.get())); | ||
| 1135 | break; | ||
| 1136 | } | ||
| 1133 | case id<CompInner_t>(): { | 1137 | case id<CompInner_t>(): { |
| 1134 | throw std::logic_error(_info.errorMessage("for-loop line decorator is not supported here"sv, appendix->item.get())); | 1138 | throw std::logic_error(_info.errorMessage("for-loop line decorator is not supported here"sv, appendix->item.get())); |
| 1135 | break; | 1139 | break; |
| @@ -1160,6 +1164,27 @@ private: | |||
| 1160 | statement->content.set(expListAssign); | 1164 | statement->content.set(expListAssign); |
| 1161 | break; | 1165 | break; |
| 1162 | } | 1166 | } |
| 1167 | case id<while_line_t>(): { | ||
| 1168 | auto while_line = static_cast<while_line_t*>(appendix->item.get()); | ||
| 1169 | auto whileNode = x->new_ptr<While_t>(); | ||
| 1170 | whileNode->type.set(while_line->type); | ||
| 1171 | whileNode->condition.set(while_line->condition); | ||
| 1172 | |||
| 1173 | auto stmt = x->new_ptr<Statement_t>(); | ||
| 1174 | stmt->content.set(statement->content); | ||
| 1175 | whileNode->body.set(stmt); | ||
| 1176 | |||
| 1177 | statement->appendix.set(nullptr); | ||
| 1178 | auto simpleValue = x->new_ptr<SimpleValue_t>(); | ||
| 1179 | simpleValue->value.set(whileNode); | ||
| 1180 | auto exp = newExp(simpleValue, x); | ||
| 1181 | auto expList = x->new_ptr<ExpList_t>(); | ||
| 1182 | expList->exprs.push_back(exp); | ||
| 1183 | auto expListAssign = x->new_ptr<ExpListAssign_t>(); | ||
| 1184 | expListAssign->expList.set(expList); | ||
| 1185 | statement->content.set(expListAssign); | ||
| 1186 | break; | ||
| 1187 | } | ||
| 1163 | case id<CompInner_t>(): { | 1188 | case id<CompInner_t>(): { |
| 1164 | auto compInner = appendix->item.to<CompInner_t>(); | 1189 | auto compInner = appendix->item.to<CompInner_t>(); |
| 1165 | auto comp = x->new_ptr<Comprehension_t>(); | 1190 | auto comp = x->new_ptr<Comprehension_t>(); |
| @@ -3445,7 +3470,8 @@ private: | |||
| 3445 | BREAK_IF(!last); | 3470 | BREAK_IF(!last); |
| 3446 | auto x = last; | 3471 | auto x = last; |
| 3447 | auto expList = expListFrom(last); | 3472 | auto expList = expListFrom(last); |
| 3448 | BREAK_IF(!expList || (last->appendix && last->appendix->item.is<CompInner_t>())); | 3473 | BREAK_IF(!expList); |
| 3474 | BREAK_IF(last->appendix && !last->appendix->item.is<if_line_t>()); | ||
| 3449 | auto expListLow = x->new_ptr<ExpListLow_t>(); | 3475 | auto expListLow = x->new_ptr<ExpListLow_t>(); |
| 3450 | expListLow->exprs.dup(expList->exprs); | 3476 | expListLow->exprs.dup(expList->exprs); |
| 3451 | auto returnNode = x->new_ptr<Return_t>(); | 3477 | auto returnNode = x->new_ptr<Return_t>(); |
| @@ -5100,7 +5126,9 @@ private: | |||
| 5100 | } | 5126 | } |
| 5101 | 5127 | ||
| 5102 | void transformNum(Num_t* num, str_list& out) { | 5128 | void transformNum(Num_t* num, str_list& out) { |
| 5103 | out.push_back(_parser.toString(num)); | 5129 | std::string numStr = _parser.toString(num); |
| 5130 | numStr.erase(std::remove(numStr.begin(), numStr.end(), '_'), numStr.end()); | ||
| 5131 | out.push_back(numStr); | ||
| 5104 | } | 5132 | } |
| 5105 | 5133 | ||
| 5106 | bool hasSpreadExp(const node_container& items) { | 5134 | bool hasSpreadExp(const node_container& items) { |
