aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/inputs/backcall.moon13
-rw-r--r--src/MoonP/moon_ast.h7
-rw-r--r--src/MoonP/moon_compiler.cpp5
-rw-r--r--src/MoonP/moon_parser.cpp3
-rw-r--r--src/MoonP/moon_parser.h1
-rw-r--r--src/moonp.cpp2
6 files changed, 26 insertions, 5 deletions
diff --git a/spec/inputs/backcall.moon b/spec/inputs/backcall.moon
index 3aedba9..2972b1d 100644
--- a/spec/inputs/backcall.moon
+++ b/spec/inputs/backcall.moon
@@ -90,4 +90,17 @@ do
90 (data)<- loadAsync file 90 (data)<- loadAsync file
91 addToCache file,data) |> reduce 0,(a,b)-> a+b 91 addToCache file,data) |> reduce 0,(a,b)-> a+b
92 92
93propA = do
94 (value)<= property => @_value
95 print "old value: #{@_value}"
96 print "new value: #{value}"
97 @_value = value
98
99propB = do
100 <= property _, (value)=>
101 print "old value: #{@_value}"
102 print "new value: #{value}"
103 @_value = value
104 @_value
105
93alert "hi" 106alert "hi"
diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h
index 917429e..dd01165 100644
--- a/src/MoonP/moon_ast.h
+++ b/src/MoonP/moon_ast.h
@@ -135,12 +135,17 @@ AST_NODE(Import)
135AST_END(Import) 135AST_END(Import)
136 136
137class FnArgsDef_t; 137class FnArgsDef_t;
138
139AST_LEAF(fn_arrow_back)
140AST_END(fn_arrow_back)
141
138class ChainValue_t; 142class ChainValue_t;
139 143
140AST_NODE(Backcall) 144AST_NODE(Backcall)
141 ast_ptr<false, FnArgsDef_t> argsDef; 145 ast_ptr<false, FnArgsDef_t> argsDef;
146 ast_ptr<true, fn_arrow_back_t> arrow;
142 ast_ptr<true, ChainValue_t> value; 147 ast_ptr<true, ChainValue_t> value;
143 AST_MEMBER(Backcall, &argsDef, &value) 148 AST_MEMBER(Backcall, &argsDef, &arrow, &value)
144AST_END(Backcall) 149AST_END(Backcall)
145 150
146AST_NODE(ExpListLow) 151AST_NODE(ExpListLow)
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index a39bfd0..83b91e6 100644
--- a/src/MoonP/moon_compiler.cpp
+++ b/src/MoonP/moon_compiler.cpp
@@ -32,7 +32,7 @@ inline std::string s(std::string_view sv) {
32} 32}
33 33
34const char* moonScriptVersion() { 34const char* moonScriptVersion() {
35 return "0.5.0-r0.1.4"; 35 return "0.5.0-r0.1.5";
36} 36}
37 37
38class MoonCompilerImpl { 38class MoonCompilerImpl {
@@ -1740,7 +1740,8 @@ private:
1740 body->content.set(block); 1740 body->content.set(block);
1741 auto funLit = x->new_ptr<FunLit_t>(); 1741 auto funLit = x->new_ptr<FunLit_t>();
1742 funLit->argsDef.set(backcall->argsDef); 1742 funLit->argsDef.set(backcall->argsDef);
1743 funLit->arrow.set(toAst<fn_arrow_t>("->"sv, x)); 1743 auto arrow = _parser.toString(backcall->arrow);
1744 funLit->arrow.set(toAst<fn_arrow_t>(arrow == "<-"sv ? "->"sv : "=>"sv, x));
1744 funLit->body.set(body); 1745 funLit->body.set(body);
1745 auto simpleValue = x->new_ptr<SimpleValue_t>(); 1746 auto simpleValue = x->new_ptr<SimpleValue_t>();
1746 simpleValue->value.set(funLit); 1747 simpleValue->value.set(funLit);
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp
index 1502f3c..fecf869 100644
--- a/src/MoonP/moon_parser.cpp
+++ b/src/MoonP/moon_parser.cpp
@@ -434,7 +434,8 @@ MoonParser::MoonParser() {
434 NameOrDestructure = Space >> Variable | TableLit; 434 NameOrDestructure = Space >> Variable | TableLit;
435 AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> White >> NameOrDestructure); 435 AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> White >> NameOrDestructure);
436 436
437 Backcall = -FnArgsDef >> Space >> symx("<-") >> Space >> ChainValue; 437 fn_arrow_back = expr('<') >> set("-=");
438 Backcall = -FnArgsDef >> Space >> fn_arrow_back >> Space >> ChainValue;
438 439
439 ExpList = Seperator >> Exp >> *(sym(',') >> White >> Exp); 440 ExpList = Seperator >> Exp >> *(sym(',') >> White >> Exp);
440 ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> White >> Exp); 441 ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> White >> Exp);
diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h
index 215c6a4..12f735b 100644
--- a/src/MoonP/moon_parser.h
+++ b/src/MoonP/moon_parser.h
@@ -191,6 +191,7 @@ private:
191 AST_RULE(ImportFrom) 191 AST_RULE(ImportFrom)
192 AST_RULE(ImportAs) 192 AST_RULE(ImportAs)
193 AST_RULE(Import) 193 AST_RULE(Import)
194 AST_RULE(fn_arrow_back)
194 AST_RULE(Backcall) 195 AST_RULE(Backcall)
195 AST_RULE(ExpListLow) 196 AST_RULE(ExpListLow)
196 AST_RULE(ExpList) 197 AST_RULE(ExpList)
diff --git a/src/moonp.cpp b/src/moonp.cpp
index 3f36d9d..ade1a1b 100644
--- a/src/moonp.cpp
+++ b/src/moonp.cpp
@@ -247,7 +247,7 @@ static int moontolua(lua_State* L) {
247 } else { 247 } else {
248 lua_pushlstring(L, err.c_str(), err.size()); 248 lua_pushlstring(L, err.c_str(), err.size());
249 } 249 }
250 if (globals && !globals->empty()) { 250 if (globals) {
251 lua_createtable(L, static_cast<int>(globals->size()), 0); 251 lua_createtable(L, static_cast<int>(globals->size()), 0);
252 int i = 1; 252 int i = 1;
253 for (const auto& var : *globals) { 253 for (const auto& var : *globals) {