summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-01-13 14:24:07 +0800
committerLi Jin <dragon-fly@qq.com>2020-01-13 14:24:07 +0800
commit2c563f0deada6e10b87b71a500ff98d4bdc1ecf6 (patch)
tree95ffa8c518b56fe1c384a96ca6d5a29c00d17217
parent4c830cdbd5993883f671e17228afc39c3a21e5cc (diff)
downloadyuescript-2c563f0deada6e10b87b71a500ff98d4bdc1ecf6.tar.gz
yuescript-2c563f0deada6e10b87b71a500ff98d4bdc1ecf6.tar.bz2
yuescript-2c563f0deada6e10b87b71a500ff98d4bdc1ecf6.zip
remove codes to be compatible with old version.
-rw-r--r--src/MoonP/moon_compiler.cpp24
-rw-r--r--src/MoonP/moon_compiler.h5
-rw-r--r--src/MoonP/moon_parser.cpp2
3 files changed, 9 insertions, 22 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index 0a5babe..d30f413 100644
--- a/src/MoonP/moon_compiler.cpp
+++ b/src/MoonP/moon_compiler.cpp
@@ -288,11 +288,11 @@ private:
288 } 288 }
289 289
290 std::string indent() { 290 std::string indent() {
291 return _config.spaceOverTab ? std::string((_scopes.size() - 1 + _indentOffset) * 2, ' ') : std::string(_scopes.size() - 1 + _indentOffset, '\t'); 291 return std::string(_scopes.size() - 1 + _indentOffset, '\t');
292 } 292 }
293 293
294 std::string indent(int offset) { 294 std::string indent(int offset) {
295 return _config.spaceOverTab ? std::string((_scopes.size() - 1 + _indentOffset + offset) * 2, ' ') : std::string(_scopes.size() - 1 + _indentOffset + offset, '\t'); 295 return std::string(_scopes.size() - 1 + _indentOffset + offset, '\t');
296 } 296 }
297 297
298 std::string clearBuf() { 298 std::string clearBuf() {
@@ -707,16 +707,7 @@ private:
707 } 707 }
708 } 708 }
709 } 709 }
710 if (_config.allowExprNotInTheEndOfBody) { 710 throw std::logic_error(debugInfo("Expression list must appear at the end of body block."sv, expList));
711 auto assign = x->new_ptr<Assign_t>();
712 assign->values.dup(expList->exprs);
713 auto assignment = x->new_ptr<ExpListAssign_t>();
714 assignment->expList.set(toAst<ExpList_t>("_", ExpList, x));
715 assignment->action.set(assign);
716 transformAssignment(assignment, out);
717 } else {
718 throw std::logic_error(debugInfo("Expression list must appear at the end of body block."sv, expList));
719 }
720 } 711 }
721 break; 712 break;
722 } 713 }
@@ -2456,8 +2447,7 @@ private:
2456 switch (loopTarget->getId()) { 2447 switch (loopTarget->getId()) {
2457 case "star_exp"_id: { 2448 case "star_exp"_id: {
2458 auto star_exp = static_cast<star_exp_t*>(loopTarget); 2449 auto star_exp = static_cast<star_exp_t*>(loopTarget);
2459 std::string listVar; 2450 auto listVar = singleVariableFrom(star_exp->value);
2460 if (_config.reuseVariable) listVar = singleVariableFrom(star_exp->value);
2461 auto indexVar = getUnusedName("_index_"); 2451 auto indexVar = getUnusedName("_index_");
2462 varAfter.push_back(indexVar); 2452 varAfter.push_back(indexVar);
2463 auto value = singleValueFrom(star_exp->value); 2453 auto value = singleValueFrom(star_exp->value);
@@ -3279,7 +3269,7 @@ private:
3279 checkAssignable(with->valueList); 3269 checkAssignable(with->valueList);
3280 auto vars = getAssignVars(with); 3270 auto vars = getAssignVars(with);
3281 if (vars.front().empty()) { 3271 if (vars.front().empty()) {
3282 if (_config.reuseVariable && with->assigns->values.objects().size() == 1) { 3272 if (with->assigns->values.objects().size() == 1) {
3283 auto var = singleVariableFrom(with->assigns->values.objects().front()); 3273 auto var = singleVariableFrom(with->assigns->values.objects().front());
3284 if (!var.empty()) { 3274 if (!var.empty()) {
3285 withVar = var; 3275 withVar = var;
@@ -3326,7 +3316,7 @@ private:
3326 transformAssignment(assignment, temp); 3316 transformAssignment(assignment, temp);
3327 } 3317 }
3328 } else { 3318 } else {
3329 if (_config.reuseVariable) withVar = singleVariableFrom(with->valueList); 3319 withVar = singleVariableFrom(with->valueList);
3330 if (withVar.empty()) { 3320 if (withVar.empty()) {
3331 withVar = getUnusedName("_with_"); 3321 withVar = getUnusedName("_with_");
3332 auto assignment = x->new_ptr<ExpListAssign_t>(); 3322 auto assignment = x->new_ptr<ExpListAssign_t>();
@@ -3882,7 +3872,7 @@ private:
3882 3872
3883const std::string MoonCompliler::Empty; 3873const std::string MoonCompliler::Empty;
3884 3874
3885std::tuple<std::string,std::string,GlobalVars> moonCompile(const std::string& codes, const MoonConfig& config) { 3875std::tuple<std::string,std::string,GlobalVars> moonCompile(const std::string& codes, const MoonConfig& config) {
3886 auto compiler = MoonCompliler{}; 3876 auto compiler = MoonCompliler{};
3887 auto result = compiler.complile(codes, config); 3877 auto result = compiler.complile(codes, config);
3888 auto globals = std::make_unique<std::list<GlobalVar>>(); 3878 auto globals = std::make_unique<std::list<GlobalVar>>();
diff --git a/src/MoonP/moon_compiler.h b/src/MoonP/moon_compiler.h
index cb1990c..0739a59 100644
--- a/src/MoonP/moon_compiler.h
+++ b/src/MoonP/moon_compiler.h
@@ -20,10 +20,7 @@ const char* moonScriptVersion();
20struct MoonConfig { 20struct MoonConfig {
21 bool lintGlobalVariable = false; 21 bool lintGlobalVariable = false;
22 bool implicitReturnRoot = true; 22 bool implicitReturnRoot = true;
23 bool reserveLineNumber = false; 23 bool reserveLineNumber = true;
24 bool spaceOverTab = false;
25 bool reuseVariable = false;
26 bool allowExprNotInTheEndOfBody = false;
27}; 24};
28 25
29struct GlobalVar { 26struct GlobalVar {
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp
index 7b5183e..1005463 100644
--- a/src/MoonP/moon_parser.cpp
+++ b/src/MoonP/moon_parser.cpp
@@ -236,7 +236,7 @@ extern rule CompInner;
236 236
237rule Comprehension = sym('[') >> Exp >> CompInner >> sym(']'); 237rule Comprehension = sym('[') >> Exp >> CompInner >> sym(']');
238rule comp_value = sym(',') >> Exp; 238rule comp_value = sym(',') >> Exp;
239rule TblComprehension = sym('{') >> (Exp >> -comp_value) >> CompInner >> sym('}'); 239rule TblComprehension = sym('{') >> (Exp >> -comp_value) >> CompInner >> sym('}');
240 240
241extern rule CompForEach, CompFor, CompClause; 241extern rule CompForEach, CompFor, CompClause;
242 242