From 6db82a69096a48c8b348217b0db6e06b297218ca Mon Sep 17 00:00:00 2001 From: Li Jin <dragon-fly@qq.com> Date: Wed, 9 Nov 2022 11:30:17 +0800 Subject: refactor and update readme and changelog. --- src/yuescript/yue_compiler.cpp | 9 ++++++--- src/yuescript/yue_parser.cpp | 18 +++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src') 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 { typedef std::list<std::string> str_list; -const std::string_view version = "0.15.11"sv; +const std::string_view version = "0.15.12"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -3769,7 +3769,7 @@ private: if (!_enableReturn.top()) { ast_node* target = returnNode->valueList.get(); if (!target) target = returnNode; - throw std::logic_error(_info.errorMessage("illegal return statement here"sv, target)); + throw std::logic_error(_info.errorMessage("can not mix use of return and export statements in module scope"sv, target)); } if (auto valueList = returnNode->valueList.as<ExpListLow_t>()) { if (valueList->exprs.size() == 1) { @@ -8008,8 +8008,11 @@ private: void transformChainAssign(ChainAssign_t* chainAssign, str_list& out) { auto x = chainAssign; - str_list temp; auto value = chainAssign->assign->values.front(); + if (chainAssign->assign->values.size() != 1) { + throw std::logic_error(_info.errorMessage("only one right value expected"sv, value)); + } + str_list temp; bool constVal = false; if (auto simpleVal = simpleSingleValueFrom(value)) { 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() { return true; }) >> (pl::user(Space >> export_default >> Exp, [](const item_t& item) { State* st = reinterpret_cast<State*>(item.user_data); - bool isValid = !st->exportDefault && st->exportCount == 1; + if (st->exportDefault) { + throw ParserError("export default has already been declared", *item.begin, *item.end); + } + if (st->exportCount > 1) { + throw ParserError("there are items already been exported", *item.begin, *item.end); + } st->exportDefault = true; - return isValid; + return true; }) | (not_(Space >> export_default) >> pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast<State*>(item.user_data); if (st->exportDefault && st->exportCount > 1) { - return false; - } else { - return true; + throw ParserError("can not export more items when export default has been declared", *item.begin, *item.end); } + return true; }) >> ExpList >> -Assign) | Space >> pl::user(Macro, [](const item_t& item) { State* st = reinterpret_cast<State*>(item.user_data); @@ -631,7 +635,7 @@ YueParser::YueParser() { ) | arg_table_block; leading_spaces_error = pl::user(+space_one >> expr('(') >> Exp >> +(sym(',') >> Exp) >> sym(')'), [](const item_t& item) { - throw ParserError("write invoke arguments in parentheses without leading spaces or leading spaces without parentheses", *item.begin, *item.end); + throw ParserError("write invoke arguments in parentheses without leading spaces or just leading spaces without parentheses", *item.begin, *item.end); return false; }); @@ -707,7 +711,7 @@ ParseInfo YueParser::parse(std::string_view codes, rule& r) { res.codes = std::make_unique<input>(); *(res.codes) = _converter.from_bytes(&codes.front(), &codes.back() + 1); } catch (const std::range_error&) { - res.error = "Invalid text encoding."sv; + res.error = "invalid text encoding"sv; return res; } error_list errors; -- cgit v1.2.3-55-g6feb