diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 9 | ||||
-rw-r--r-- | src/yuescript/yue_parser.cpp | 18 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 4072974..f5436d1 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -59,7 +59,7 @@ namespace yue { | |||
59 | 59 | ||
60 | typedef std::list<std::string> str_list; | 60 | typedef std::list<std::string> str_list; |
61 | 61 | ||
62 | const std::string_view version = "0.15.11"sv; | 62 | const std::string_view version = "0.15.12"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 { |
@@ -3769,7 +3769,7 @@ private: | |||
3769 | if (!_enableReturn.top()) { | 3769 | if (!_enableReturn.top()) { |
3770 | ast_node* target = returnNode->valueList.get(); | 3770 | ast_node* target = returnNode->valueList.get(); |
3771 | if (!target) target = returnNode; | 3771 | if (!target) target = returnNode; |
3772 | throw std::logic_error(_info.errorMessage("illegal return statement here"sv, target)); | 3772 | throw std::logic_error(_info.errorMessage("can not mix use of return and export statements in module scope"sv, target)); |
3773 | } | 3773 | } |
3774 | if (auto valueList = returnNode->valueList.as<ExpListLow_t>()) { | 3774 | if (auto valueList = returnNode->valueList.as<ExpListLow_t>()) { |
3775 | if (valueList->exprs.size() == 1) { | 3775 | if (valueList->exprs.size() == 1) { |
@@ -8008,8 +8008,11 @@ private: | |||
8008 | 8008 | ||
8009 | void transformChainAssign(ChainAssign_t* chainAssign, str_list& out) { | 8009 | void transformChainAssign(ChainAssign_t* chainAssign, str_list& out) { |
8010 | auto x = chainAssign; | 8010 | auto x = chainAssign; |
8011 | str_list temp; | ||
8012 | auto value = chainAssign->assign->values.front(); | 8011 | auto value = chainAssign->assign->values.front(); |
8012 | if (chainAssign->assign->values.size() != 1) { | ||
8013 | throw std::logic_error(_info.errorMessage("only one right value expected"sv, value)); | ||
8014 | } | ||
8015 | str_list temp; | ||
8013 | bool constVal = false; | 8016 | bool constVal = false; |
8014 | if (auto simpleVal = simpleSingleValueFrom(value)) { | 8017 | if (auto simpleVal = simpleSingleValueFrom(value)) { |
8015 | constVal = ast_is<const_value_t, Num_t>(simpleVal->value); | 8018 | constVal = ast_is<const_value_t, Num_t>(simpleVal->value); |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index b1f29a9..c8b974f 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -532,17 +532,21 @@ YueParser::YueParser() { | |||
532 | return true; | 532 | return true; |
533 | }) >> (pl::user(Space >> export_default >> Exp, [](const item_t& item) { | 533 | }) >> (pl::user(Space >> export_default >> Exp, [](const item_t& item) { |
534 | State* st = reinterpret_cast<State*>(item.user_data); | 534 | State* st = reinterpret_cast<State*>(item.user_data); |
535 | bool isValid = !st->exportDefault && st->exportCount == 1; | 535 | if (st->exportDefault) { |
536 | throw ParserError("export default has already been declared", *item.begin, *item.end); | ||
537 | } | ||
538 | if (st->exportCount > 1) { | ||
539 | throw ParserError("there are items already been exported", *item.begin, *item.end); | ||
540 | } | ||
536 | st->exportDefault = true; | 541 | st->exportDefault = true; |
537 | return isValid; | 542 | return true; |
538 | }) | 543 | }) |
539 | | (not_(Space >> export_default) >> pl::user(true_(), [](const item_t& item) { | 544 | | (not_(Space >> export_default) >> pl::user(true_(), [](const item_t& item) { |
540 | State* st = reinterpret_cast<State*>(item.user_data); | 545 | State* st = reinterpret_cast<State*>(item.user_data); |
541 | if (st->exportDefault && st->exportCount > 1) { | 546 | if (st->exportDefault && st->exportCount > 1) { |
542 | return false; | 547 | throw ParserError("can not export more items when export default has been declared", *item.begin, *item.end); |
543 | } else { | ||
544 | return true; | ||
545 | } | 548 | } |
549 | return true; | ||
546 | }) >> ExpList >> -Assign) | 550 | }) >> ExpList >> -Assign) |
547 | | Space >> pl::user(Macro, [](const item_t& item) { | 551 | | Space >> pl::user(Macro, [](const item_t& item) { |
548 | State* st = reinterpret_cast<State*>(item.user_data); | 552 | State* st = reinterpret_cast<State*>(item.user_data); |
@@ -631,7 +635,7 @@ YueParser::YueParser() { | |||
631 | ) | arg_table_block; | 635 | ) | arg_table_block; |
632 | 636 | ||
633 | leading_spaces_error = pl::user(+space_one >> expr('(') >> Exp >> +(sym(',') >> Exp) >> sym(')'), [](const item_t& item) { | 637 | leading_spaces_error = pl::user(+space_one >> expr('(') >> Exp >> +(sym(',') >> Exp) >> sym(')'), [](const item_t& item) { |
634 | throw ParserError("write invoke arguments in parentheses without leading spaces or leading spaces without parentheses", *item.begin, *item.end); | 638 | throw ParserError("write invoke arguments in parentheses without leading spaces or just leading spaces without parentheses", *item.begin, *item.end); |
635 | return false; | 639 | return false; |
636 | }); | 640 | }); |
637 | 641 | ||
@@ -707,7 +711,7 @@ ParseInfo YueParser::parse(std::string_view codes, rule& r) { | |||
707 | res.codes = std::make_unique<input>(); | 711 | res.codes = std::make_unique<input>(); |
708 | *(res.codes) = _converter.from_bytes(&codes.front(), &codes.back() + 1); | 712 | *(res.codes) = _converter.from_bytes(&codes.front(), &codes.back() + 1); |
709 | } catch (const std::range_error&) { | 713 | } catch (const std::range_error&) { |
710 | res.error = "Invalid text encoding."sv; | 714 | res.error = "invalid text encoding"sv; |
711 | return res; | 715 | return res; |
712 | } | 716 | } |
713 | error_list errors; | 717 | error_list errors; |