diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuescript/yue_ast.cpp | 7 | ||||
| -rw-r--r-- | src/yuescript/yue_ast.h | 7 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 8 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 3 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.h | 1 |
5 files changed, 9 insertions, 17 deletions
diff --git a/src/yuescript/yue_ast.cpp b/src/yuescript/yue_ast.cpp index be10859..c4f133b 100644 --- a/src/yuescript/yue_ast.cpp +++ b/src/yuescript/yue_ast.cpp | |||
| @@ -609,15 +609,12 @@ std::string CatchBlock_t::to_string(void* ud) const { | |||
| 609 | info->popScope(); | 609 | info->popScope(); |
| 610 | return line + '\n' + blockStr; | 610 | return line + '\n' + blockStr; |
| 611 | } | 611 | } |
| 612 | std::string Omit_t::to_string(void*) const { | ||
| 613 | return "!"s; | ||
| 614 | } | ||
| 615 | std::string Try_t::to_string(void* ud) const { | 612 | std::string Try_t::to_string(void* ud) const { |
| 616 | auto info = reinterpret_cast<YueFormat*>(ud); | 613 | auto info = reinterpret_cast<YueFormat*>(ud); |
| 617 | str_list temp; | 614 | str_list temp; |
| 618 | temp.emplace_back("try"s); | 615 | temp.emplace_back("try"s); |
| 619 | if (omit) { | 616 | if (eop) { |
| 620 | temp.back() += '!'; | 617 | temp.back() += eop->to_string(ud); |
| 621 | } | 618 | } |
| 622 | if (func.is<Exp_t>()) { | 619 | if (func.is<Exp_t>()) { |
| 623 | temp.back() += (" "s + func->to_string(ud)); | 620 | temp.back() += (" "s + func->to_string(ud)); |
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index 393f374..6bdc31b 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h | |||
| @@ -383,14 +383,11 @@ AST_NODE(CatchBlock) | |||
| 383 | AST_MEMBER(CatchBlock, &err, &block) | 383 | AST_MEMBER(CatchBlock, &err, &block) |
| 384 | AST_END(CatchBlock) | 384 | AST_END(CatchBlock) |
| 385 | 385 | ||
| 386 | AST_LEAF(Omit) | ||
| 387 | AST_END(Omit) | ||
| 388 | |||
| 389 | AST_NODE(Try) | 386 | AST_NODE(Try) |
| 390 | ast_ptr<false, Omit_t> omit; | 387 | ast_ptr<false, ExistentialOp_t> eop; |
| 391 | ast_sel<true, Block_t, Exp_t> func; | 388 | ast_sel<true, Block_t, Exp_t> func; |
| 392 | ast_ptr<false, CatchBlock_t> catchBlock; | 389 | ast_ptr<false, CatchBlock_t> catchBlock; |
| 393 | AST_MEMBER(Try, &omit, &func, &catchBlock) | 390 | AST_MEMBER(Try, &eop, &func, &catchBlock) |
| 394 | AST_END(Try) | 391 | AST_END(Try) |
| 395 | 392 | ||
| 396 | AST_NODE(Comprehension) | 393 | AST_NODE(Comprehension) |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 35745f2..4bac51b 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -78,7 +78,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
| 78 | "close"s // Lua 5.4 | 78 | "close"s // Lua 5.4 |
| 79 | }; | 79 | }; |
| 80 | 80 | ||
| 81 | const std::string_view version = "0.28.6"sv; | 81 | const std::string_view version = "0.28.7"sv; |
| 82 | const std::string_view extension = "yue"sv; | 82 | const std::string_view extension = "yue"sv; |
| 83 | 83 | ||
| 84 | class CompileError : public std::logic_error { | 84 | class CompileError : public std::logic_error { |
| @@ -2332,7 +2332,7 @@ private: | |||
| 2332 | } | 2332 | } |
| 2333 | case id<Try_t>(): { | 2333 | case id<Try_t>(): { |
| 2334 | auto tryNode = static_cast<Try_t*>(value); | 2334 | auto tryNode = static_cast<Try_t*>(value); |
| 2335 | if (tryNode->omit) { | 2335 | if (tryNode->eop) { |
| 2336 | auto assignList = assignment->expList.get(); | 2336 | auto assignList = assignment->expList.get(); |
| 2337 | std::string preDefine = getPreDefineLine(assignment); | 2337 | std::string preDefine = getPreDefineLine(assignment); |
| 2338 | transformTry(tryNode, out, ExpUsage::Assignment, assignList); | 2338 | transformTry(tryNode, out, ExpUsage::Assignment, assignList); |
| @@ -10055,7 +10055,7 @@ private: | |||
| 10055 | 10055 | ||
| 10056 | void transformTry(Try_t* tryNode, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { | 10056 | void transformTry(Try_t* tryNode, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { |
| 10057 | auto x = tryNode; | 10057 | auto x = tryNode; |
| 10058 | if (tryNode->omit && usage == ExpUsage::Assignment) { | 10058 | if (tryNode->eop && usage == ExpUsage::Assignment) { |
| 10059 | str_list rets; | 10059 | str_list rets; |
| 10060 | pushScope(); | 10060 | pushScope(); |
| 10061 | auto okVar = getUnusedName("_ok_"sv); | 10061 | auto okVar = getUnusedName("_ok_"sv); |
| @@ -10080,7 +10080,7 @@ private: | |||
| 10080 | transformAssignment(assignment, out); | 10080 | transformAssignment(assignment, out); |
| 10081 | return; | 10081 | return; |
| 10082 | } | 10082 | } |
| 10083 | if (tryNode->omit && usage != ExpUsage::Common) { | 10083 | if (tryNode->eop && usage != ExpUsage::Common) { |
| 10084 | auto okVar = getUnusedName("_ok_"sv); | 10084 | auto okVar = getUnusedName("_ok_"sv); |
| 10085 | auto code = "do\n\t"s + okVar + ", ... = try nil\n\t... if "s + okVar; | 10085 | auto code = "do\n\t"s + okVar + ", ... = try nil\n\t... if "s + okVar; |
| 10086 | auto doNode = toAst<Do_t>(code, x); | 10086 | auto doNode = toAst<Do_t>(code, x); |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 2b0aea8..0cf7f05 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -501,9 +501,8 @@ YueParser::YueParser() { | |||
| 501 | return true; | 501 | return true; |
| 502 | }); | 502 | }); |
| 503 | 503 | ||
| 504 | Omit = expr('!'); | ||
| 505 | CatchBlock = line_break >> *space_break >> check_indent_match >> space >> key("catch") >> space >> Variable >> space >> in_block; | 504 | CatchBlock = line_break >> *space_break >> check_indent_match >> space >> key("catch") >> space >> Variable >> space >> in_block; |
| 506 | Try = key("try") >> -Omit >> space >> (in_block | Exp) >> -CatchBlock; | 505 | Try = key("try") >> -ExistentialOp >> space >> (in_block | Exp) >> -CatchBlock; |
| 507 | 506 | ||
| 508 | list_value = | 507 | list_value = |
| 509 | and_( | 508 | and_( |
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index 99f3d45..0d9db19 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h | |||
| @@ -347,7 +347,6 @@ private: | |||
| 347 | AST_RULE(ForEach); | 347 | AST_RULE(ForEach); |
| 348 | AST_RULE(Do); | 348 | AST_RULE(Do); |
| 349 | AST_RULE(CatchBlock); | 349 | AST_RULE(CatchBlock); |
| 350 | AST_RULE(Omit); | ||
| 351 | AST_RULE(Try); | 350 | AST_RULE(Try); |
| 352 | AST_RULE(Comprehension); | 351 | AST_RULE(Comprehension); |
| 353 | AST_RULE(CompValue); | 352 | AST_RULE(CompValue); |
