diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-04-19 18:10:08 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-04-19 18:10:08 +0800 |
| commit | 7ac784e73b026ce7e17babb2f0b819864fd898b0 (patch) | |
| tree | 244a39123a4789a04fb577d6956bdb461509a153 /src/yuescript/yue_compiler.cpp | |
| parent | ce9f6632635222b38ef0b37b4b1273da4a1877b4 (diff) | |
| download | yuescript-7ac784e73b026ce7e17babb2f0b819864fd898b0.tar.gz yuescript-7ac784e73b026ce7e17babb2f0b819864fd898b0.tar.bz2 yuescript-7ac784e73b026ce7e17babb2f0b819864fd898b0.zip | |
rename BackcallOperator to PipeOperator.
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index caa5b9e..85744d5 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -59,7 +59,7 @@ inline std::string s(std::string_view sv) { | |||
| 59 | return std::string(sv); | 59 | return std::string(sv); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | const std::string_view version = "0.7.6"sv; | 62 | const std::string_view version = "0.7.7"sv; |
| 63 | const std::string_view extension = "yue"sv; | 63 | const std::string_view extension = "yue"sv; |
| 64 | 64 | ||
| 65 | class YueCompilerImpl { | 65 | class YueCompilerImpl { |
| @@ -467,8 +467,8 @@ private: | |||
| 467 | if (!exp) return nullptr; | 467 | if (!exp) return nullptr; |
| 468 | BLOCK_START | 468 | BLOCK_START |
| 469 | BREAK_IF(!exp->opValues.empty()); | 469 | BREAK_IF(!exp->opValues.empty()); |
| 470 | BREAK_IF(exp->backcalls.size() != 1); | 470 | BREAK_IF(exp->pipeExprs.size() != 1); |
| 471 | auto unary = static_cast<unary_exp_t*>(exp->backcalls.back()); | 471 | auto unary = static_cast<unary_exp_t*>(exp->pipeExprs.back()); |
| 472 | BREAK_IF(unary->expos.size() != 1); | 472 | BREAK_IF(unary->expos.size() != 1); |
| 473 | return unary; | 473 | return unary; |
| 474 | BLOCK_END | 474 | BLOCK_END |
| @@ -488,7 +488,7 @@ private: | |||
| 488 | auto unary = x->new_ptr<unary_exp_t>(); | 488 | auto unary = x->new_ptr<unary_exp_t>(); |
| 489 | unary->expos.push_back(value); | 489 | unary->expos.push_back(value); |
| 490 | auto exp = x->new_ptr<Exp_t>(); | 490 | auto exp = x->new_ptr<Exp_t>(); |
| 491 | exp->backcalls.push_back(unary); | 491 | exp->pipeExprs.push_back(unary); |
| 492 | return exp; | 492 | return exp; |
| 493 | } | 493 | } |
| 494 | 494 | ||
| @@ -500,17 +500,17 @@ private: | |||
| 500 | auto runary = x->new_ptr<unary_exp_t>(); | 500 | auto runary = x->new_ptr<unary_exp_t>(); |
| 501 | runary->expos.push_back(right); | 501 | runary->expos.push_back(right); |
| 502 | opValue->op.set(op); | 502 | opValue->op.set(op); |
| 503 | opValue->backcalls.push_back(runary); | 503 | opValue->pipeExprs.push_back(runary); |
| 504 | } | 504 | } |
| 505 | auto exp = x->new_ptr<Exp_t>(); | 505 | auto exp = x->new_ptr<Exp_t>(); |
| 506 | exp->backcalls.push_back(lunary); | 506 | exp->pipeExprs.push_back(lunary); |
| 507 | exp->opValues.push_back(opValue); | 507 | exp->opValues.push_back(opValue); |
| 508 | return exp; | 508 | return exp; |
| 509 | } | 509 | } |
| 510 | 510 | ||
| 511 | ast_ptr<false, Exp_t> newExp(unary_exp_t* unary, ast_node* x) { | 511 | ast_ptr<false, Exp_t> newExp(unary_exp_t* unary, ast_node* x) { |
| 512 | auto exp = x->new_ptr<Exp_t>(); | 512 | auto exp = x->new_ptr<Exp_t>(); |
| 513 | exp->backcalls.push_back(unary); | 513 | exp->pipeExprs.push_back(unary); |
| 514 | return exp; | 514 | return exp; |
| 515 | } | 515 | } |
| 516 | 516 | ||
| @@ -785,7 +785,7 @@ private: | |||
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | bool isPureBackcall(Exp_t* exp) const { | 787 | bool isPureBackcall(Exp_t* exp) const { |
| 788 | return exp->opValues.empty() && exp->backcalls.size() > 1; | 788 | return exp->opValues.empty() && exp->pipeExprs.size() > 1; |
| 789 | } | 789 | } |
| 790 | 790 | ||
| 791 | bool isMacroChain(ChainValue_t* chainValue) const { | 791 | bool isMacroChain(ChainValue_t* chainValue) const { |
| @@ -923,7 +923,7 @@ private: | |||
| 923 | case id<Label_t>(): transformLabel(static_cast<Label_t*>(content), out); break; | 923 | case id<Label_t>(): transformLabel(static_cast<Label_t*>(content), out); break; |
| 924 | case id<Goto_t>(): transformGoto(static_cast<Goto_t*>(content), out); break; | 924 | case id<Goto_t>(): transformGoto(static_cast<Goto_t*>(content), out); break; |
| 925 | case id<LocalAttrib_t>(): transformLocalAttrib(static_cast<LocalAttrib_t*>(content), out); break; | 925 | case id<LocalAttrib_t>(): transformLocalAttrib(static_cast<LocalAttrib_t*>(content), out); break; |
| 926 | case id<BackcallBody_t>(): throw std::logic_error(_info.errorMessage("backcall chain must be following a value"sv, x)); break; | 926 | case id<PipeBody_t>(): throw std::logic_error(_info.errorMessage("pipe chain must be following a value"sv, x)); break; |
| 927 | case id<ExpListAssign_t>(): { | 927 | case id<ExpListAssign_t>(): { |
| 928 | auto expListAssign = static_cast<ExpListAssign_t*>(content); | 928 | auto expListAssign = static_cast<ExpListAssign_t*>(content); |
| 929 | if (expListAssign->action) { | 929 | if (expListAssign->action) { |
| @@ -1955,7 +1955,7 @@ private: | |||
| 1955 | out.push_back(join(temp, ", "sv)); | 1955 | out.push_back(join(temp, ", "sv)); |
| 1956 | } | 1956 | } |
| 1957 | 1957 | ||
| 1958 | void transform_backcall_exp(const node_container& values, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { | 1958 | void transform_pipe_exp(const node_container& values, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { |
| 1959 | if (values.size() == 1 && usage == ExpUsage::Closure) { | 1959 | if (values.size() == 1 && usage == ExpUsage::Closure) { |
| 1960 | transform_unary_exp(static_cast<unary_exp_t*>(values.front()), out); | 1960 | transform_unary_exp(static_cast<unary_exp_t*>(values.front()), out); |
| 1961 | } else { | 1961 | } else { |
| @@ -1968,7 +1968,7 @@ private: | |||
| 1968 | if (values.back() == *it && !unary->ops.empty() && usage == ExpUsage::Common) { | 1968 | if (values.back() == *it && !unary->ops.empty() && usage == ExpUsage::Common) { |
| 1969 | throw std::logic_error(_info.errorMessage("expression list is not supported here"sv, x)); | 1969 | throw std::logic_error(_info.errorMessage("expression list is not supported here"sv, x)); |
| 1970 | } | 1970 | } |
| 1971 | if (!value) throw std::logic_error(_info.errorMessage("backcall operator must be followed by chain value"sv, *it)); | 1971 | if (!value) throw std::logic_error(_info.errorMessage("pipe operator must be followed by chain value"sv, *it)); |
| 1972 | if (auto chainValue = value->item.as<ChainValue_t>()) { | 1972 | if (auto chainValue = value->item.as<ChainValue_t>()) { |
| 1973 | if (isChainValueCall(chainValue)) { | 1973 | if (isChainValueCall(chainValue)) { |
| 1974 | auto last = chainValue->items.back(); | 1974 | auto last = chainValue->items.back(); |
| @@ -1989,7 +1989,7 @@ private: | |||
| 1989 | args->swap(a, arg); | 1989 | args->swap(a, arg); |
| 1990 | findPlaceHolder = true; | 1990 | findPlaceHolder = true; |
| 1991 | } else { | 1991 | } else { |
| 1992 | throw std::logic_error(_info.errorMessage("backcall placeholder can be used only in one place"sv, a)); | 1992 | throw std::logic_error(_info.errorMessage("pipe placeholder can be used only in one place"sv, a)); |
| 1993 | } | 1993 | } |
| 1994 | } | 1994 | } |
| 1995 | } | 1995 | } |
| @@ -2003,7 +2003,7 @@ private: | |||
| 2003 | } | 2003 | } |
| 2004 | arg.set(newExp(unary, x)); | 2004 | arg.set(newExp(unary, x)); |
| 2005 | } else { | 2005 | } else { |
| 2006 | throw std::logic_error(_info.errorMessage("backcall operator must be followed by chain value"sv, value)); | 2006 | throw std::logic_error(_info.errorMessage("pipe operator must be followed by chain value"sv, value)); |
| 2007 | } | 2007 | } |
| 2008 | } | 2008 | } |
| 2009 | switch (usage) { | 2009 | switch (usage) { |
| @@ -2046,18 +2046,18 @@ private: | |||
| 2046 | 2046 | ||
| 2047 | void transformExp(Exp_t* exp, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { | 2047 | void transformExp(Exp_t* exp, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { |
| 2048 | if (exp->opValues.empty()) { | 2048 | if (exp->opValues.empty()) { |
| 2049 | transform_backcall_exp(exp->backcalls.objects(), out, usage, assignList); | 2049 | transform_pipe_exp(exp->pipeExprs.objects(), out, usage, assignList); |
| 2050 | return; | 2050 | return; |
| 2051 | } | 2051 | } |
| 2052 | if (usage != ExpUsage::Closure) { | 2052 | if (usage != ExpUsage::Closure) { |
| 2053 | YUEE("invalid expression usage", exp); | 2053 | YUEE("invalid expression usage", exp); |
| 2054 | } | 2054 | } |
| 2055 | str_list temp; | 2055 | str_list temp; |
| 2056 | transform_backcall_exp(exp->backcalls.objects(), temp, ExpUsage::Closure); | 2056 | transform_pipe_exp(exp->pipeExprs.objects(), temp, ExpUsage::Closure); |
| 2057 | for (auto _opValue : exp->opValues.objects()) { | 2057 | for (auto _opValue : exp->opValues.objects()) { |
| 2058 | auto opValue = static_cast<exp_op_value_t*>(_opValue); | 2058 | auto opValue = static_cast<exp_op_value_t*>(_opValue); |
| 2059 | transformBinaryOperator(opValue->op, temp); | 2059 | transformBinaryOperator(opValue->op, temp); |
| 2060 | transform_backcall_exp(opValue->backcalls.objects(), temp, ExpUsage::Closure); | 2060 | transform_pipe_exp(opValue->pipeExprs.objects(), temp, ExpUsage::Closure); |
| 2061 | } | 2061 | } |
| 2062 | out.push_back(join(temp, " "sv)); | 2062 | out.push_back(join(temp, " "sv)); |
| 2063 | } | 2063 | } |
| @@ -2206,7 +2206,7 @@ private: | |||
| 2206 | for (auto it = nodes.begin(); it != nodes.end(); ++it) { | 2206 | for (auto it = nodes.begin(); it != nodes.end(); ++it) { |
| 2207 | auto node = *it; | 2207 | auto node = *it; |
| 2208 | auto stmt = static_cast<Statement_t*>(node); | 2208 | auto stmt = static_cast<Statement_t*>(node); |
| 2209 | if (auto backcallBody = stmt->content.as<BackcallBody_t>()) { | 2209 | if (auto pipeBody = stmt->content.as<PipeBody_t>()) { |
| 2210 | auto x = stmt; | 2210 | auto x = stmt; |
| 2211 | bool cond = false; | 2211 | bool cond = false; |
| 2212 | BLOCK_START | 2212 | BLOCK_START |
| @@ -2214,7 +2214,7 @@ private: | |||
| 2214 | auto last = it; --last; | 2214 | auto last = it; --last; |
| 2215 | auto lst = static_cast<Statement_t*>(*last); | 2215 | auto lst = static_cast<Statement_t*>(*last); |
| 2216 | if (lst->appendix) { | 2216 | if (lst->appendix) { |
| 2217 | throw std::logic_error(_info.errorMessage("statement decorator must be placed at the end of backcall chain"sv, lst->appendix.get())); | 2217 | throw std::logic_error(_info.errorMessage("statement decorator must be placed at the end of pipe chain"sv, lst->appendix.get())); |
| 2218 | } | 2218 | } |
| 2219 | lst->appendix.set(stmt->appendix); | 2219 | lst->appendix.set(stmt->appendix); |
| 2220 | stmt->appendix.set(nullptr); | 2220 | stmt->appendix.set(nullptr); |
| @@ -2222,18 +2222,18 @@ private: | |||
| 2222 | stmt->needSep.set(nullptr); | 2222 | stmt->needSep.set(nullptr); |
| 2223 | auto exp = lastExpFromStatement(lst); | 2223 | auto exp = lastExpFromStatement(lst); |
| 2224 | BREAK_IF(!exp); | 2224 | BREAK_IF(!exp); |
| 2225 | for (auto val : backcallBody->values.objects()) { | 2225 | for (auto val : pipeBody->values.objects()) { |
| 2226 | exp->backcalls.push_back(val); | 2226 | exp->pipeExprs.push_back(val); |
| 2227 | } | 2227 | } |
| 2228 | cond = true; | 2228 | cond = true; |
| 2229 | BLOCK_END | 2229 | BLOCK_END |
| 2230 | if (!cond) throw std::logic_error(_info.errorMessage("backcall chain must be following a value"sv, x)); | 2230 | if (!cond) throw std::logic_error(_info.errorMessage("pipe chain must be following a value"sv, x)); |
| 2231 | stmt->content.set(nullptr); | 2231 | stmt->content.set(nullptr); |
| 2232 | auto next = it; ++next; | 2232 | auto next = it; ++next; |
| 2233 | BLOCK_START | 2233 | BLOCK_START |
| 2234 | BREAK_IF(next == nodes.end()); | 2234 | BREAK_IF(next == nodes.end()); |
| 2235 | BREAK_IF(!static_cast<Statement_t*>(*next)->content.as<BackcallBody_t>()); | 2235 | BREAK_IF(!static_cast<Statement_t*>(*next)->content.as<PipeBody_t>()); |
| 2236 | throw std::logic_error(_info.errorMessage("indent mismatch in backcall chain"sv, *next)); | 2236 | throw std::logic_error(_info.errorMessage("indent mismatch in pipe chain"sv, *next)); |
| 2237 | BLOCK_END | 2237 | BLOCK_END |
| 2238 | } else if (auto backcall = stmt->content.as<Backcall_t>()) { | 2238 | } else if (auto backcall = stmt->content.as<Backcall_t>()) { |
| 2239 | auto x = *nodes.begin(); | 2239 | auto x = *nodes.begin(); |
| @@ -3513,7 +3513,7 @@ private: | |||
| 3513 | for (auto arg : *args) { | 3513 | for (auto arg : *args) { |
| 3514 | std::string str; | 3514 | std::string str; |
| 3515 | // check whether arg is reassembled | 3515 | // check whether arg is reassembled |
| 3516 | // do some workaround for backcall expression | 3516 | // do some workaround for pipe expression |
| 3517 | if (ast_is<Exp_t>(arg) && arg->m_begin.m_it == arg->m_end.m_it) { | 3517 | if (ast_is<Exp_t>(arg) && arg->m_begin.m_it == arg->m_end.m_it) { |
| 3518 | auto exp = static_cast<Exp_t*>(arg); | 3518 | auto exp = static_cast<Exp_t*>(arg); |
| 3519 | BLOCK_START | 3519 | BLOCK_START |
| @@ -3525,10 +3525,10 @@ private: | |||
| 3525 | str = std::get<1>(expandMacroStr(chainValue)); | 3525 | str = std::get<1>(expandMacroStr(chainValue)); |
| 3526 | BLOCK_END | 3526 | BLOCK_END |
| 3527 | if (str.empty()) { | 3527 | if (str.empty()) { |
| 3528 | // exp is reassembled due to backcall expressions | 3528 | // exp is reassembled due to pipe expressions |
| 3529 | // in transform stage, toString(exp) won't be able | 3529 | // in transform stage, toString(exp) won't be able |
| 3530 | // to convert its whole text content | 3530 | // to convert its whole text content |
| 3531 | str = _parser.toString(exp->backcalls.front()); | 3531 | str = _parser.toString(exp->pipeExprs.front()); |
| 3532 | } | 3532 | } |
| 3533 | } else if (auto lstr = ast_cast<LuaString_t>(arg)) { | 3533 | } else if (auto lstr = ast_cast<LuaString_t>(arg)) { |
| 3534 | str = _parser.toString(lstr->content); | 3534 | str = _parser.toString(lstr->content); |
