aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/yuescript/yue_ast.h7
-rw-r--r--src/yuescript/yue_compiler.cpp23
-rw-r--r--src/yuescript/yue_parser.cpp9
-rw-r--r--src/yuescript/yue_parser.h1
4 files changed, 25 insertions, 15 deletions
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index fa47559..6b2b7f8 100644
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -302,14 +302,15 @@ AST_NODE(Switch)
302AST_END(Switch, "switch"sv) 302AST_END(Switch, "switch"sv)
303 303
304AST_NODE(Assignment) 304AST_NODE(Assignment)
305 ast_ptr<true, ExpList_t> expList; 305 ast_ptr<false, ExpList_t> expList;
306 ast_ptr<true, Assign_t> assign; 306 ast_ptr<true, Assign_t> assign;
307 AST_MEMBER(Assignment, &expList, &assign) 307 AST_MEMBER(Assignment, &expList, &assign)
308AST_END(Assignment, "assignment"sv) 308AST_END(Assignment, "assignment"sv)
309 309
310AST_NODE(IfCond) 310AST_NODE(IfCond)
311 ast_sel<true, Exp_t, Assignment_t> condition; 311 ast_ptr<true, Exp_t> condition;
312 AST_MEMBER(IfCond, &condition) 312 ast_ptr<false, Assignment_t> assignment;
313 AST_MEMBER(IfCond, &condition, &assignment)
313AST_END(IfCond, "if_cond"sv) 314AST_END(IfCond, "if_cond"sv)
314 315
315AST_LEAF(IfType) 316AST_LEAF(IfType)
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 69a028f..d37f911 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = {
75 "close"s // Lua 5.4 75 "close"s // Lua 5.4
76}; 76};
77 77
78const std::string_view version = "0.20.7"sv; 78const std::string_view version = "0.21.0"sv;
79const std::string_view extension = "yue"sv; 79const std::string_view extension = "yue"sv;
80 80
81class CompileError : public std::logic_error { 81class CompileError : public std::logic_error {
@@ -3088,7 +3088,7 @@ private:
3088 for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { 3088 for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) {
3089 ns.push_back(*it); 3089 ns.push_back(*it);
3090 if (auto cond = ast_cast<IfCond_t>(*it)) { 3090 if (auto cond = ast_cast<IfCond_t>(*it)) {
3091 if (*it != nodes.front() && cond->condition.is<Assignment_t>()) { 3091 if (*it != nodes.front() && cond->assignment) {
3092 auto x = *it; 3092 auto x = *it;
3093 auto newIf = x->new_ptr<If_t>(); 3093 auto newIf = x->new_ptr<If_t>();
3094 newIf->type.set(toAst<IfType_t>("if"sv, x)); 3094 newIf->type.set(toAst<IfType_t>("if"sv, x));
@@ -3142,11 +3142,12 @@ private:
3142 default: YUEE("AST node mismatch", node); break; 3142 default: YUEE("AST node mismatch", node); break;
3143 } 3143 }
3144 } 3144 }
3145 auto asmt = ifCondPairs.front().first->condition.as<Assignment_t>(); 3145 auto firstIfCond = ifCondPairs.front().first;
3146 auto asmt = firstIfCond->assignment.get();
3146 bool storingValue = false; 3147 bool storingValue = false;
3147 ast_ptr<false, ExpListAssign_t> extraAssignment; 3148 ast_ptr<false, ExpListAssign_t> extraAssignment;
3148 if (asmt) { 3149 if (asmt) {
3149 ast_ptr<false, ast_node> exp = asmt->expList->exprs.front(); 3150 auto exp = firstIfCond->condition.get();
3150 auto x = exp; 3151 auto x = exp;
3151 auto var = singleVariableFrom(exp, false); 3152 auto var = singleVariableFrom(exp, false);
3152 if (var.empty() || isGlobal(var)) { 3153 if (var.empty() || isGlobal(var)) {
@@ -3164,11 +3165,12 @@ private:
3164 temp.push_back(indent() + "do"s + nll(asmt)); 3165 temp.push_back(indent() + "do"s + nll(asmt));
3165 pushScope(); 3166 pushScope();
3166 } 3167 }
3167 asmt->expList->exprs.pop_front();
3168 auto expList = toAst<ExpList_t>(desVar, x); 3168 auto expList = toAst<ExpList_t>(desVar, x);
3169 auto assignment = x->new_ptr<ExpListAssign_t>(); 3169 auto assignment = x->new_ptr<ExpListAssign_t>();
3170 for (auto expr : asmt->expList->exprs.objects()) { 3170 if (asmt->expList) {
3171 expList->exprs.push_back(expr); 3171 for (auto expr : asmt->expList->exprs.objects()) {
3172 expList->exprs.push_back(expr);
3173 }
3172 } 3174 }
3173 assignment->expList.set(expList); 3175 assignment->expList.set(expList);
3174 assignment->action.set(asmt->assign); 3176 assignment->action.set(asmt->assign);
@@ -3196,9 +3198,10 @@ private:
3196 } 3198 }
3197 auto expList = x->new_ptr<ExpList_t>(); 3199 auto expList = x->new_ptr<ExpList_t>();
3198 expList->exprs.push_back(exp); 3200 expList->exprs.push_back(exp);
3199 asmt->expList->exprs.pop_front(); 3201 if (asmt->expList) {
3200 for (auto expr : asmt->expList->exprs.objects()) { 3202 for (auto expr : asmt->expList->exprs.objects()) {
3201 expList->exprs.push_back(expr); 3203 expList->exprs.push_back(expr);
3204 }
3202 } 3205 }
3203 auto assignment = x->new_ptr<ExpListAssign_t>(); 3206 auto assignment = x->new_ptr<ExpListAssign_t>();
3204 assignment->expList.set(expList); 3207 assignment->expList.set(expList);
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 2206686..5b97a25 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -114,6 +114,11 @@ YueParser::YueParser() {
114 return false; 114 return false;
115 }); 115 });
116 116
117 if_assignment_syntax_error = pl::user(true_(), [](const item_t& item) {
118 throw ParserError("use := for if-assignment expression"sv, item.begin);
119 return false;
120 });
121
117 #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) 122 #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut)
118 123
119 #define key(str) (expr(str) >> not_alpha_num) 124 #define key(str) (expr(str) >> not_alpha_num)
@@ -369,8 +374,8 @@ YueParser::YueParser() {
369 +space_break >> advance_match >> space >> SwitchCase >> switch_block >> pop_indent 374 +space_break >> advance_match >> space >> SwitchCase >> switch_block >> pop_indent
370 ) >> switch_block; 375 ) >> switch_block;
371 376
372 Assignment = ExpList >> space >> Assign; 377 Assignment = -(',' >> space >> ExpList >> space) >> (':' >> Assign | and_('=') >> if_assignment_syntax_error);
373 IfCond = disable_chain_rule(disable_arg_table_block_rule(Assignment | Exp)); 378 IfCond = disable_chain_rule(disable_arg_table_block_rule(Exp >> -(space >> Assignment)));
374 if_else_if = -(line_break >> *space_break >> check_indent_match) >> space >> key("elseif") >> space >> IfCond >> space >> body_with("then"); 379 if_else_if = -(line_break >> *space_break >> check_indent_match) >> space >> key("elseif") >> space >> IfCond >> space >> body_with("then");
375 if_else = -(line_break >> *space_break >> check_indent_match) >> space >> key("else") >> space >> body; 380 if_else = -(line_break >> *space_break >> check_indent_match) >> space >> key("else") >> space >> body;
376 IfType = (expr("if") | "unless") >> not_alpha_num; 381 IfType = (expr("if") | "unless") >> not_alpha_num;
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h
index 16b57b2..c3d5d7d 100644
--- a/src/yuescript/yue_parser.h
+++ b/src/yuescript/yue_parser.h
@@ -141,6 +141,7 @@ private:
141 NONE_AST_RULE(invalid_interpolation_error); 141 NONE_AST_RULE(invalid_interpolation_error);
142 NONE_AST_RULE(confusing_unary_not_error); 142 NONE_AST_RULE(confusing_unary_not_error);
143 NONE_AST_RULE(table_key_pair_error); 143 NONE_AST_RULE(table_key_pair_error);
144 NONE_AST_RULE(if_assignment_syntax_error);
144 145
145 NONE_AST_RULE(inc_exp_level); 146 NONE_AST_RULE(inc_exp_level);
146 NONE_AST_RULE(dec_exp_level); 147 NONE_AST_RULE(dec_exp_level);