aboutsummaryrefslogtreecommitdiff
path: root/src/yuescript/yue_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
-rw-r--r--src/yuescript/yue_parser.cpp18
1 files changed, 11 insertions, 7 deletions
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;