From 97bbe98289fb74c7cf2d9793b80a1a27b4146045 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 8 Oct 2020 13:01:18 +0800 Subject: change file extension moonp. --- spec/inputs/ambiguous.moon | 26 --- spec/inputs/ambiguous.mp | 26 +++ spec/inputs/assign.moon | 33 ---- spec/inputs/assign.mp | 33 ++++ spec/inputs/attrib.moon | 40 ---- spec/inputs/attrib.mp | 40 ++++ spec/inputs/backcall.moon | 117 ------------ spec/inputs/backcall.mp | 117 ++++++++++++ spec/inputs/bubbling.moon | 27 --- spec/inputs/bubbling.mp | 27 +++ spec/inputs/class.moon | 232 ----------------------- spec/inputs/class.mp | 232 +++++++++++++++++++++++ spec/inputs/comprehension.moon | 52 ------ spec/inputs/comprehension.mp | 52 ++++++ spec/inputs/cond.moon | 190 ------------------- spec/inputs/cond.mp | 190 +++++++++++++++++++ spec/inputs/destructure.moon | 117 ------------ spec/inputs/destructure.mp | 117 ++++++++++++ spec/inputs/do.moon | 27 --- spec/inputs/do.mp | 27 +++ spec/inputs/existential.moon | 51 ------ spec/inputs/existential.mp | 51 ++++++ spec/inputs/export.moon | 76 -------- spec/inputs/export.mp | 76 ++++++++ spec/inputs/export_default.moon | 15 -- spec/inputs/export_default.mp | 15 ++ spec/inputs/funcs.moon | 160 ---------------- spec/inputs/funcs.mp | 160 ++++++++++++++++ spec/inputs/global.moon | 77 -------- spec/inputs/global.mp | 77 ++++++++ spec/inputs/goto.moon | 41 ----- spec/inputs/goto.mp | 41 +++++ spec/inputs/import.moon | 67 ------- spec/inputs/import.mp | 67 +++++++ spec/inputs/lists.moon | 72 -------- spec/inputs/lists.mp | 72 ++++++++ spec/inputs/literals.moon | 46 ----- spec/inputs/literals.mp | 46 +++++ spec/inputs/local.moon | 94 ---------- spec/inputs/local.mp | 94 ++++++++++ spec/inputs/loops.moon | 142 -------------- spec/inputs/loops.mp | 142 ++++++++++++++ spec/inputs/macro.moon | 188 ------------------- spec/inputs/macro.mp | 190 +++++++++++++++++++ spec/inputs/macro_export.moon | 29 --- spec/inputs/macro_export.mp | 29 +++ spec/inputs/operators.moon | 72 -------- spec/inputs/operators.mp | 72 ++++++++ spec/inputs/plus.moon | 38 ---- spec/inputs/plus.mp | 38 ++++ spec/inputs/return.moon | 55 ------ spec/inputs/return.mp | 55 ++++++ spec/inputs/string.moon | 66 ------- spec/inputs/string.mp | 66 +++++++ spec/inputs/stub.moon | 18 -- spec/inputs/stub.mp | 18 ++ spec/inputs/switch.moon | 64 ------- spec/inputs/switch.mp | 64 +++++++ spec/inputs/syntax.moon | 396 ---------------------------------------- spec/inputs/syntax.mp | 396 ++++++++++++++++++++++++++++++++++++++++ spec/inputs/tables.moon | 207 --------------------- spec/inputs/tables.mp | 207 +++++++++++++++++++++ spec/inputs/unless_else.moon | 5 - spec/inputs/unless_else.mp | 5 + spec/inputs/using.moon | 22 --- spec/inputs/using.mp | 22 +++ spec/inputs/whitespace.moon | 140 -------------- spec/inputs/whitespace.mp | 140 ++++++++++++++ spec/inputs/with.moon | 118 ------------ spec/inputs/with.mp | 118 ++++++++++++ src/MoonP/moon_compiler.cpp | 7 +- src/MoonP/moon_compiler.h | 3 +- src/MoonP/moonplus.cpp | 6 +- src/MoonP/moonplus.h | 11 +- src/MoonP/stacktraceplus.h | 2 +- src/moonp.cpp | 8 +- 76 files changed, 3143 insertions(+), 3136 deletions(-) delete mode 100644 spec/inputs/ambiguous.moon create mode 100644 spec/inputs/ambiguous.mp delete mode 100644 spec/inputs/assign.moon create mode 100644 spec/inputs/assign.mp delete mode 100644 spec/inputs/attrib.moon create mode 100644 spec/inputs/attrib.mp delete mode 100644 spec/inputs/backcall.moon create mode 100644 spec/inputs/backcall.mp delete mode 100644 spec/inputs/bubbling.moon create mode 100644 spec/inputs/bubbling.mp delete mode 100644 spec/inputs/class.moon create mode 100644 spec/inputs/class.mp delete mode 100644 spec/inputs/comprehension.moon create mode 100644 spec/inputs/comprehension.mp delete mode 100644 spec/inputs/cond.moon create mode 100644 spec/inputs/cond.mp delete mode 100644 spec/inputs/destructure.moon create mode 100644 spec/inputs/destructure.mp delete mode 100644 spec/inputs/do.moon create mode 100644 spec/inputs/do.mp delete mode 100644 spec/inputs/existential.moon create mode 100644 spec/inputs/existential.mp delete mode 100644 spec/inputs/export.moon create mode 100644 spec/inputs/export.mp delete mode 100644 spec/inputs/export_default.moon create mode 100644 spec/inputs/export_default.mp delete mode 100644 spec/inputs/funcs.moon create mode 100644 spec/inputs/funcs.mp delete mode 100644 spec/inputs/global.moon create mode 100644 spec/inputs/global.mp delete mode 100644 spec/inputs/goto.moon create mode 100644 spec/inputs/goto.mp delete mode 100644 spec/inputs/import.moon create mode 100644 spec/inputs/import.mp delete mode 100644 spec/inputs/lists.moon create mode 100644 spec/inputs/lists.mp delete mode 100644 spec/inputs/literals.moon create mode 100644 spec/inputs/literals.mp delete mode 100644 spec/inputs/local.moon create mode 100644 spec/inputs/local.mp delete mode 100644 spec/inputs/loops.moon create mode 100644 spec/inputs/loops.mp delete mode 100644 spec/inputs/macro.moon create mode 100644 spec/inputs/macro.mp delete mode 100644 spec/inputs/macro_export.moon create mode 100644 spec/inputs/macro_export.mp delete mode 100644 spec/inputs/operators.moon create mode 100644 spec/inputs/operators.mp delete mode 100644 spec/inputs/plus.moon create mode 100644 spec/inputs/plus.mp delete mode 100644 spec/inputs/return.moon create mode 100644 spec/inputs/return.mp delete mode 100644 spec/inputs/string.moon create mode 100644 spec/inputs/string.mp delete mode 100644 spec/inputs/stub.moon create mode 100644 spec/inputs/stub.mp delete mode 100644 spec/inputs/switch.moon create mode 100644 spec/inputs/switch.mp delete mode 100644 spec/inputs/syntax.moon create mode 100644 spec/inputs/syntax.mp delete mode 100644 spec/inputs/tables.moon create mode 100644 spec/inputs/tables.mp delete mode 100644 spec/inputs/unless_else.moon create mode 100644 spec/inputs/unless_else.mp delete mode 100644 spec/inputs/using.moon create mode 100644 spec/inputs/using.mp delete mode 100644 spec/inputs/whitespace.moon create mode 100644 spec/inputs/whitespace.mp delete mode 100644 spec/inputs/with.moon create mode 100644 spec/inputs/with.mp diff --git a/spec/inputs/ambiguous.moon b/spec/inputs/ambiguous.moon deleted file mode 100644 index a5980db..0000000 --- a/spec/inputs/ambiguous.moon +++ /dev/null @@ -1,26 +0,0 @@ -import bind from grasp -(bind stmt) color: "Red" - -a = 'b' -c = d -(a b) c d -import c from d -(a b) c d -(c d) a b -a, b = c, d -(d a) c - -macro block f = (func,arg)-> "(#{func}) #{arg}" -for i = 1, 10 - a = -> - $f print, 1 - a = f - $f print, 2 - if cond - $f print, 3 - ::abc:: - (print) 4 - goto abc - (print) 5 -nil - diff --git a/spec/inputs/ambiguous.mp b/spec/inputs/ambiguous.mp new file mode 100644 index 0000000..a5980db --- /dev/null +++ b/spec/inputs/ambiguous.mp @@ -0,0 +1,26 @@ +import bind from grasp +(bind stmt) color: "Red" + +a = 'b' +c = d +(a b) c d +import c from d +(a b) c d +(c d) a b +a, b = c, d +(d a) c + +macro block f = (func,arg)-> "(#{func}) #{arg}" +for i = 1, 10 + a = -> + $f print, 1 + a = f + $f print, 2 + if cond + $f print, 3 + ::abc:: + (print) 4 + goto abc + (print) 5 +nil + diff --git a/spec/inputs/assign.moon b/spec/inputs/assign.moon deleted file mode 100644 index dac2ba3..0000000 --- a/spec/inputs/assign.moon +++ /dev/null @@ -1,33 +0,0 @@ - -_ = -> - joop = 2302 - - (hi) -> - d = 100 - hi = 1021 - - a,b,c,d = 1,2,3,4 - - hello[232], (5+5)[121], hello, x[99] = 100, 200, 300 - - joop = 12 - -joop = 2345 - -a, b = if hello - "hello" -else - "nothing", "yeah" - - -a, b = if hello - if yeah then "one", "two" else "mmhh" -else - print "the other" - "nothing", "yeah" - -c, d = 1, 2 if true - -x = (do - f! - 123) if f = getHandler! diff --git a/spec/inputs/assign.mp b/spec/inputs/assign.mp new file mode 100644 index 0000000..dac2ba3 --- /dev/null +++ b/spec/inputs/assign.mp @@ -0,0 +1,33 @@ + +_ = -> + joop = 2302 + + (hi) -> + d = 100 + hi = 1021 + + a,b,c,d = 1,2,3,4 + + hello[232], (5+5)[121], hello, x[99] = 100, 200, 300 + + joop = 12 + +joop = 2345 + +a, b = if hello + "hello" +else + "nothing", "yeah" + + +a, b = if hello + if yeah then "one", "two" else "mmhh" +else + print "the other" + "nothing", "yeah" + +c, d = 1, 2 if true + +x = (do + f! + 123) if f = getHandler! diff --git a/spec/inputs/attrib.moon b/spec/inputs/attrib.moon deleted file mode 100644 index bc1e67e..0000000 --- a/spec/inputs/attrib.moon +++ /dev/null @@ -1,40 +0,0 @@ -do - close a, b = setmetatable {},__close:=> print "closed" - const c, d = 123, 'abc' - - close a, b - const c, d - -do - close v = if flag - func! - else - setmetatable {},__close:=> - - close f = with io.open "file.txt" - \write "Hello" - -macro block defer = (item)-> "close _ = #{item}" -macro block defer_f = (func)-> "close _ = setmetatable {},__close:#{func}" - -do - $defer with io.open "file.txt" - \write "Hello" - - $defer setmetatable {},__close:=> print "second" - - $defer_f -> print "first" - -_defers = setmetatable {},__close:=> - @[#@]! - @[#@] = nil - -macro block defer_i = (item)-> " -_defers[#_defers + 1] = #{item} -close _ = _defers" - -do - $defer_i -> print 3 - $defer_i -> print 2 - $defer_i -> print 1 - diff --git a/spec/inputs/attrib.mp b/spec/inputs/attrib.mp new file mode 100644 index 0000000..bc1e67e --- /dev/null +++ b/spec/inputs/attrib.mp @@ -0,0 +1,40 @@ +do + close a, b = setmetatable {},__close:=> print "closed" + const c, d = 123, 'abc' + + close a, b + const c, d + +do + close v = if flag + func! + else + setmetatable {},__close:=> + + close f = with io.open "file.txt" + \write "Hello" + +macro block defer = (item)-> "close _ = #{item}" +macro block defer_f = (func)-> "close _ = setmetatable {},__close:#{func}" + +do + $defer with io.open "file.txt" + \write "Hello" + + $defer setmetatable {},__close:=> print "second" + + $defer_f -> print "first" + +_defers = setmetatable {},__close:=> + @[#@]! + @[#@] = nil + +macro block defer_i = (item)-> " +_defers[#_defers + 1] = #{item} +close _ = _defers" + +do + $defer_i -> print 3 + $defer_i -> print 2 + $defer_i -> print 1 + diff --git a/spec/inputs/backcall.moon b/spec/inputs/backcall.moon deleted file mode 100644 index a648b16..0000000 --- a/spec/inputs/backcall.moon +++ /dev/null @@ -1,117 +0,0 @@ - -{"abc", 123, 998} |> foreach print - -{1,2,3} - |> map((x)-> x * 2) - |> filter((x)-> x > 4) - |> reduce(0, (a,b)-> a + b) - |> print - -[i |> tostring for i = 0,10] |> table.concat(",") |> print - -b = 1 + 2 + (4 |> tostring |> print(1) or 123) - -if x = 233 |> math.max 998 - print x - -with b |> create? "new" - .value = 123 - print \work! - -123 |> f? - -"abc" |> f1? |> f2? - -c = "abc" |> f1? |> f2? - -f = -> - arg |> x.y?\if - -998 |> func2 "abc", 233 |> func0 |> func1 -998 |> func0("abc", 233) |> func1 |> func2 - -1 |> f 2, 3, 4, 5 -val(2) |> f 1, _, 3, 4, 5 -arr[3] |> f 1, 2, _, 4, 5 - -a = {"1","2","3"} |> table.concat("") |> tonumber |> f1(1, 2, 3, _) |> f2(1, _, 3) - -do - (x)<- map {1,2,3} - x * 2 - -do - (x)<- map _,{1,2,3} - x * 2 - -do - (x)<- filter _, do - (x)<- map _,{1,2,3,4} - x * 2 - x > 2 - -do - (data)<- http?.get "ajaxtest" - body[".result"]\html data - (processed)<- http.post "ajaxprocess", data - body[".result"]\append processed - <- setTimeout 1000 - print "done" - -do - <- syncStatus - (err,data="nil")<- loadAsync "file.moon" - if err - print err - return - (codes)<- compileAsync data - func = loadstring codes - func! - -do - <- f1 - <- f2 - do - <- f3 - <- f4 - <- f5 - <- f6 - f7! - -do - :result,:msg = do - (data)<- receiveAsync "filename.txt" - print data - (info)<- processAsync data - check info - print result,msg - - totalSize = (for file in *files - (data)<- loadAsync file - addToCache file,data) |> reduce 0,(a,b)-> a+b - -propA = do - (value)<= property => @_value - print "old value: #{@_value}" - print "new value: #{value}" - @_value = value - -propB = do - <= property _, (value)=> - print "old value: #{@_value}" - print "new value: #{value}" - @_value = value - @_value - -alert "hi" - -x = 123 |> a |> b or 456 |> c |> d or a.if\then("abc") or a?.b\c?(123) or x\y - -x1 = 3 * -4 |> f - -x2 = 3 * -2 ^ 2 |> f - -y = 1 + not # 2 |> (a ^ c) |> b(3,_) * 4 ^ -123 |> f |> f1 or 123 - -nil - diff --git a/spec/inputs/backcall.mp b/spec/inputs/backcall.mp new file mode 100644 index 0000000..a648b16 --- /dev/null +++ b/spec/inputs/backcall.mp @@ -0,0 +1,117 @@ + +{"abc", 123, 998} |> foreach print + +{1,2,3} + |> map((x)-> x * 2) + |> filter((x)-> x > 4) + |> reduce(0, (a,b)-> a + b) + |> print + +[i |> tostring for i = 0,10] |> table.concat(",") |> print + +b = 1 + 2 + (4 |> tostring |> print(1) or 123) + +if x = 233 |> math.max 998 + print x + +with b |> create? "new" + .value = 123 + print \work! + +123 |> f? + +"abc" |> f1? |> f2? + +c = "abc" |> f1? |> f2? + +f = -> + arg |> x.y?\if + +998 |> func2 "abc", 233 |> func0 |> func1 +998 |> func0("abc", 233) |> func1 |> func2 + +1 |> f 2, 3, 4, 5 +val(2) |> f 1, _, 3, 4, 5 +arr[3] |> f 1, 2, _, 4, 5 + +a = {"1","2","3"} |> table.concat("") |> tonumber |> f1(1, 2, 3, _) |> f2(1, _, 3) + +do + (x)<- map {1,2,3} + x * 2 + +do + (x)<- map _,{1,2,3} + x * 2 + +do + (x)<- filter _, do + (x)<- map _,{1,2,3,4} + x * 2 + x > 2 + +do + (data)<- http?.get "ajaxtest" + body[".result"]\html data + (processed)<- http.post "ajaxprocess", data + body[".result"]\append processed + <- setTimeout 1000 + print "done" + +do + <- syncStatus + (err,data="nil")<- loadAsync "file.moon" + if err + print err + return + (codes)<- compileAsync data + func = loadstring codes + func! + +do + <- f1 + <- f2 + do + <- f3 + <- f4 + <- f5 + <- f6 + f7! + +do + :result,:msg = do + (data)<- receiveAsync "filename.txt" + print data + (info)<- processAsync data + check info + print result,msg + + totalSize = (for file in *files + (data)<- loadAsync file + addToCache file,data) |> reduce 0,(a,b)-> a+b + +propA = do + (value)<= property => @_value + print "old value: #{@_value}" + print "new value: #{value}" + @_value = value + +propB = do + <= property _, (value)=> + print "old value: #{@_value}" + print "new value: #{value}" + @_value = value + @_value + +alert "hi" + +x = 123 |> a |> b or 456 |> c |> d or a.if\then("abc") or a?.b\c?(123) or x\y + +x1 = 3 * -4 |> f + +x2 = 3 * -2 ^ 2 |> f + +y = 1 + not # 2 |> (a ^ c) |> b(3,_) * 4 ^ -123 |> f |> f1 or 123 + +nil + diff --git a/spec/inputs/bubbling.moon b/spec/inputs/bubbling.moon deleted file mode 100644 index 23a85d4..0000000 --- a/spec/inputs/bubbling.moon +++ /dev/null @@ -1,27 +0,0 @@ - --- vararg bubbling -f = (...) -> #{...} - -dont_bubble = -> - [x for x in ((...)-> print ...)("hello")] - -k = [x for x in ((...)-> print ...)("hello")] - -j = for i=1,10 - (...) -> print ... - --- bubble me - -m = (...) -> - [x for x in *{...} when f(...) > 4] - -_ = (...)-> - x = for i in *{...} do i - y = [x for x in *{...}] - z = [x for x in hallo when f(...) > 4] - - a = for i=1,10 do ... - - b = for i=1,10 - (...)-> print ... - diff --git a/spec/inputs/bubbling.mp b/spec/inputs/bubbling.mp new file mode 100644 index 0000000..23a85d4 --- /dev/null +++ b/spec/inputs/bubbling.mp @@ -0,0 +1,27 @@ + +-- vararg bubbling +f = (...) -> #{...} + +dont_bubble = -> + [x for x in ((...)-> print ...)("hello")] + +k = [x for x in ((...)-> print ...)("hello")] + +j = for i=1,10 + (...) -> print ... + +-- bubble me + +m = (...) -> + [x for x in *{...} when f(...) > 4] + +_ = (...)-> + x = for i in *{...} do i + y = [x for x in *{...}] + z = [x for x in hallo when f(...) > 4] + + a = for i=1,10 do ... + + b = for i=1,10 + (...)-> print ... + diff --git a/spec/inputs/class.moon b/spec/inputs/class.moon deleted file mode 100644 index ca8b58c..0000000 --- a/spec/inputs/class.moon +++ /dev/null @@ -1,232 +0,0 @@ - -class Hello - new: (@test, @world) => - print "creating object.." - hello: => - print @test, @world - __tostring: => "hello world" - -x = Hello 1,2 -x\hello() - -print x - -class Simple - cool: => print "cool" - -class Yikes extends Simple - new: => print "created hello" - -x = Yikes() -x\cool() - - -class Hi - new: (arg) => - print "init arg", arg - - cool: (num) => - print "num", num - - -class Simple extends Hi - new: => super "man" - cool: => super 120302 - -x = Simple() -x\cool() - -print x.__class == Simple - - -class Okay - -- what is going on - something: 20323 - -- yeaha - - -class Biggie extends Okay - something: => - super 1,2,3,4 - super.something another_self, 1,2,3,4 - assert super == Okay - - -class Yeah - okay: => - super\something 1,2,3,4 - - -class What - something: => print "val:", @val - -class Hello extends What - val: 2323 - something: => super\something - -with Hello! - x = \something! - print x - x! - -class CoolSuper - hi: => - super(1,2,3,4) 1,2,3,4 - super.something 1,2,3,4 - _ = super.something(1,2,3,4).world - super\yeah"world".okay hi, hi, hi - _ = something.super - _ = super.super.super.super - _ = super\hello - nil - - --- selfing -x = @hello -x = @@hello - -@hello "world" -@@hello "world" - -@@one @@two(4,5) @three, @four - -xx = (@hello, @@world, cool) -> - - --- class properties -class ClassMan - @yeah: 343 - blue: => - @hello: 3434, @world: 23423 - green: => - @red: => - - -x = @ -y = @@ - -@ something - -@@ something - -@ = @ + @ / @ - -@ = 343 -@.hello 2,3,4 - -_ = hello[@].world - - -class Whacko - _ = @hello - if something - print "hello world" - - hello = "world" - @another = "day" - - print "yeah" if something -- this is briken - - -print "hello" - -yyy = -> - class Cool - _ = nil - - --- - -class a.b.c.D - _ = nil - - -class a.b["hello"] - _ = nil - -class (-> require "moon")!.Something extends Hello.World - _ = nil - --- - -a = class -b = class Something -c = class Something extends Hello -d = class extends World - -print (class WhatsUp).__name - --- - -global ^ -class Something - _ = nil - - --- - --- hoisting -class Something - val = 23 - {:insert} = table - new: => print insert, val -- prints nil 23 - --- - -class X - new: hi - - --- - -class Cool extends Thing - dang: => - { - hello: -> super! - world: -> super.one - } - --- - -class Whack extends Thing - dang: do_something => - super! - ---- - -class Wowha extends Thing - @butt: -> - super! - _ = super.hello - super\hello! - super\hello - - - @zone: cool { - -> - super! - _ = super.hello - super\hello! - super\hello - } - -do - class Test - new: => @@if = true - @do: => 1 - test: => @@if and @@do! - test = Test! - test\test! - -do - class Test - new: => @if = true - do: => 1 - test: => @if and @do! - test = Test! - test\test! - -class extends lapis.Application - "/": => json: { status: true } - -nil diff --git a/spec/inputs/class.mp b/spec/inputs/class.mp new file mode 100644 index 0000000..ca8b58c --- /dev/null +++ b/spec/inputs/class.mp @@ -0,0 +1,232 @@ + +class Hello + new: (@test, @world) => + print "creating object.." + hello: => + print @test, @world + __tostring: => "hello world" + +x = Hello 1,2 +x\hello() + +print x + +class Simple + cool: => print "cool" + +class Yikes extends Simple + new: => print "created hello" + +x = Yikes() +x\cool() + + +class Hi + new: (arg) => + print "init arg", arg + + cool: (num) => + print "num", num + + +class Simple extends Hi + new: => super "man" + cool: => super 120302 + +x = Simple() +x\cool() + +print x.__class == Simple + + +class Okay + -- what is going on + something: 20323 + -- yeaha + + +class Biggie extends Okay + something: => + super 1,2,3,4 + super.something another_self, 1,2,3,4 + assert super == Okay + + +class Yeah + okay: => + super\something 1,2,3,4 + + +class What + something: => print "val:", @val + +class Hello extends What + val: 2323 + something: => super\something + +with Hello! + x = \something! + print x + x! + +class CoolSuper + hi: => + super(1,2,3,4) 1,2,3,4 + super.something 1,2,3,4 + _ = super.something(1,2,3,4).world + super\yeah"world".okay hi, hi, hi + _ = something.super + _ = super.super.super.super + _ = super\hello + nil + + +-- selfing +x = @hello +x = @@hello + +@hello "world" +@@hello "world" + +@@one @@two(4,5) @three, @four + +xx = (@hello, @@world, cool) -> + + +-- class properties +class ClassMan + @yeah: 343 + blue: => + @hello: 3434, @world: 23423 + green: => + @red: => + + +x = @ +y = @@ + +@ something + +@@ something + +@ = @ + @ / @ + +@ = 343 +@.hello 2,3,4 + +_ = hello[@].world + + +class Whacko + _ = @hello + if something + print "hello world" + + hello = "world" + @another = "day" + + print "yeah" if something -- this is briken + + +print "hello" + +yyy = -> + class Cool + _ = nil + + +-- + +class a.b.c.D + _ = nil + + +class a.b["hello"] + _ = nil + +class (-> require "moon")!.Something extends Hello.World + _ = nil + +-- + +a = class +b = class Something +c = class Something extends Hello +d = class extends World + +print (class WhatsUp).__name + +-- + +global ^ +class Something + _ = nil + + +-- + +-- hoisting +class Something + val = 23 + {:insert} = table + new: => print insert, val -- prints nil 23 + +-- + +class X + new: hi + + +-- + +class Cool extends Thing + dang: => + { + hello: -> super! + world: -> super.one + } + +-- + +class Whack extends Thing + dang: do_something => + super! + +--- + +class Wowha extends Thing + @butt: -> + super! + _ = super.hello + super\hello! + super\hello + + + @zone: cool { + -> + super! + _ = super.hello + super\hello! + super\hello + } + +do + class Test + new: => @@if = true + @do: => 1 + test: => @@if and @@do! + test = Test! + test\test! + +do + class Test + new: => @if = true + do: => 1 + test: => @if and @do! + test = Test! + test\test! + +class extends lapis.Application + "/": => json: { status: true } + +nil diff --git a/spec/inputs/comprehension.moon b/spec/inputs/comprehension.moon deleted file mode 100644 index b6adb94..0000000 --- a/spec/inputs/comprehension.moon +++ /dev/null @@ -1,52 +0,0 @@ - --- see lists.moon for list comprehension tests - -items = {1,2,3,4,5,6} -out = {k,k*2 for k in items} - - -x = hello: "world", okay: 2323 - -copy = {k,v for k,v in pairs x when k != "okay"} - --- - -_ = { unpack(x) for x in yes } -_ = { unpack(x) for x in *yes } - -_ = { xxxx for x in yes } -_ = { unpack [a*i for i, a in ipairs x] for x in *{{1,2}, {3,4}} } - - --- - -n1 = [i for i=1,10] -n2 = [i for i=1,10 when i % 2 == 1] - -aa = [{x,y} for x=1,10 for y=5,14] -bb = [y for thing in y for i=1,10] -cc = [y for i=1,10 for thing in y] -dd = [y for i=1,10 when cool for thing in y when x > 3 when c + 3] - -_ = {"hello", "world" for i=1,10} - --- - -j = [a for {a,b,c} in things] -k = [a for {a,b,c} in *things] -i = [hello for {:hello, :world} in *things] - -hj = {a,c for {a,b,c} in things} -hk = {a,c for {a,b,c} in *things} -hi = {hello,world for {:hello, :world} in *things} - -ok(a,b,c) for {a,b,c} in things - --- - -_ = [item for item in *items[1 + 2,3+4]] -_ = [item for item in *items[hello! * 4, 2 - thing[4]]] - -list = [item?\invoke 123 for item in items] - -nil diff --git a/spec/inputs/comprehension.mp b/spec/inputs/comprehension.mp new file mode 100644 index 0000000..b6adb94 --- /dev/null +++ b/spec/inputs/comprehension.mp @@ -0,0 +1,52 @@ + +-- see lists.moon for list comprehension tests + +items = {1,2,3,4,5,6} +out = {k,k*2 for k in items} + + +x = hello: "world", okay: 2323 + +copy = {k,v for k,v in pairs x when k != "okay"} + +-- + +_ = { unpack(x) for x in yes } +_ = { unpack(x) for x in *yes } + +_ = { xxxx for x in yes } +_ = { unpack [a*i for i, a in ipairs x] for x in *{{1,2}, {3,4}} } + + +-- + +n1 = [i for i=1,10] +n2 = [i for i=1,10 when i % 2 == 1] + +aa = [{x,y} for x=1,10 for y=5,14] +bb = [y for thing in y for i=1,10] +cc = [y for i=1,10 for thing in y] +dd = [y for i=1,10 when cool for thing in y when x > 3 when c + 3] + +_ = {"hello", "world" for i=1,10} + +-- + +j = [a for {a,b,c} in things] +k = [a for {a,b,c} in *things] +i = [hello for {:hello, :world} in *things] + +hj = {a,c for {a,b,c} in things} +hk = {a,c for {a,b,c} in *things} +hi = {hello,world for {:hello, :world} in *things} + +ok(a,b,c) for {a,b,c} in things + +-- + +_ = [item for item in *items[1 + 2,3+4]] +_ = [item for item in *items[hello! * 4, 2 - thing[4]]] + +list = [item?\invoke 123 for item in items] + +nil diff --git a/spec/inputs/cond.moon b/spec/inputs/cond.moon deleted file mode 100644 index 3dee99b..0000000 --- a/spec/inputs/cond.moon +++ /dev/null @@ -1,190 +0,0 @@ - -you_cool = false - -_ = if cool - if you_cool - one - else if eatdic - yeah - else - _ = two - three -else - no - -_ = if cool then no -_ = if cool then no else yes - -if cool then wow cool else - noso cool - -if working - _ = if cool then if cool then okay else what else nah - - -if yeah then no day elseif cool me then okay ya else u way -if yeah then no dad else if cool you then okay bah else p way - - -if (->)() then what ever - -if nil then flip me else - it be,rad - - -if things great then no way elseif okay sure - what here - - -if things then no chance -elseif okay - what now - - -if things - yes man -elseif okay person then hi there else hmm sure - -if lets go - print "greetings" -elseif "just us" - print "will smith" else show 5555555 - --- - -if something = 10 - print something -else - print "else" - -hello = if something = 10 - print something -else - print "else" - - -hello = 5 + if something = 10 - print something - ---- - -z = false - -_ = if false - one -elseif x = true - two -elseif z = true - three -else - four - - -out = if false - one -elseif x = true - two -elseif z = true - three -else - four - -kzy = -> - if something = true - 1 - elseif another = false - 2 - ---- - -unless true - print "cool!" - -unless true and false - print "cool!" - -unless false then print "cool!" -unless false then print "cool!" else print "no way!" - -unless nil - print "hello" -else - print "world" - --- - -x = unless true - print "cool!" - -x = unless true and false - print "cool!" - -y = unless false then print "cool!" -y = unless false then print "cool!" else print "no way!" - -z = unless nil - print "hello" -else - print "world" - -print unless true - print "cool!" - -print unless true and false - print "cool!" - -print unless false then print "cool!" -print unless false then print "cool!" else print "no way!" - -print unless nil - print "hello" -else - print "world" - --- - -print "hello" unless value - -dddd = {1,2,3} unless value - - --- - -do - j = 100 - unless j = hi! - error "not j!" - ----------------- - -a = 12 -a,c,b = "cool" if something - - - ---- - -j = if 1 - if 2 - 3 -else 6 - - -m = if 1 - - - - if 2 - - - 3 - - -else 6 - - - -nil - - - diff --git a/spec/inputs/cond.mp b/spec/inputs/cond.mp new file mode 100644 index 0000000..3dee99b --- /dev/null +++ b/spec/inputs/cond.mp @@ -0,0 +1,190 @@ + +you_cool = false + +_ = if cool + if you_cool + one + else if eatdic + yeah + else + _ = two + three +else + no + +_ = if cool then no +_ = if cool then no else yes + +if cool then wow cool else + noso cool + +if working + _ = if cool then if cool then okay else what else nah + + +if yeah then no day elseif cool me then okay ya else u way +if yeah then no dad else if cool you then okay bah else p way + + +if (->)() then what ever + +if nil then flip me else + it be,rad + + +if things great then no way elseif okay sure + what here + + +if things then no chance +elseif okay + what now + + +if things + yes man +elseif okay person then hi there else hmm sure + +if lets go + print "greetings" +elseif "just us" + print "will smith" else show 5555555 + +-- + +if something = 10 + print something +else + print "else" + +hello = if something = 10 + print something +else + print "else" + + +hello = 5 + if something = 10 + print something + +--- + +z = false + +_ = if false + one +elseif x = true + two +elseif z = true + three +else + four + + +out = if false + one +elseif x = true + two +elseif z = true + three +else + four + +kzy = -> + if something = true + 1 + elseif another = false + 2 + +--- + +unless true + print "cool!" + +unless true and false + print "cool!" + +unless false then print "cool!" +unless false then print "cool!" else print "no way!" + +unless nil + print "hello" +else + print "world" + +-- + +x = unless true + print "cool!" + +x = unless true and false + print "cool!" + +y = unless false then print "cool!" +y = unless false then print "cool!" else print "no way!" + +z = unless nil + print "hello" +else + print "world" + +print unless true + print "cool!" + +print unless true and false + print "cool!" + +print unless false then print "cool!" +print unless false then print "cool!" else print "no way!" + +print unless nil + print "hello" +else + print "world" + +-- + +print "hello" unless value + +dddd = {1,2,3} unless value + + +-- + +do + j = 100 + unless j = hi! + error "not j!" + +---------------- + +a = 12 +a,c,b = "cool" if something + + + +--- + +j = if 1 + if 2 + 3 +else 6 + + +m = if 1 + + + + if 2 + + + 3 + + +else 6 + + + +nil + + + diff --git a/spec/inputs/destructure.moon b/spec/inputs/destructure.moon deleted file mode 100644 index 49e6393..0000000 --- a/spec/inputs/destructure.moon +++ /dev/null @@ -1,117 +0,0 @@ - -do - {a, b} = hello - - {{a}, b, {c}} = hello - - { :hello, :world } = value - -do - { yes: no, thing } = world - - {:a,:b,:c,:d} = yeah - - {a} = one, two - {b}, c = one - {d}, e = one, two - - x, {y} = one, two - - xx, yy = 1, 2 - {yy, xx} = {xx, yy} - - {a, :b, c, :d, e, :f, g} = tbl - ---- - -do - futurists = - sculptor: "Umberto Boccioni" - painter: "Vladimir Burliuk" - poet: - name: "F.T. Marinetti" - address: { - "Via Roma 42R" - "Bellagio, Italy 22021" - } - - {poet: {:name, address: {street, city}}} = futurists - --- - -do - { @world } = x - { a.b, c.y, func!.z } = x - - { world: @world } = x - --- - -do - thing = {{1,2}, {3,4}} - - for {x,y} in *thing - print x,y - - --- - -do - with {a,b} = thing - print a, b - - --- - -do - thing = nil - if {a} = thing - print a - else - print "nothing" - - thang = {1,2} - if {a,b} = thang - print a,b - - if {a,b} = thing - print a,b - elseif {c,d} = thang - print c,d - else - print "NO" - --- - -do - z = "yeah" - {a,b,c} = z - -do - {a,b,c} = z - -_ = (z) -> - {a,b,c} = z - -do - z = "oo" - _ = (k) -> - {a,b,c} = z - -do - {function:{end:endVar}} = thing - -do - {if:{a,b,c}} = thing - -do - {:a, :b} = {a: "Hello", b: "World"} if true - - {days, hours, mins, secs} = [tonumber a for a in *{ - string.match "1 2 3 4", "(.+)%s(.+)%s(.+)%s(.+)" - }] - - {:one, :two, :three} = {w,true for w in foo\gmatch("%S+")} - - {:a},b = a\if(123) + t, 123 - diff --git a/spec/inputs/destructure.mp b/spec/inputs/destructure.mp new file mode 100644 index 0000000..49e6393 --- /dev/null +++ b/spec/inputs/destructure.mp @@ -0,0 +1,117 @@ + +do + {a, b} = hello + + {{a}, b, {c}} = hello + + { :hello, :world } = value + +do + { yes: no, thing } = world + + {:a,:b,:c,:d} = yeah + + {a} = one, two + {b}, c = one + {d}, e = one, two + + x, {y} = one, two + + xx, yy = 1, 2 + {yy, xx} = {xx, yy} + + {a, :b, c, :d, e, :f, g} = tbl + +--- + +do + futurists = + sculptor: "Umberto Boccioni" + painter: "Vladimir Burliuk" + poet: + name: "F.T. Marinetti" + address: { + "Via Roma 42R" + "Bellagio, Italy 22021" + } + + {poet: {:name, address: {street, city}}} = futurists + +-- + +do + { @world } = x + { a.b, c.y, func!.z } = x + + { world: @world } = x + +-- + +do + thing = {{1,2}, {3,4}} + + for {x,y} in *thing + print x,y + + +-- + +do + with {a,b} = thing + print a, b + + +-- + +do + thing = nil + if {a} = thing + print a + else + print "nothing" + + thang = {1,2} + if {a,b} = thang + print a,b + + if {a,b} = thing + print a,b + elseif {c,d} = thang + print c,d + else + print "NO" + +-- + +do + z = "yeah" + {a,b,c} = z + +do + {a,b,c} = z + +_ = (z) -> + {a,b,c} = z + +do + z = "oo" + _ = (k) -> + {a,b,c} = z + +do + {function:{end:endVar}} = thing + +do + {if:{a,b,c}} = thing + +do + {:a, :b} = {a: "Hello", b: "World"} if true + + {days, hours, mins, secs} = [tonumber a for a in *{ + string.match "1 2 3 4", "(.+)%s(.+)%s(.+)%s(.+)" + }] + + {:one, :two, :three} = {w,true for w in foo\gmatch("%S+")} + + {:a},b = a\if(123) + t, 123 + diff --git a/spec/inputs/do.moon b/spec/inputs/do.moon deleted file mode 100644 index 2fbcbb9..0000000 --- a/spec/inputs/do.moon +++ /dev/null @@ -1,27 +0,0 @@ - -do - print "hello" - print "world" - -x = do - print "hello" - print "world" - -y = do - things = "shhh" - -> "hello: " .. things - -_ = -> if something then do "yeah" - -t = { - y: do - number = 100 - (x) -> x + number -} - -(y=(do - x = 10 + 2 - x), k=do - "nothing") -> do - "uhhh" - diff --git a/spec/inputs/do.mp b/spec/inputs/do.mp new file mode 100644 index 0000000..2fbcbb9 --- /dev/null +++ b/spec/inputs/do.mp @@ -0,0 +1,27 @@ + +do + print "hello" + print "world" + +x = do + print "hello" + print "world" + +y = do + things = "shhh" + -> "hello: " .. things + +_ = -> if something then do "yeah" + +t = { + y: do + number = 100 + (x) -> x + number +} + +(y=(do + x = 10 + 2 + x), k=do + "nothing") -> do + "uhhh" + diff --git a/spec/inputs/existential.moon b/spec/inputs/existential.moon deleted file mode 100644 index 3055705..0000000 --- a/spec/inputs/existential.moon +++ /dev/null @@ -1,51 +0,0 @@ - -f1?! - -f2? "arg0",123 - -x = tab?.value - -print abc?["hello world"]?.xyz - -if print and x? - print x - -@?\func 998 - -with abc?!\func?! - if \p? "abc" - return 123 - -if {:x} = a?.if?\then?(123)? @?\function 998 - print x - -res = b.function\do!\while?("OK")\if("def",998)\f? -print res - -solipsism = true if mind? and not world? - -speed = 0 -speed or= 15 - -footprints = yeti or "bear" - -major = 'Computer Science' - -unless major? - signUpForClass 'Introduction to Wines' - -if window? - environment = 'browser (probably)' - -zip = lottery.drawWinner?!.address?.zipcode - -len = utf8?.len or string?.len or (o) -> #o - -a = tb1?\end? 123 + tb2?\then 456 - -b = tb1?\end? or tb2?\then - -with? io.open "test.txt", "w" - \write "hello" - \close! - diff --git a/spec/inputs/existential.mp b/spec/inputs/existential.mp new file mode 100644 index 0000000..3055705 --- /dev/null +++ b/spec/inputs/existential.mp @@ -0,0 +1,51 @@ + +f1?! + +f2? "arg0",123 + +x = tab?.value + +print abc?["hello world"]?.xyz + +if print and x? + print x + +@?\func 998 + +with abc?!\func?! + if \p? "abc" + return 123 + +if {:x} = a?.if?\then?(123)? @?\function 998 + print x + +res = b.function\do!\while?("OK")\if("def",998)\f? +print res + +solipsism = true if mind? and not world? + +speed = 0 +speed or= 15 + +footprints = yeti or "bear" + +major = 'Computer Science' + +unless major? + signUpForClass 'Introduction to Wines' + +if window? + environment = 'browser (probably)' + +zip = lottery.drawWinner?!.address?.zipcode + +len = utf8?.len or string?.len or (o) -> #o + +a = tb1?\end? 123 + tb2?\then 456 + +b = tb1?\end? or tb2?\then + +with? io.open "test.txt", "w" + \write "hello" + \close! + diff --git a/spec/inputs/export.moon b/spec/inputs/export.moon deleted file mode 100644 index 9a494d9..0000000 --- a/spec/inputs/export.moon +++ /dev/null @@ -1,76 +0,0 @@ - -export a,b,c = 223, 343, 123 -export cool = "dad" - -d,e,f = 3, 2, 1 -export d, e, f - -export class Something - umm: "cool" - -export if this - 232 -else - 4343 - -export What = if this - 232 -else - 4343 - -export y = -> - hallo = 3434 - -export with tmp - j = 2000 - -export cbVal = do - h = 100 - (x)<- f - return x h - -export y = -> - h = 100 - k = 100 - -export switch h - when 100, 150 then 200 - when 200 then 300 - else 0 - -export Constant = switch value - when "good" then 1 - when "better" then 2 - when "best" then 3 - -export x - -f if a then b -f do 123 -f switch a - when b then c -f [i for i = 1,10] -f for i = 1,10 do i -f {k,v for k,v in pairs tb} -f for k,v in pairs tb do k,v -f while a do true -f with a - .b = 123 -f a?.b -f a\b -f class A - -_ = "#{if a then b}" -_ = "#{do 123}" -_ = "#{switch a - when b then c}" -_ = "#{[i for i = 1,10]}" -_ = "#{for i = 1,10 do i}" -_ = "#{{k,v for k,v in pairs tb}}" -_ = "#{for k,v in pairs tb do k,v}" -_ = "#{while a do true}" -_ = "#{with a - .b = 123}" -_ = "#{a?.b}" -_ = "#{a\b}" -_ = "#{class A}" diff --git a/spec/inputs/export.mp b/spec/inputs/export.mp new file mode 100644 index 0000000..9a494d9 --- /dev/null +++ b/spec/inputs/export.mp @@ -0,0 +1,76 @@ + +export a,b,c = 223, 343, 123 +export cool = "dad" + +d,e,f = 3, 2, 1 +export d, e, f + +export class Something + umm: "cool" + +export if this + 232 +else + 4343 + +export What = if this + 232 +else + 4343 + +export y = -> + hallo = 3434 + +export with tmp + j = 2000 + +export cbVal = do + h = 100 + (x)<- f + return x h + +export y = -> + h = 100 + k = 100 + +export switch h + when 100, 150 then 200 + when 200 then 300 + else 0 + +export Constant = switch value + when "good" then 1 + when "better" then 2 + when "best" then 3 + +export x + +f if a then b +f do 123 +f switch a + when b then c +f [i for i = 1,10] +f for i = 1,10 do i +f {k,v for k,v in pairs tb} +f for k,v in pairs tb do k,v +f while a do true +f with a + .b = 123 +f a?.b +f a\b +f class A + +_ = "#{if a then b}" +_ = "#{do 123}" +_ = "#{switch a + when b then c}" +_ = "#{[i for i = 1,10]}" +_ = "#{for i = 1,10 do i}" +_ = "#{{k,v for k,v in pairs tb}}" +_ = "#{for k,v in pairs tb do k,v}" +_ = "#{while a do true}" +_ = "#{with a + .b = 123}" +_ = "#{a?.b}" +_ = "#{a\b}" +_ = "#{class A}" diff --git a/spec/inputs/export_default.moon b/spec/inputs/export_default.moon deleted file mode 100644 index 73f43ac..0000000 --- a/spec/inputs/export_default.moon +++ /dev/null @@ -1,15 +0,0 @@ - -print "OK" - -export default -> - print "hello" - 123 - -(x, fy)<- f 123, "abc" unless isOff -print x -(y, res)<- fy -return if res - abc + y -else - abc - diff --git a/spec/inputs/export_default.mp b/spec/inputs/export_default.mp new file mode 100644 index 0000000..73f43ac --- /dev/null +++ b/spec/inputs/export_default.mp @@ -0,0 +1,15 @@ + +print "OK" + +export default -> + print "hello" + 123 + +(x, fy)<- f 123, "abc" unless isOff +print x +(y, res)<- fy +return if res + abc + y +else + abc + diff --git a/spec/inputs/funcs.moon b/spec/inputs/funcs.moon deleted file mode 100644 index 4176e33..0000000 --- a/spec/inputs/funcs.moon +++ /dev/null @@ -1,160 +0,0 @@ - - -x = -> print what - -_ = -> - -_ = -> -> -> - -go to the barn - -open -> the -> door - -open -> - the door - hello = -> - my func - -h = -> hi - -eat ->, world - - -(->)() - -x = (...) -> - -hello! -hello.world! - -_ = hello!.something -_ = what!["ofefe"] - -what! the! heck! - -_ = (a,b,c,d,e) -> - -_ = (a,a,a,a,a) -> - print a - -_ = (x=23023) -> - -_ = (x=(y=()->) ->) -> - -_ = (x = if something then yeah else no) -> - -something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") -> - print hello - -_ = (x, y) => -_ = (@x, @y) => -_ = (x=1) => -_ = (@x=1,y,@z="hello world") => - - -x -> return -y -> return 1 -z -> return 1, "hello", "world" -k -> if yes then return else return - -_ = -> real_name if something - --- - -d( - -> - print "hello world" - 10 -) - - - -d( - 1,2,3 - 4 - 5 - 6 - - if something - print "okay" - 10 - - 10,20 -) - - -f( - - )( - - )( - what - )(-> - print "srue" - 123) - --- - -x = (a, - b) -> - print "what" - - -y = (a="hi", - b=23) -> - print "what" - -z = ( - a="hi", - b=23) -> - print "what" - - -j = (f,g,m, - a="hi", - b=23 -) -> - print "what" - - -y = (a="hi", - b=23, - ...) -> - print "what" - - -y = (a="hi", - b=23, - ... -) -> - print "what" - --- - -args = (a - b) -> - print "what" - - -args = (a="hi" - b=23) -> - print "what" - -args = ( - a="hi" - b=23) -> - print "what" - - -args = (f,g,m - a="hi" - b=23 -) -> - print "what" - - -@ = (n)-> - return 1 if n == 0 - n * @(n-1) - -nil diff --git a/spec/inputs/funcs.mp b/spec/inputs/funcs.mp new file mode 100644 index 0000000..4176e33 --- /dev/null +++ b/spec/inputs/funcs.mp @@ -0,0 +1,160 @@ + + +x = -> print what + +_ = -> + +_ = -> -> -> + +go to the barn + +open -> the -> door + +open -> + the door + hello = -> + my func + +h = -> hi + +eat ->, world + + +(->)() + +x = (...) -> + +hello! +hello.world! + +_ = hello!.something +_ = what!["ofefe"] + +what! the! heck! + +_ = (a,b,c,d,e) -> + +_ = (a,a,a,a,a) -> + print a + +_ = (x=23023) -> + +_ = (x=(y=()->) ->) -> + +_ = (x = if something then yeah else no) -> + +something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") -> + print hello + +_ = (x, y) => +_ = (@x, @y) => +_ = (x=1) => +_ = (@x=1,y,@z="hello world") => + + +x -> return +y -> return 1 +z -> return 1, "hello", "world" +k -> if yes then return else return + +_ = -> real_name if something + +-- + +d( + -> + print "hello world" + 10 +) + + + +d( + 1,2,3 + 4 + 5 + 6 + + if something + print "okay" + 10 + + 10,20 +) + + +f( + + )( + + )( + what + )(-> + print "srue" + 123) + +-- + +x = (a, + b) -> + print "what" + + +y = (a="hi", + b=23) -> + print "what" + +z = ( + a="hi", + b=23) -> + print "what" + + +j = (f,g,m, + a="hi", + b=23 +) -> + print "what" + + +y = (a="hi", + b=23, + ...) -> + print "what" + + +y = (a="hi", + b=23, + ... +) -> + print "what" + +-- + +args = (a + b) -> + print "what" + + +args = (a="hi" + b=23) -> + print "what" + +args = ( + a="hi" + b=23) -> + print "what" + + +args = (f,g,m + a="hi" + b=23 +) -> + print "what" + + +@ = (n)-> + return 1 if n == 0 + n * @(n-1) + +nil diff --git a/spec/inputs/global.moon b/spec/inputs/global.moon deleted file mode 100644 index 7d6cfde..0000000 --- a/spec/inputs/global.moon +++ /dev/null @@ -1,77 +0,0 @@ - -do - global a,b,c = 223, 343 - global cool = "dad" - -do - global class Something - umm: "cool" - -do - global a,b,c - a,b,c,d = "hello" - - -do - What = if this - 232 - else - 4343 - - global ^ - - another = 3434 - Another = 7890 - - if inner then Yeah = "10000" - - What = if this - 232 - else - 4343 - - -do - global * - - What = if this - 232 - else - 4343 - - x,y,z = 1,2,3 - - y = -> - hallo = 3434 - - with tmp - j = 2000 - - -do - global * - x = 3434 - if y then - x = 10 - -do - global * - if y then - x = 10 - x = 3434 - -do - do - global * - - k = 1212 - - do - h = 100 - - y = -> - h = 100 - k = 100 - - h = 100 - diff --git a/spec/inputs/global.mp b/spec/inputs/global.mp new file mode 100644 index 0000000..7d6cfde --- /dev/null +++ b/spec/inputs/global.mp @@ -0,0 +1,77 @@ + +do + global a,b,c = 223, 343 + global cool = "dad" + +do + global class Something + umm: "cool" + +do + global a,b,c + a,b,c,d = "hello" + + +do + What = if this + 232 + else + 4343 + + global ^ + + another = 3434 + Another = 7890 + + if inner then Yeah = "10000" + + What = if this + 232 + else + 4343 + + +do + global * + + What = if this + 232 + else + 4343 + + x,y,z = 1,2,3 + + y = -> + hallo = 3434 + + with tmp + j = 2000 + + +do + global * + x = 3434 + if y then + x = 10 + +do + global * + if y then + x = 10 + x = 3434 + +do + do + global * + + k = 1212 + + do + h = 100 + + y = -> + h = 100 + k = 100 + + h = 100 + diff --git a/spec/inputs/goto.moon b/spec/inputs/goto.moon deleted file mode 100644 index 3410ca3..0000000 --- a/spec/inputs/goto.moon +++ /dev/null @@ -1,41 +0,0 @@ -do - a = 0 - ::start:: - a += 1 - goto done if a == 5 - goto start - ::done:: - -do - for z = 1, 10 for y = 1, 10 for x = 1, 10 - if x^2 + y^2 == z^2 - print 'found a Pythagorean triple:', x, y, z - goto done - ::done:: - -do - for z = 1, 10 - for y = 1, 10 for x = 1, 10 - if x^2 + y^2 == z^2 - print 'found a Pythagorean triple:', x, y, z - print 'now trying next z...' - goto zcontinue - ::zcontinue:: - -do - ::redo:: - for x = 1, 10 for y = 1, 10 - if not f x, y then goto continue - if not g x, y then goto skip - if not h x, y then goto redo - ::continue:: - ::skip:: - -do - for x in *t - if x % 2 == 0 - print 'list has even number' - goto has - print 'list lacks even number' - ::has:: - diff --git a/spec/inputs/goto.mp b/spec/inputs/goto.mp new file mode 100644 index 0000000..3410ca3 --- /dev/null +++ b/spec/inputs/goto.mp @@ -0,0 +1,41 @@ +do + a = 0 + ::start:: + a += 1 + goto done if a == 5 + goto start + ::done:: + +do + for z = 1, 10 for y = 1, 10 for x = 1, 10 + if x^2 + y^2 == z^2 + print 'found a Pythagorean triple:', x, y, z + goto done + ::done:: + +do + for z = 1, 10 + for y = 1, 10 for x = 1, 10 + if x^2 + y^2 == z^2 + print 'found a Pythagorean triple:', x, y, z + print 'now trying next z...' + goto zcontinue + ::zcontinue:: + +do + ::redo:: + for x = 1, 10 for y = 1, 10 + if not f x, y then goto continue + if not g x, y then goto skip + if not h x, y then goto redo + ::continue:: + ::skip:: + +do + for x in *t + if x % 2 == 0 + print 'list has even number' + goto has + print 'list lacks even number' + ::has:: + diff --git a/spec/inputs/import.moon b/spec/inputs/import.moon deleted file mode 100644 index 99981f8..0000000 --- a/spec/inputs/import.moon +++ /dev/null @@ -1,67 +0,0 @@ - - -import hello from yeah -import hello, world from table["cool"] - -import a, \b, c from items - - -import master, \ghost from find "mytable" - - -a, yumm = 3434, "hello" - - -_table_0 = 232 - -import something from a table - - -if indent - import okay, \well from tables[100] - -do - import a, b, c from z - -do - import a, - b, c from z - -do - import a - b - c from z - -do - import - a - b - c from z - - -do - import - a - b - c - from z - - -do - import 'module' - import 'module_x' - import "d-a-s-h-e-s" - import "module.part" - -do - import "player" as Player - import "lpeg" as {:C, :Ct, :Cmt} - -do - global * - import 'module' - import 'module_x' - import "org.package.module-y" - -do - import "org.package.module" as {function:func,if:ifVar} diff --git a/spec/inputs/import.mp b/spec/inputs/import.mp new file mode 100644 index 0000000..99981f8 --- /dev/null +++ b/spec/inputs/import.mp @@ -0,0 +1,67 @@ + + +import hello from yeah +import hello, world from table["cool"] + +import a, \b, c from items + + +import master, \ghost from find "mytable" + + +a, yumm = 3434, "hello" + + +_table_0 = 232 + +import something from a table + + +if indent + import okay, \well from tables[100] + +do + import a, b, c from z + +do + import a, + b, c from z + +do + import a + b + c from z + +do + import + a + b + c from z + + +do + import + a + b + c + from z + + +do + import 'module' + import 'module_x' + import "d-a-s-h-e-s" + import "module.part" + +do + import "player" as Player + import "lpeg" as {:C, :Ct, :Cmt} + +do + global * + import 'module' + import 'module_x' + import "org.package.module-y" + +do + import "org.package.module" as {function:func,if:ifVar} diff --git a/spec/inputs/lists.moon b/spec/inputs/lists.moon deleted file mode 100644 index 15eb9ab..0000000 --- a/spec/inputs/lists.moon +++ /dev/null @@ -1,72 +0,0 @@ - -hi = [x*2 for _, x in ipairs{1,2,3,4}] - -items = {1,2,3,4,5,6} - -_ = [z for z in ipairs items when z > 4] - -rad = [{a} for a in ipairs { - 1,2,3,4,5,6, -} when good_number a] - - -_ = [z for z in items for j in list when z > 4] - -require "util" - -dump = (x) -> print util.dump x - -range = (count) -> - i = 0 - return coroutine.wrap -> - while i < count - coroutine.yield i - i = i + 1 - -dump [x for x in range 10] -dump [{x, y} for x in range 5 when x > 2 for y in range 5] - -things = [x + y for x in range 10 when x > 5 for y in range 10 when y > 7] - -print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 - -print "hello", x for x in items - -_ = [x for x in x] -x = [x for x in x] - -print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 - -double = [x*2 for x in *items] - -print x for x in *double - -cut = [x for x in *items when x > 3] - -hello = [x + y for x in *items for y in *items] - -print z for z in *hello - - --- slice -x = {1, 2, 3, 4, 5, 6, 7} -print y for y in *x[2,-5,2] -print y for y in *x[,3] -print y for y in *x[2,] -print y for y in *x[,,2] -print y for y in *x[2,,2] - -a, b, c = 1, 5, 2 -print y for y in *x[a,b,c] - - -normal = (hello) -> - [x for x in yeah] - - -test = x 1,2,3,4,5 -print thing for thing in *test - --> a = b for row in *rows - - diff --git a/spec/inputs/lists.mp b/spec/inputs/lists.mp new file mode 100644 index 0000000..15eb9ab --- /dev/null +++ b/spec/inputs/lists.mp @@ -0,0 +1,72 @@ + +hi = [x*2 for _, x in ipairs{1,2,3,4}] + +items = {1,2,3,4,5,6} + +_ = [z for z in ipairs items when z > 4] + +rad = [{a} for a in ipairs { + 1,2,3,4,5,6, +} when good_number a] + + +_ = [z for z in items for j in list when z > 4] + +require "util" + +dump = (x) -> print util.dump x + +range = (count) -> + i = 0 + return coroutine.wrap -> + while i < count + coroutine.yield i + i = i + 1 + +dump [x for x in range 10] +dump [{x, y} for x in range 5 when x > 2 for y in range 5] + +things = [x + y for x in range 10 when x > 5 for y in range 10 when y > 7] + +print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 + +print "hello", x for x in items + +_ = [x for x in x] +x = [x for x in x] + +print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 + +double = [x*2 for x in *items] + +print x for x in *double + +cut = [x for x in *items when x > 3] + +hello = [x + y for x in *items for y in *items] + +print z for z in *hello + + +-- slice +x = {1, 2, 3, 4, 5, 6, 7} +print y for y in *x[2,-5,2] +print y for y in *x[,3] +print y for y in *x[2,] +print y for y in *x[,,2] +print y for y in *x[2,,2] + +a, b, c = 1, 5, 2 +print y for y in *x[a,b,c] + + +normal = (hello) -> + [x for x in yeah] + + +test = x 1,2,3,4,5 +print thing for thing in *test + +-> a = b for row in *rows + + diff --git a/spec/inputs/literals.moon b/spec/inputs/literals.moon deleted file mode 100644 index d4b0326..0000000 --- a/spec/inputs/literals.moon +++ /dev/null @@ -1,46 +0,0 @@ - -_ = { - 121 - 121.2323 - 121.2323e-1 - 121.2323e13434 - 2323E34 - 0x12323 - - 0xfF2323 - 0xabcdef - 0xABCDEF - - .2323 - .2323e-1 - .2323e13434 - - - 1LL - 1ULL - 9332LL - 9332 - 0x2aLL - 0x2aULL - - [[ hello world ]] - - [=[ hello world ]=] - [====[ hello world ]====] - - "another world" - - 'what world' - - - " - hello world - " - - 'yeah - what is going on - here is something cool' - -} -nil - diff --git a/spec/inputs/literals.mp b/spec/inputs/literals.mp new file mode 100644 index 0000000..d4b0326 --- /dev/null +++ b/spec/inputs/literals.mp @@ -0,0 +1,46 @@ + +_ = { + 121 + 121.2323 + 121.2323e-1 + 121.2323e13434 + 2323E34 + 0x12323 + + 0xfF2323 + 0xabcdef + 0xABCDEF + + .2323 + .2323e-1 + .2323e13434 + + + 1LL + 1ULL + 9332LL + 9332 + 0x2aLL + 0x2aULL + + [[ hello world ]] + + [=[ hello world ]=] + [====[ hello world ]====] + + "another world" + + 'what world' + + + " + hello world + " + + 'yeah + what is going on + here is something cool' + +} +nil + diff --git a/spec/inputs/local.moon b/spec/inputs/local.moon deleted file mode 100644 index 33251a9..0000000 --- a/spec/inputs/local.moon +++ /dev/null @@ -1,94 +0,0 @@ - -do - local a - local a,b,c - - b,g = 23232 - - -do - x = 1212 - something = -> - local x - x = 1212 - -do - local * - y = 2323 - z = 2323 - -do - local * - print "Nothing Here!" - -do - local ^ - x = 3434 - y = 3434 - X = 3434 - Y = "yeah" - -do - local ^ - x,y = "a", "b" - -do - local * - x,y = "a", "b" - - -do - local * - if something - x = 2323 - -do - local * - do - x = "one" - - x = 100 - - do - x = "two" - -do - local * - k = if what - 10 - x = 100 - - {:a,:b, :c} = y - - -do - local * - - a = 100 - print "hi" - b = 200 - - local * - c = 100 - print "hi" - d = 200 - d = 2323 - - -do - local ^ - lowercase = 5 - Uppercase = 3 - - class One - Five = 6 - - class Two - class No - -do - local * - -- this generates a nil value in the body - for a in *{} do _ = a - -g = 2323 -- test if anything leaked diff --git a/spec/inputs/local.mp b/spec/inputs/local.mp new file mode 100644 index 0000000..33251a9 --- /dev/null +++ b/spec/inputs/local.mp @@ -0,0 +1,94 @@ + +do + local a + local a,b,c + + b,g = 23232 + + +do + x = 1212 + something = -> + local x + x = 1212 + +do + local * + y = 2323 + z = 2323 + +do + local * + print "Nothing Here!" + +do + local ^ + x = 3434 + y = 3434 + X = 3434 + Y = "yeah" + +do + local ^ + x,y = "a", "b" + +do + local * + x,y = "a", "b" + + +do + local * + if something + x = 2323 + +do + local * + do + x = "one" + + x = 100 + + do + x = "two" + +do + local * + k = if what + 10 + x = 100 + + {:a,:b, :c} = y + + +do + local * + + a = 100 + print "hi" + b = 200 + + local * + c = 100 + print "hi" + d = 200 + d = 2323 + + +do + local ^ + lowercase = 5 + Uppercase = 3 + + class One + Five = 6 + + class Two + class No + +do + local * + -- this generates a nil value in the body + for a in *{} do _ = a + +g = 2323 -- test if anything leaked diff --git a/spec/inputs/loops.moon b/spec/inputs/loops.moon deleted file mode 100644 index 24d960f..0000000 --- a/spec/inputs/loops.moon +++ /dev/null @@ -1,142 +0,0 @@ - -for x=1,10 - print "yeah" - -for x=1,#something - print "yeah" - -for y=100,60,-3 - print "count down", y - -for a=1,10 do print "okay" - -for a=1,10 - for b = 2,43 - print a,b - -for i in iter - for j in yeah - x = 343 + i + j - print i, j - -for x in *something - print x - -for k,v in pairs hello do print k,v - -for x in y, z - print x - -for x in y, z, k - print x - - -x = -> - for x in y - _ = y - -hello = {1,2,3,4,5} - -x = for y in *hello - if y % 2 == 0 - y - -x = -> - for x in *hello - _ = y - -t = for i=10,20 do i * 2 - -hmm = 0 -y = for j = 3,30, 8 - hmm += 1 - j * hmm - -_ = -> - for k=10,40 - _ = "okay" - -_ = -> - return for k=10,40 - "okay" - -while true do print "name" - -while 5 + 5 - print "okay world" - working man - -while also do - i work too - _ = "okay" - -i = 0 -x = while i < 10 - i += 1 - --- values that can'e be coerced - -x = for thing in *3 - y = "hello" - -x = for x=1,2 - y = "hello" - - --- continue - -while true - continue if false - print "yes" - break if true - print "no" - -a = 1 -repeat - a += 1 - if a == 5 - continue - if a == 6 - break - print a -until a == 10 - -for x=1,10 - continue if x > 3 and x < 7 - print x - - -list = for x=1,10 - continue if x > 3 and x < 7 - x - - -for a in *{1,2,3,4,5,6} - continue if a == 1 - continue if a == 3 - print a - - - -for x=1,10 - continue if x % 2 == 0 - for y = 2,12 - continue if y % 3 == 0 - - -while true - continue if false - break - -while true - continue if false - return 22 - --- - -do - xxx = {1,2,3,4} - for thing in *xxx - print thing - - diff --git a/spec/inputs/loops.mp b/spec/inputs/loops.mp new file mode 100644 index 0000000..24d960f --- /dev/null +++ b/spec/inputs/loops.mp @@ -0,0 +1,142 @@ + +for x=1,10 + print "yeah" + +for x=1,#something + print "yeah" + +for y=100,60,-3 + print "count down", y + +for a=1,10 do print "okay" + +for a=1,10 + for b = 2,43 + print a,b + +for i in iter + for j in yeah + x = 343 + i + j + print i, j + +for x in *something + print x + +for k,v in pairs hello do print k,v + +for x in y, z + print x + +for x in y, z, k + print x + + +x = -> + for x in y + _ = y + +hello = {1,2,3,4,5} + +x = for y in *hello + if y % 2 == 0 + y + +x = -> + for x in *hello + _ = y + +t = for i=10,20 do i * 2 + +hmm = 0 +y = for j = 3,30, 8 + hmm += 1 + j * hmm + +_ = -> + for k=10,40 + _ = "okay" + +_ = -> + return for k=10,40 + "okay" + +while true do print "name" + +while 5 + 5 + print "okay world" + working man + +while also do + i work too + _ = "okay" + +i = 0 +x = while i < 10 + i += 1 + +-- values that can'e be coerced + +x = for thing in *3 + y = "hello" + +x = for x=1,2 + y = "hello" + + +-- continue + +while true + continue if false + print "yes" + break if true + print "no" + +a = 1 +repeat + a += 1 + if a == 5 + continue + if a == 6 + break + print a +until a == 10 + +for x=1,10 + continue if x > 3 and x < 7 + print x + + +list = for x=1,10 + continue if x > 3 and x < 7 + x + + +for a in *{1,2,3,4,5,6} + continue if a == 1 + continue if a == 3 + print a + + + +for x=1,10 + continue if x % 2 == 0 + for y = 2,12 + continue if y % 3 == 0 + + +while true + continue if false + break + +while true + continue if false + return 22 + +-- + +do + xxx = {1,2,3,4} + for thing in *xxx + print thing + + diff --git a/spec/inputs/macro.moon b/spec/inputs/macro.moon deleted file mode 100644 index aa8356c..0000000 --- a/spec/inputs/macro.moon +++ /dev/null @@ -1,188 +0,0 @@ -macro block init = -> - with require "moonp" - package.moonpath = "?.moon;./spec/inputs/?.moon" - "" - -$init! - -import "macro_export" as {$myconfig:$config, :$showMacro, :$asserts, :$assert} - -$asserts item == nil - -$myconfig false - -v = $assert item == nil - -macro expr and = (...)-> - values = [value for value in *{...}] - $showMacro "and", "#{ table.concat values, " and " }" - -if $and f1! - print "OK" - -if $and f1!, f2!, f3! - print "OK" - -macro expr in = (target, ...)-> - values = [value for value in *{...}] - $showMacro "in", "#{ table.concat ["#{target} == #{item}" for item in *values], " or " }" - -if x |> $in "Apple", "Pig", "Dog" - print "exist" - -macro expr map = (items, action)-> - $showMacro "map", "[#{action} for _ in *#{items}]" - -macro expr filter = (items, action)-> - $showMacro "filter", "[_ for _ in *#{items} when #{action}]" - -macro expr reduce = (items, def, action)-> - $showMacro "reduce", "if ##{items} == 0 - #{def} -else - _1 = #{def} - for _2 in *#{items} - _1 = #{action} - _1" - -macro block foreach = (items, action)-> - $showMacro "foreach", "for _ in *#{items} - #{action}" - -macro expr pipe = (...)-> - switch select "#", ... - when 0 then return "" - when 1 then return ... - ops = {...} - last = ops[1] - stmts = for i = 2,#ops - stmt = "\tlocal _#{i} = #{last} |> #{ops[i]}" - last = "_#{i}" - stmt - res = "do -#{table.concat stmts, "\n"} - #{last}" - $showMacro "pipe", res - -{1,2,3} |> $map(_ * 2) |> $filter(_ > 4) |> $foreach print _ - -$foreach $filter($map({1,2,3}, _ * 2), _ > 4), print _ - -val = $pipe( - {1, 2, 3} - $map(_ * 2) - $filter(_ > 4) - $reduce(0, _1 + _2) -) - -macro expr plus = (a, b)-> "#{a} + #{b}" - -$plus(1,2)\call 123 - -res = 1 |> $plus 2 - -macro expr curry = (...)-> - args = {...} - len = #args - body = args[len] - def = table.concat ["(#{args[i]})->" for i = 1, len - 1] - "#{def}\n#{body\gsub "^do%s*\n",""}" - -f = $curry x,y,z,do - print x,y,z - -macro expr get_inner = (var)-> "do - a = 1 - a + 1" - -macro expr get_inner_hygienic = (var)-> "(-> - local a = 1 - a + 1)!" - -do - a = 8 - a = $get_inner! - a += $get_inner! - print a - -do - a = 8 - a = $get_inner_hygienic! - a += $get_inner_hygienic! - print a - -macro lua lua = (codes)-> "#{codes}" - -x = 0 - -$lua [[ -local function f(a) - return a + 1 -end -x = x + f(3) -]] - -print x - -macro lua def = (fname, ...)-> - args = {...} - last = table.remove args - $showMacro "def", "local function #{fname}(#{table.concat args, ', '}) - #{last} -end" - -sel = (a, b, c)-> if a then b else c - -$def sel, a, b, c, [[ - if a then - return b - else - return c - end -]] - -$def dummy,[[ -]] - -import 'underscore' as _ - -macro expr chain = (...)-> $showMacro "chain",table.concat {...}, "\\" - -a = $chain( - _({1, 2, 3, 4, -2, 3}) - chain! - map(=> @ * 2) - filter(=> @ > 3) - value! -) - -macro block chainB = (...)-> - switch select "#", ... - when 0 then return "" - when 1 then return ... - items = {...} - last = nil - stmts = for i = 1,#items - stmt = if i == #items - "\t#{last and "#{last}\\" or ""}#{items[i]}" - else - "\tlocal _#{i} = #{last and "#{last}\\" or ""}#{items[i]}" - last = "_#{i}" - stmt - res = "do -#{table.concat stmts, "\n"} -" - $showMacro "chainB",res - -$chainB( - _{1, 2, 3, 4, -2, 3} - chain! - map => @ * 2 - filter => @ > 3 - each => print @ -) - -macro block implicitReturnblockMacroIsAllowed = -> "123" - -$implicitReturnblockMacroIsAllowed! - diff --git a/spec/inputs/macro.mp b/spec/inputs/macro.mp new file mode 100644 index 0000000..c7ec79c --- /dev/null +++ b/spec/inputs/macro.mp @@ -0,0 +1,190 @@ +macro block init = -> + with require "moonp" + package.moonpath = "?.mp;./spec/inputs/?.mp" + "" + +$init! + +import "macro_export" as {$myconfig:$config, :$showMacro, :$asserts, :$assert} + +$asserts item == nil + +$myconfig false + +v = $assert item == nil + +macro expr and = (...)-> + values = [value for value in *{...}] + $showMacro "and", "#{ table.concat values, " and " }" + +if $and f1! + print "OK" + +if $and f1!, f2!, f3! + print "OK" + +macro expr in = (target, ...)-> + values = [value for value in *{...}] + $showMacro "in", table.concat ["#{target} == #{item}" for item in *values], " or " + +if x |> $in "Apple", "Pig", "Dog" + print "exist" + +macro expr map = (items, action)-> + $showMacro "map", "[#{action} for _ in *#{items}]" + +macro expr filter = (items, action)-> + $showMacro "filter", "[_ for _ in *#{items} when #{action}]" + +macro expr reduce = (items, def, action)-> + $showMacro "reduce", "if ##{items} == 0 + #{def} +else + _1 = #{def} + for _2 in *#{items} + _1 = #{action} + _1" + +macro block foreach = (items, action)-> + $showMacro "foreach", "for _ in *#{items} + #{action}" + +macro expr pipe = (...)-> + switch select "#", ... + when 0 then return "" + when 1 then return ... + ops = {...} + last = ops[1] + stmts = for i = 2, #ops + stmt = "\tlocal _#{i} = #{last} |> #{ops[i]}" + last = "_#{i}" + stmt + res = "do +#{table.concat stmts, "\n"} + #{last}" + $showMacro "pipe", res + +{1,2,3} |> $map(_ * 2) |> $filter(_ > 4) |> $foreach print _ + +$foreach $filter($map({1,2,3}, _ * 2), _ > 4), print _ + +val = $pipe( + {1, 2, 3} + $map(_ * 2) + $filter(_ > 4) + $reduce(0, _1 + _2) +) + +macro expr plus = (a, b)-> "#{a} + #{b}" + +$plus(1,2)\call 123 + +res = 1 |> $plus 2 + +macro expr curry = (...)-> + args = {...} + len = #args + body = args[len] + def = table.concat ["(#{args[i]})->" for i = 1, len - 1] + "#{def}\n#{body\gsub "^do%s*\n",""}" + +f = $curry x,y,z,do + print x,y,z + +macro expr get_inner = (var)-> "do + a = 1 + a + 1" + +macro expr get_inner_hygienic = (var)-> "(-> + local a = 1 + a + 1)!" + +do + a = 8 + a = $get_inner! + a += $get_inner! + print a + +do + a = 8 + a = $get_inner_hygienic! + a += $get_inner_hygienic! + print a + +macro lua lua = (codes)-> "#{codes}" + +x = 0 + +$lua [[ +local function f(a) + return a + 1 +end +x = x + f(3) +]] + +print x + +macro lua def = (fname, ...)-> + args = {...} + last = table.remove args + $showMacro "def", "local function #{fname}(#{table.concat args, ', '}) + #{last} +end" + +sel = (a, b, c)-> if a then b else c + +$def sel, a, b, c, [[ + if a then + return b + else + return c + end +]] + +$def dummy,[[ +]] + +import 'underscore' as _ + +macro expr chain = (...)-> $showMacro "chain",table.concat {...}, "\\" + +a = $chain( + _({1, 2, 3, 4, -2, 3}) + chain! + map(=> @ * 2) + filter(=> @ > 3) + value! +) + +macro block chainB = (...)-> + switch select "#", ... + when 0 then return "" + when 1 then return ... + items = {...} + last = nil + stmts = for i = 1,#items + stmt = if i == #items + lastStr = last and "#{last}\\" or "" + "\t#{lastStr}#{items[i]}" + else + lastStr = last and "#{last}\\" or "" + "\tlocal _#{i} = #{lastStr}#{items[i]}" + last = "_#{i}" + stmt + res = "do +#{table.concat stmts, '\n'} +" + $showMacro "chainB", res + +$chainB( + _{1, 2, 3, 4, -2, 3} + chain! + map => @ * 2 + filter => @ > 3 + each => print @ +) + +macro block implicitReturnblockMacroIsAllowed = -> "123" + +$implicitReturnblockMacroIsAllowed! + diff --git a/spec/inputs/macro_export.moon b/spec/inputs/macro_export.moon deleted file mode 100644 index 759c6d1..0000000 --- a/spec/inputs/macro_export.moon +++ /dev/null @@ -1,29 +0,0 @@ -export macro block config = (debugging = true)-> - global debugMode = debugging == "true" - global debugMacro = true - "" - -export macro expr showMacro = (name,res)-> - if debugMacro - "do - txt = #{res} - print '[macro '..#{name}..']' - print txt - txt" - else - "#{res}" - -export macro block asserts = (cond)-> - if debugMode - $showMacro "assert", "assert #{cond}" - else - "" - -export macro expr assert = (cond)-> - if debugMode - $showMacro "assert", "assert #{cond}" - else - "#{cond}" - -$config! - diff --git a/spec/inputs/macro_export.mp b/spec/inputs/macro_export.mp new file mode 100644 index 0000000..759c6d1 --- /dev/null +++ b/spec/inputs/macro_export.mp @@ -0,0 +1,29 @@ +export macro block config = (debugging = true)-> + global debugMode = debugging == "true" + global debugMacro = true + "" + +export macro expr showMacro = (name,res)-> + if debugMacro + "do + txt = #{res} + print '[macro '..#{name}..']' + print txt + txt" + else + "#{res}" + +export macro block asserts = (cond)-> + if debugMode + $showMacro "assert", "assert #{cond}" + else + "" + +export macro expr assert = (cond)-> + if debugMode + $showMacro "assert", "assert #{cond}" + else + "#{cond}" + +$config! + diff --git a/spec/inputs/operators.moon b/spec/inputs/operators.moon deleted file mode 100644 index 57e58d6..0000000 --- a/spec/inputs/operators.moon +++ /dev/null @@ -1,72 +0,0 @@ - --- binary ops -x = 1 + 3 - -y = 1 + - 3 - -z = 1 + - 3 + - 4 - --- - -k = b and c and - g - - -h = thing and - -> - print "hello world" - --- TODO: should fail, indent still set to previous line so it thinks body is --- indented -i = thing or - -> - print "hello world" - -p = thing and - -> -print "hello world" - -s = thing or - -> and 234 - - --- -u = { - color: 1 and 2 and - 3 - 4 - 4 -} - -v = { - color: 1 and - -> - "yeah" - "great" - oksy: 3 ^ -2 -} - --- parens - -nno = ( - yeah + 2 ) - -nn = ( - yeah + 2 -) - -n = hello( - b -) -> - -hello a, - ( - yeah + - 2 - ) - - okay - diff --git a/spec/inputs/operators.mp b/spec/inputs/operators.mp new file mode 100644 index 0000000..57e58d6 --- /dev/null +++ b/spec/inputs/operators.mp @@ -0,0 +1,72 @@ + +-- binary ops +x = 1 + 3 + +y = 1 + + 3 + +z = 1 + + 3 + + 4 + +-- + +k = b and c and + g + + +h = thing and + -> + print "hello world" + +-- TODO: should fail, indent still set to previous line so it thinks body is +-- indented +i = thing or + -> + print "hello world" + +p = thing and + -> +print "hello world" + +s = thing or + -> and 234 + + +-- +u = { + color: 1 and 2 and + 3 + 4 + 4 +} + +v = { + color: 1 and + -> + "yeah" + "great" + oksy: 3 ^ +2 +} + +-- parens + +nno = ( + yeah + 2 ) + +nn = ( + yeah + 2 +) + +n = hello( + b +) -> + +hello a, + ( + yeah + + 2 + ) - + okay + diff --git a/spec/inputs/plus.moon b/spec/inputs/plus.moon deleted file mode 100644 index ca03499..0000000 --- a/spec/inputs/plus.moon +++ /dev/null @@ -1,38 +0,0 @@ -x\do "work" - -func a\do!\end("OK")\if "abc",123 - -res = b.function\do!\while("OK")\if "def",998 - -c.repeat.if\then("xyz")\else res - -print @for,@@function 123 - -if fcolor = message\match "<%w*>" then message = message\gsub "<%->", fcolor - -message = message\gsub "<%->", fcolor if fcolor = message\match "<%w*>" - -valA = func! if func = getfunc! - -valB = do - func = getfunc! - func?! - -global backpack = - something: - yeah: 200 - they: -> - print "hello" - yor_feet"small" - pretty: hair - gold: hmm - yow: 1000 - - eat: goo - yeah: dudd - -start = - something: "cold" - -local bathe = - on: "fire" diff --git a/spec/inputs/plus.mp b/spec/inputs/plus.mp new file mode 100644 index 0000000..ca03499 --- /dev/null +++ b/spec/inputs/plus.mp @@ -0,0 +1,38 @@ +x\do "work" + +func a\do!\end("OK")\if "abc",123 + +res = b.function\do!\while("OK")\if "def",998 + +c.repeat.if\then("xyz")\else res + +print @for,@@function 123 + +if fcolor = message\match "<%w*>" then message = message\gsub "<%->", fcolor + +message = message\gsub "<%->", fcolor if fcolor = message\match "<%w*>" + +valA = func! if func = getfunc! + +valB = do + func = getfunc! + func?! + +global backpack = + something: + yeah: 200 + they: -> + print "hello" + yor_feet"small" + pretty: hair + gold: hmm + yow: 1000 + + eat: goo + yeah: dudd + +start = + something: "cold" + +local bathe = + on: "fire" diff --git a/spec/inputs/return.moon b/spec/inputs/return.moon deleted file mode 100644 index f170ffd..0000000 --- a/spec/inputs/return.moon +++ /dev/null @@ -1,55 +0,0 @@ --- testing `return` propagation - -_ = -> _ = x for x in *things -_ = -> [x for x in *things] - - --- doesn't make sense on purpose -do - return x for x in *things - -do - return [x for x in *things] - -do - return {x,y for x,y in *things} - -_ = -> - if a - if a - a - else - b - elseif b - if a - a - else - b - else - if a - a - else - b - - -do - return if a - if a - a - else - b - elseif b - if a - a - else - b - else - if a - a - else - b - -_ = -> a\b -do a\b - - diff --git a/spec/inputs/return.mp b/spec/inputs/return.mp new file mode 100644 index 0000000..f170ffd --- /dev/null +++ b/spec/inputs/return.mp @@ -0,0 +1,55 @@ +-- testing `return` propagation + +_ = -> _ = x for x in *things +_ = -> [x for x in *things] + + +-- doesn't make sense on purpose +do + return x for x in *things + +do + return [x for x in *things] + +do + return {x,y for x,y in *things} + +_ = -> + if a + if a + a + else + b + elseif b + if a + a + else + b + else + if a + a + else + b + + +do + return if a + if a + a + else + b + elseif b + if a + a + else + b + else + if a + a + else + b + +_ = -> a\b +do a\b + + diff --git a/spec/inputs/string.moon b/spec/inputs/string.moon deleted file mode 100644 index 5d8f772..0000000 --- a/spec/inputs/string.moon +++ /dev/null @@ -1,66 +0,0 @@ - -hi = "hello" -hello = "what the heckyes" -print hi - -umm = 'umm' - -here, another = "yeah", 'world' - -aye = "YU'M" -you '"hmmm" I said' - -print aye, you - -another = [[ hello world ]] - - -hi_there = [[ - hi there -]] - -well = [==[ "helo" ]==] - -hola = [===[ - eat noots]===] - -mm = [[well trhere]] - -oo = "" - -x = "\\" -x = "a\\b" -x = "\\\n" -x = "\"" - --- - -a = "hello #{hello} hello" -b = "#{hello} hello" -c = "hello #{5+1}" -d = "#{hello world}" -e = "#{1} #{2} #{3}" - -f = [[hello #{world} world]] - --- - -a = 'hello #{hello} hello' -b = '#{hello} hello' -c = 'hello #{hello}' - - --- - -_ = "hello" -"hello"\format 1 -"hello"\format(1,2,3) -"hello"\format(1,2,3) 1,2,3 - -"hello"\world! -"hello"\format!.hello 1,2,3 -"hello"\format 1,2,3 - -something"hello"\world! -something "hello"\world! - diff --git a/spec/inputs/string.mp b/spec/inputs/string.mp new file mode 100644 index 0000000..5d8f772 --- /dev/null +++ b/spec/inputs/string.mp @@ -0,0 +1,66 @@ + +hi = "hello" +hello = "what the heckyes" +print hi + +umm = 'umm' + +here, another = "yeah", 'world' + +aye = "YU'M" +you '"hmmm" I said' + +print aye, you + +another = [[ hello world ]] + + +hi_there = [[ + hi there +]] + +well = [==[ "helo" ]==] + +hola = [===[ + eat noots]===] + +mm = [[well trhere]] + +oo = "" + +x = "\\" +x = "a\\b" +x = "\\\n" +x = "\"" + +-- + +a = "hello #{hello} hello" +b = "#{hello} hello" +c = "hello #{5+1}" +d = "#{hello world}" +e = "#{1} #{2} #{3}" + +f = [[hello #{world} world]] + +-- + +a = 'hello #{hello} hello' +b = '#{hello} hello' +c = 'hello #{hello}' + + +-- + +_ = "hello" +"hello"\format 1 +"hello"\format(1,2,3) +"hello"\format(1,2,3) 1,2,3 + +"hello"\world! +"hello"\format!.hello 1,2,3 +"hello"\format 1,2,3 + +something"hello"\world! +something "hello"\world! + diff --git a/spec/inputs/stub.moon b/spec/inputs/stub.moon deleted file mode 100644 index 60347e7..0000000 --- a/spec/inputs/stub.moon +++ /dev/null @@ -1,18 +0,0 @@ - - -x = { - val: 100 - hello: => - print @val -} - -fn = x\val -print fn! -print x\val! - - --- ... should be bubbled up anon functions -((...)-> x = hello(...)\world)! - -nil - diff --git a/spec/inputs/stub.mp b/spec/inputs/stub.mp new file mode 100644 index 0000000..60347e7 --- /dev/null +++ b/spec/inputs/stub.mp @@ -0,0 +1,18 @@ + + +x = { + val: 100 + hello: => + print @val +} + +fn = x\val +print fn! +print x\val! + + +-- ... should be bubbled up anon functions +((...)-> x = hello(...)\world)! + +nil + diff --git a/spec/inputs/switch.moon b/spec/inputs/switch.moon deleted file mode 100644 index ac3dbea..0000000 --- a/spec/inputs/switch.moon +++ /dev/null @@ -1,64 +0,0 @@ - -switch value - when "cool" - print "hello world" - - -switch value - when "cool" - print "hello world" - else - print "okay rad" - - -switch value - when "cool" - print "hello world" - when "yeah" - _ = [[FFFF]] + [[MMMM]] - when 2323 + 32434 - print "okay" - else - print "okay rad" - -out = switch value - when "cool" then print "hello world" - else print "okay rad" - -out = switch value - when "cool" then xxxx - when "umm" then 34340 - else error "this failed big time" - -with something - switch \value! - when .okay - _ = "world" - else - _ = "yesh" - -fix this -call_func switch something - when 1 then "yes" - else "no" - --- - -switch hi - when hello or world - _ = greene - --- - -switch hi - when "one", "two" - print "cool" - when "dad" - _ = no - -switch hi - when 3+1, hello!, (-> 4)! - yello - else - print "cool" - diff --git a/spec/inputs/switch.mp b/spec/inputs/switch.mp new file mode 100644 index 0000000..ac3dbea --- /dev/null +++ b/spec/inputs/switch.mp @@ -0,0 +1,64 @@ + +switch value + when "cool" + print "hello world" + + +switch value + when "cool" + print "hello world" + else + print "okay rad" + + +switch value + when "cool" + print "hello world" + when "yeah" + _ = [[FFFF]] + [[MMMM]] + when 2323 + 32434 + print "okay" + else + print "okay rad" + +out = switch value + when "cool" then print "hello world" + else print "okay rad" + +out = switch value + when "cool" then xxxx + when "umm" then 34340 + else error "this failed big time" + +with something + switch \value! + when .okay + _ = "world" + else + _ = "yesh" + +fix this +call_func switch something + when 1 then "yes" + else "no" + +-- + +switch hi + when hello or world + _ = greene + +-- + +switch hi + when "one", "two" + print "cool" + when "dad" + _ = no + +switch hi + when 3+1, hello!, (-> 4)! + yello + else + print "cool" + diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon deleted file mode 100644 index af72f73..0000000 --- a/spec/inputs/syntax.moon +++ /dev/null @@ -1,396 +0,0 @@ -#!/this/is/ignored - -a = 1 + 2* 3 / 6 - -a, bunch, go, here = another, world - -func arg1, arg2, another, arg3 - -here, we = () ->, yeah -the, different = () -> approach; yeah - -dad() -dad(lord) -hello(one,two)() -(5 + 5)(world) - -fun(a)(b) - -fun(a) b - -fun(a) b, bad hello - -hello world what are you doing here - - -what(the)[3243] world, yeck heck - -hairy[hands][are](gross) okay okay[world] - -_ = (get[something] + 5)[years] - -i,x = 200, 300 - -yeah = (1 + 5) * 3 -yeah = ((1+5)*3)/2 -yeah = ((1+5)*3)/2 + i % 100 - -whoa = (1+2) * (3+4) * (4+5) - -_ = -> - if something - return 1,2,4 - - print "hello" - -_ = -> - if hello - "heloo", "world" - else - no, way - - -_ = -> 1,2,34 - -return 5 + () -> 4 + 2 - -return 5 + (() -> 4) + 2 - -print 5 + () -> - _ = 34 - good nads - - -something 'else', "ya" - -something'else' -something"else" - -_ = something[[hey]] * 2 -_ = something[======[hey]======] * 2 -_ = something[ [======[hey]======] ] * 2 - - -_ = something'else', 2 -_ = something"else", 2 -_ = something[[else]], 2 -_ = something[ [[else]] ], 2 - -something 'else', 2 -something "else", 2 -something [[else]], 2 - -_ = here(we)"go"[12123] - --- this runs -something = - test: 12323 - what: -> print "hello world" - -print something.test - -frick = hello: "world" - -argon = - num: 100 - world: (self) -> - print self.num - return { - something: -> print "hi from something" - } - somethin: (self, str) -> - print "string is", str - return world: (a,b) -> print "sum", a + b - -something.what() -argon\world().something() - -argon\somethin"200".world(1,2) - -x = -434 - -x = -hello world one two - -hi = -"herfef" - -x = -[x for x in x] - -print "hello" if cool -print "hello" unless cool -print "hello" unless 1212 and 3434 -- hello -print "hello" for i=1,10 - -print "nutjob" - -if hello then _ = 343 - -print "what" if cool - -((...)-> arg = {...})! - -x = (...) -> - dump {...} - - -x = not true - -y = not(5+5) - - -y = #"hello" - -x = #{#{},#{1},#{1,2}} - -_ = hello, world - -something\hello(what) a,b -something\hello what -something.hello\world a,b -something.hello\world(1,2,3) a,b - - -x = 1232 -x += 10 + 3 -j -= "hello" -y *= 2 -y /= 100 -m %= 2 -hello ..= "world" - -@@something += 10 -@something += 10 - -a["hello"] += 10 -a["hello#{tostring ff}"] += 10 -a[four].x += 10 - -x = 0 -_ = (if ntype(v) == "fndef" then x += 1) for v in *values - - -hello = - something: world - if: "hello" - else: 3434 - function: "okay" - good: 230203 - - -div class: "cool" - -_ = 5 + what wack -what whack + 5 - -_ = 5 - what wack -what whack - 5 - -x = hello - world - something - -((something = with what - \cool 100) -> - print something)! - -if something - _ = 03589 - --- okay what about this - -else - _ = 3434 - - -if something - _ = yeah - - -elseif "ymmm" - - print "cool" - -else - - _ = okay - - --- test names containing keywords -x = notsomething -y = ifsomething -z = x and b -z = x andb - - --- undelimited tables - -while 10 > something - something: "world" - print "yeah" - -x = - okay: sure - -yeah - okay: man - sure: sir - -hello "no comma" - yeah: dada - another: world - -hello "comma", - something: hello_world - frick: you - --- creates one table -another hello, one, - two, three, four, yeah: man - okay: yeah - fine: alright - -another hello, one, - two, three, four, - yeah: man, okay: yeah - * fine: alright, - okay: 1 - * fine: alright, - okay: 2 - -another hello, one, two, three, four, - yeah: man - okay: yeah - -another hello, one, two, three, four, yeah: man - okay: yeah - -ajax url, - (data) -> - process data, - (error) -> - print error - --- -a += 3 - 5 -a *= 3 + 5 -a *= 3 -a >>= 3 -a <<= 3 -a /= func "cool" - ---- - -x.then = "hello" -x.while.true = "hello" - --- - -x or= "hello" -x and= "hello" - --- - -z = a-b -z = a -b -z = a - b -z = a- b - - --- cooool - -str = --[[ -This is a multi line comment. -It's OK. -]] strA \ -- comment 1 - .. strB \ -- comment 2 - .. strC - -func --[[port]] 3000, --[[ip]] "192.168.1.1" - -f = -> - a,b, \ - c,d, \ - e,f - -f = -> - a,b \ - ,c,d \ - ,e,f - -with obj - invoke( - --[[arg1]] \func!, - --[[arg2]] 123, - --[[arg3]] "abc" - ) - -invokeA( - invokeB( - invokeC 123 - ) -) - -123 - |> invokeC - |> invokeB - |> invokeA - -v = { - a -1 - a( --1) - a \ -- 1 - a-1 - a - 1 - a - -1 - a- -1 - a - --[[123]]1 - - a ~1 - a( -~1) - a \ -~ 1 - a~1 - a ~ 1 - a ~ -1 - a~ -1 - a ~ --[[123]]1 -} - -do - a = 1 \ - + 2 \ - * 3 / - 4 - - _1 = f1 -1 \ - + 2 \ - + 3 - - _2 = f1 - 1 \ - + 2 \ - + 3 - - f2 = (x)-> print x \ - +1 - - a = f2! - -1 |> f2 - - a = f2! \ - - 1 |> f2 - - _1 \ - ,_2 \ - ,_3 \ - ,_4 = 1 \ - ,f 2 \ - ,3 \ - ,f 4, \ - 4 - -nil - diff --git a/spec/inputs/syntax.mp b/spec/inputs/syntax.mp new file mode 100644 index 0000000..1bb962f --- /dev/null +++ b/spec/inputs/syntax.mp @@ -0,0 +1,396 @@ +#!/this/is/ignored + +a = 1 + 2* 3 / 6 + +a, bunch, go, here = another, world + +func arg1, arg2, another, arg3 + +here, we = () ->, yeah +the, different = () -> approach; yeah + +dad() +dad(lord) +hello(one,two)() +(5 + 5)(world) + +fun(a)(b) + +fun(a) b + +fun(a) b, bad hello + +hello world what are you doing here + + +what(the)[3243] world, yeck heck + +hairy[hands][are](gross) okay okay[world] + +_ = (get[something] + 5)[years] + +i,x = 200, 300 + +yeah = (1 + 5) * 3 +yeah = ((1+5)*3)/2 +yeah = ((1+5)*3)/2 + i % 100 + +whoa = (1+2) * (3+4) * (4+5) + +_ = -> + if something + return 1,2,4 + + print "hello" + +_ = -> + if hello + "heloo", "world" + else + no, way + + +_ = -> 1,2,34 + +return 5 + () -> 4 + 2 + +return 5 + (() -> 4) + 2 + +print 5 + () -> + _ = 34 + good nads + + +something 'else', "ya" + +something'else' +something"else" + +_ = something[[hey]] * 2 +_ = something[======[hey]======] * 2 +_ = something[ [======[hey]======] ] * 2 + + +_ = something'else', 2 +_ = something"else", 2 +_ = something[[else]], 2 +_ = something[ [[else]] ], 2 + +something 'else', 2 +something "else", 2 +something [[else]], 2 + +_ = here(we)"go"[12123] + +-- this runs +something = + test: 12323 + what: -> print "hello world" + +print something.test + +frick = hello: "world" + +argon = + num: 100 + world: (self) -> + print self.num + return { + something: -> print "hi from something" + } + somethin: (self, str) -> + print "string is", str + return world: (a,b) -> print "sum", a + b + +something.what() +argon\world().something() + +argon\somethin"200".world(1,2) + +x = -434 + +x = -hello world one two + +hi = -"herfef" + +x = -[x for x in x] + +print "hello" if cool +print "hello" unless cool +print "hello" unless 1212 and 3434 -- hello +print "hello" for i=1,10 + +print "nutjob" + +if hello then _ = 343 + +print "what" if cool + +((...)-> arg = {...})! + +x = (...) -> + dump {...} + + +x = not true + +y = not(5+5) + + +y = #"hello" + +x = #{#{},#{1},#{1,2}} + +_ = hello, world + +something\hello(what) a,b +something\hello what +something.hello\world a,b +something.hello\world(1,2,3) a,b + + +x = 1232 +x += 10 + 3 +j -= "hello" +y *= 2 +y /= 100 +m %= 2 +hello ..= "world" + +@@something += 10 +@something += 10 + +a["hello"] += 10 +a["hello#{tostring ff}"] += 10 +a[four].x += 10 + +x = 0 +_ = (if ntype(v) == "fndef" then x += 1) for v in *values + + +hello = + something: world + if: "hello" + else: 3434 + function: "okay" + good: 230203 + + +div class: "cool" + +_ = 5 + what wack +what whack + 5 + +_ = 5 - what wack +what whack - 5 + +x = hello - world - something + +((something = with what + \cool 100) -> + print something)! + +if something + _ = 03589 + +-- okay what about this + +else + _ = 3434 + + +if something + _ = yeah + + +elseif "ymmm" + + print "cool" + +else + + _ = okay + + +-- test names containing keywords +x = notsomething +y = ifsomething +z = x and b +z = x andb + + +-- undelimited tables + +while 10 > something + something: "world" + print "yeah" + +x = + okay: sure + +yeah + okay: man + sure: sir + +hello "no comma" + yeah: dada + another: world + +hello "comma", + something: hello_world + frick: you + +-- creates one table +another hello, one, + two, three, four, yeah: man + okay: yeah + fine: alright + +another hello, one, + two, three, four, + yeah: man, okay: yeah + * fine: alright, + okay: 1 + * fine: alright, + okay: 2 + +another hello, one, two, three, four, + yeah: man + okay: yeah + +another hello, one, two, three, four, yeah: man + okay: yeah + +ajax url, + (data) -> + process data, + (error) -> + print error + +-- +a += 3 - 5 +a *= 3 + 5 +a *= 3 +a >>= 3 +a <<= 3 +a /= func "cool" + +--- + +x.then = "hello" +x.while.true = "hello" + +-- + +x or= "hello" +x and= "hello" + +-- + +z = a-b +z = a -b +z = a - b +z = a- b + + +-- cooool + +str = --[[ +This is a multi line comment. +It's OK. +]] strA \ -- comment 1 + .. strB \ -- comment 2 + .. strC + +func --[[port]] 3000, --[[ip]] "192.168.1.1" + +f = -> + a,b, \ + c,d, \ + e,f + +f = -> + a,b \ + ,c,d \ + ,e,f + +with obj + invoke( + --[[arg1]] \func!, + --[[arg2]] 123, + --[[arg3]] "abc" + ) + +invokeA( + invokeB( + invokeC 123 + ) +) + +123 + |> invokeC + |> invokeB + |> invokeA + +v = { + a -1 + a( +-1) + a \ +- 1 + a-1 + a - 1 + a - +1 + a- +1 + a - --[[123]]1 + + a ~1 + a( +~1) + a \ +~ 1 + a~1 + a ~ 1 + a ~ +1 + a~ +1 + a ~ --[[123]]1 +} + +do + a = 1 \ + + 2 \ + * 3 / + 4 + + _1 = f1 -1 \ + + 2 \ + + 3 + + _2 = f1 - 1 \ + + 2 \ + + 3 + + f2 = (x)-> print x \ + +1 + + a = f2! + -1 |> f2 + + a = f2! \ + - 1 |> f2 + + _1 \ + ,_2 \ + ,_3 \ + ,_4 = 1 \ + ,f 2 \ + ,3 \ + ,f 4, \ + 4 + +nil + diff --git a/spec/inputs/tables.moon b/spec/inputs/tables.moon deleted file mode 100644 index e816003..0000000 --- a/spec/inputs/tables.moon +++ /dev/null @@ -1,207 +0,0 @@ - -backpack = - something: - yeah: 200 - they: -> - print "hello" - yor_feet"small" - pretty: hair - gold: hmm - yow: 1000 - - eat: goo - yeah: dudd - - -start = - something: "cold" - -bathe = - on: "fire" - -another = - [4]: 232 - ["good food"]: "is the best" - -fwip = - something: hello"what", number: 2323, - what: yo "momma", "yeah", - fruit: basket - nuts: day - - -frick = hello: "world" - -frack, best = hello: "world", rice: 3434, "what" - -ya = { 1,2,3, key: 100, 343, "hello", umm: 232 } - - -x = { 1,2, - 4343, 343 ,343 } - - -g, p = { - 1,2, nowy: "yes", 3,4, - hey: 232, another: "day" -}, 234 - -annother = { - 1,2,3 - 3,4,5 - 6,7,8 -} - -yeah = { - [232]: 3434, "helo" - ice: "cake" -} - --- confusing stuff... -whatabout = { - hello world, another - what, about, now - - hello"world", yeah - hello "world", yeah -} - -x = - -- yeah - something: => "hello" - cool: -- umm - --so ething - bed: { - 2323,2323 - } - red: 2343 -- here - -- what - name: (node) => @value node -- here - -- comment me --- okay - - -x = { :something, something: something } - -y = { - :hi, :there, :how, :you - :thing -} - -call_me "hello", :x, :y, :z - -t = { - a: 'a' - [b]: 'b' -} - -xam = { - hello: 1234 - "hello": 12354 - [[hello]]: 12354 - ["hello"]: 12354 - [ [[hello]] ]: 12354 -} - - -kam = { - hello: 12 - goodcheese: - "mmm" - - yeah: - 12 + 232 - - lets: - keepit going: true, - okay: "yeah" - - more: - { - 1, [x for x=1,10] - } - - [{"one", "two"}]: - one_thing => -} - --- both of these have desirable output -keepit going: true, - okay: "yeah", - workd: "okay" - -thing what: - "great", no: - "more" - okay: 123 - - --- -thing what: - "great", no: - "more" -_ = okay: 123 -- a anon table - - --- - -k = { "hello": "world" } -k = { 'hello': 'world' } -k = { "hello": 'world', "hat": "zat" } - -please "hello": "world" -k = "hello": "world", "one": "zone" - -f = "one", "two": three, "four" -f = "two": three, "four" -f = { "one", "two": three, "four" } - - -j = "one", "two": three, "four": five, 6, 7 - -heroine = - name: "Christina" - age: 18 - job: "Princess" - likes: - * name: "kittens" - img: "/image/kittens.png" - * name: "flower" - img: "/image/flower.png" - items: - * name: "ring" - amount: 2 - * name: "necklace" - amount: 1 - status: - desc: "weak" - * attribute: "health" - value: 50 - * attribute: "mana" - value: 100 - -inventory = - equipment: - * "sword" - * "shield" - items: - * name: "potion" - count: 10 - * name: "bread" - count: 3 - -items = - * func! - * with tb - .abc = 123 - * {1, 2, 3} - * f {1, 2, 3} - * f - * 1 - * 2 - * 3 - * [i for i = 1, 3] - * "#{if a then b}" - -nil - diff --git a/spec/inputs/tables.mp b/spec/inputs/tables.mp new file mode 100644 index 0000000..e816003 --- /dev/null +++ b/spec/inputs/tables.mp @@ -0,0 +1,207 @@ + +backpack = + something: + yeah: 200 + they: -> + print "hello" + yor_feet"small" + pretty: hair + gold: hmm + yow: 1000 + + eat: goo + yeah: dudd + + +start = + something: "cold" + +bathe = + on: "fire" + +another = + [4]: 232 + ["good food"]: "is the best" + +fwip = + something: hello"what", number: 2323, + what: yo "momma", "yeah", + fruit: basket + nuts: day + + +frick = hello: "world" + +frack, best = hello: "world", rice: 3434, "what" + +ya = { 1,2,3, key: 100, 343, "hello", umm: 232 } + + +x = { 1,2, + 4343, 343 ,343 } + + +g, p = { + 1,2, nowy: "yes", 3,4, + hey: 232, another: "day" +}, 234 + +annother = { + 1,2,3 + 3,4,5 + 6,7,8 +} + +yeah = { + [232]: 3434, "helo" + ice: "cake" +} + +-- confusing stuff... +whatabout = { + hello world, another + what, about, now + + hello"world", yeah + hello "world", yeah +} + +x = + -- yeah + something: => "hello" + cool: -- umm + --so ething + bed: { + 2323,2323 + } + red: 2343 -- here + -- what + name: (node) => @value node -- here + -- comment me +-- okay + + +x = { :something, something: something } + +y = { + :hi, :there, :how, :you + :thing +} + +call_me "hello", :x, :y, :z + +t = { + a: 'a' + [b]: 'b' +} + +xam = { + hello: 1234 + "hello": 12354 + [[hello]]: 12354 + ["hello"]: 12354 + [ [[hello]] ]: 12354 +} + + +kam = { + hello: 12 + goodcheese: + "mmm" + + yeah: + 12 + 232 + + lets: + keepit going: true, + okay: "yeah" + + more: + { + 1, [x for x=1,10] + } + + [{"one", "two"}]: + one_thing => +} + +-- both of these have desirable output +keepit going: true, + okay: "yeah", + workd: "okay" + +thing what: + "great", no: + "more" + okay: 123 + + +-- +thing what: + "great", no: + "more" +_ = okay: 123 -- a anon table + + +-- + +k = { "hello": "world" } +k = { 'hello': 'world' } +k = { "hello": 'world', "hat": "zat" } + +please "hello": "world" +k = "hello": "world", "one": "zone" + +f = "one", "two": three, "four" +f = "two": three, "four" +f = { "one", "two": three, "four" } + + +j = "one", "two": three, "four": five, 6, 7 + +heroine = + name: "Christina" + age: 18 + job: "Princess" + likes: + * name: "kittens" + img: "/image/kittens.png" + * name: "flower" + img: "/image/flower.png" + items: + * name: "ring" + amount: 2 + * name: "necklace" + amount: 1 + status: + desc: "weak" + * attribute: "health" + value: 50 + * attribute: "mana" + value: 100 + +inventory = + equipment: + * "sword" + * "shield" + items: + * name: "potion" + count: 10 + * name: "bread" + count: 3 + +items = + * func! + * with tb + .abc = 123 + * {1, 2, 3} + * f {1, 2, 3} + * f + * 1 + * 2 + * 3 + * [i for i = 1, 3] + * "#{if a then b}" + +nil + diff --git a/spec/inputs/unless_else.moon b/spec/inputs/unless_else.moon deleted file mode 100644 index b421d4d..0000000 --- a/spec/inputs/unless_else.moon +++ /dev/null @@ -1,5 +0,0 @@ -if a - unless b - print "hi" - elseif c - print "not hi" diff --git a/spec/inputs/unless_else.mp b/spec/inputs/unless_else.mp new file mode 100644 index 0000000..b421d4d --- /dev/null +++ b/spec/inputs/unless_else.mp @@ -0,0 +1,5 @@ +if a + unless b + print "hi" + elseif c + print "not hi" diff --git a/spec/inputs/using.moon b/spec/inputs/using.moon deleted file mode 100644 index fe0a433..0000000 --- a/spec/inputs/using.moon +++ /dev/null @@ -1,22 +0,0 @@ - -hello = "hello" -world = "world" - -_ = (using nil) -> - hello = 3223 - -_ = (a using nil) -> - hello = 3223 - a = 323 - -_ = (a,b,c using a,b,c) -> - a,b,c = 1,2,3 - world = 12321 - -(a,e,f using a,b,c, hello) -> - a,b,c = 1,2,3 - hello = 12321 - world = "yeah" - - - diff --git a/spec/inputs/using.mp b/spec/inputs/using.mp new file mode 100644 index 0000000..fe0a433 --- /dev/null +++ b/spec/inputs/using.mp @@ -0,0 +1,22 @@ + +hello = "hello" +world = "world" + +_ = (using nil) -> + hello = 3223 + +_ = (a using nil) -> + hello = 3223 + a = 323 + +_ = (a,b,c using a,b,c) -> + a,b,c = 1,2,3 + world = 12321 + +(a,e,f using a,b,c, hello) -> + a,b,c = 1,2,3 + hello = 12321 + world = "yeah" + + + diff --git a/spec/inputs/whitespace.moon b/spec/inputs/whitespace.moon deleted file mode 100644 index 329280f..0000000 --- a/spec/inputs/whitespace.moon +++ /dev/null @@ -1,140 +0,0 @@ - -_ = { - 1, 2 -} - -_ = { 1, 2 -} - -_ = { 1, 2 } - -_ = {1,2} - -_ = { -1,2 - -} - -_ = { something 1,2, - 4,5,6, - 3,4,5 -} - -_ = { - a 1,2,3, - 4,5,6 - 1,2,3 -} - - -_ = { - b 1,2,3, - 4,5,6 - 1,2,3, - 1,2,3 -} - -_ = { 1,2,3 } - -_ = { c 1,2,3, -} - - -hello 1,2,3,4, - 1,2,3,4,4,5 - -x 1, - 2, 3, - 4, 5, 6 - - -hello 1,2,3, - world 4,5,6, - 5,6,7,8 - -hello 1,2,3, - world 4,5,6, - 5,6,7,8, - 9,9 - - -_ = { - hello 1,2, - 3,4, - 5, 6 -} - -x = { - hello 1,2,3,4, - 5,6,7 - 1,2,3,4 -} - -if hello 1,2,3, - world, - world - print "hello" - -if hello 1,2,3, - world, - world - print "hello" - - --- - -a( - one, two, three -) - -b( - one, - two, - three -) - - -c(one, two, - three, four) - --- - -v = -> - a, \-- v1 - b, \-- v2 - c -- v3 - -v1, v2, \ - v3 = -> - a; \-- end of function for v1 - b, \-- v2 - c -- v3 - -a, b, \ - c, d, \ -e, f = 1, \ - f2 - :abc; \-- arg2 - 3, \ - 4, \ - f5 abc; \-- arg5 - 6 - -for a, \-- destruct 1 - b, \-- destruct 2 - --[[destruct 3]] c \ - in pairs tb - print a, \ - b, \ - c - -for i = 1, \-- initial - 10, \-- stop - -1 -- step - print i - -local a,\ - b,\ - c - -nil diff --git a/spec/inputs/whitespace.mp b/spec/inputs/whitespace.mp new file mode 100644 index 0000000..329280f --- /dev/null +++ b/spec/inputs/whitespace.mp @@ -0,0 +1,140 @@ + +_ = { + 1, 2 +} + +_ = { 1, 2 +} + +_ = { 1, 2 } + +_ = {1,2} + +_ = { +1,2 + +} + +_ = { something 1,2, + 4,5,6, + 3,4,5 +} + +_ = { + a 1,2,3, + 4,5,6 + 1,2,3 +} + + +_ = { + b 1,2,3, + 4,5,6 + 1,2,3, + 1,2,3 +} + +_ = { 1,2,3 } + +_ = { c 1,2,3, +} + + +hello 1,2,3,4, + 1,2,3,4,4,5 + +x 1, + 2, 3, + 4, 5, 6 + + +hello 1,2,3, + world 4,5,6, + 5,6,7,8 + +hello 1,2,3, + world 4,5,6, + 5,6,7,8, + 9,9 + + +_ = { + hello 1,2, + 3,4, + 5, 6 +} + +x = { + hello 1,2,3,4, + 5,6,7 + 1,2,3,4 +} + +if hello 1,2,3, + world, + world + print "hello" + +if hello 1,2,3, + world, + world + print "hello" + + +-- + +a( + one, two, three +) + +b( + one, + two, + three +) + + +c(one, two, + three, four) + +-- + +v = -> + a, \-- v1 + b, \-- v2 + c -- v3 + +v1, v2, \ + v3 = -> + a; \-- end of function for v1 + b, \-- v2 + c -- v3 + +a, b, \ + c, d, \ +e, f = 1, \ + f2 + :abc; \-- arg2 + 3, \ + 4, \ + f5 abc; \-- arg5 + 6 + +for a, \-- destruct 1 + b, \-- destruct 2 + --[[destruct 3]] c \ + in pairs tb + print a, \ + b, \ + c + +for i = 1, \-- initial + 10, \-- stop + -1 -- step + print i + +local a,\ + b,\ + c + +nil diff --git a/spec/inputs/with.moon b/spec/inputs/with.moon deleted file mode 100644 index 704c494..0000000 --- a/spec/inputs/with.moon +++ /dev/null @@ -1,118 +0,0 @@ - -do - a = -> - with something - print .hello - print hi - print "world" - -do - with leaf - .world! - .world 1,2,3 - - g = .what.is.this - - .hi 1,2,3 - - \hi(1,2).world 2323 - - \hi "yeah", "man" - .world = 200 - -do - zyzyzy = with something - .set_state "hello world" - -do - x = 5 + with Something! - \write "hello world" - - -do - x = { - hello: with yeah - \okay! - } - -do - with foo - _ = \prop"something".hello - .prop\send(one) - .prop\send one - - --- - -do - with a, b -- b is lost - print .world - - mod = with _M = {} - .Thing = "hi" - - -- operate on a only - with a, b = something, pooh - print .world - - x = with a, b = 1, 2 - print a + b - - print with a, b = 1, 2 - print a + b - - -- assignment lhs must be evaluated in the order they appear - p = with hello!.x, world!.y = 1, 2 - print a + b - --- - -do - x = "hello" - with x - x\upper! - -do - with k = "jo" - print \upper! - -do - with a,b,c = "", "", "" - print \upper! - -do - a = "bunk" - with a,b,c = "", "", "" - print \upper! - -do - with j - print \upper! - -do - with k.j = "jo" - print \upper! - -do - with a - print .b - -- nested `with`s should change the scope correctly - with .c - print .d - -do - with a - -- nested `with`s with assignments should change the scope correctly - with .b = 2 - print .c - -do - _ = -> - with hi - return .a, .b - - -do - with dad - .if "yes" - y = .end.of.function diff --git a/spec/inputs/with.mp b/spec/inputs/with.mp new file mode 100644 index 0000000..704c494 --- /dev/null +++ b/spec/inputs/with.mp @@ -0,0 +1,118 @@ + +do + a = -> + with something + print .hello + print hi + print "world" + +do + with leaf + .world! + .world 1,2,3 + + g = .what.is.this + + .hi 1,2,3 + + \hi(1,2).world 2323 + + \hi "yeah", "man" + .world = 200 + +do + zyzyzy = with something + .set_state "hello world" + +do + x = 5 + with Something! + \write "hello world" + + +do + x = { + hello: with yeah + \okay! + } + +do + with foo + _ = \prop"something".hello + .prop\send(one) + .prop\send one + + +-- + +do + with a, b -- b is lost + print .world + + mod = with _M = {} + .Thing = "hi" + + -- operate on a only + with a, b = something, pooh + print .world + + x = with a, b = 1, 2 + print a + b + + print with a, b = 1, 2 + print a + b + + -- assignment lhs must be evaluated in the order they appear + p = with hello!.x, world!.y = 1, 2 + print a + b + +-- + +do + x = "hello" + with x + x\upper! + +do + with k = "jo" + print \upper! + +do + with a,b,c = "", "", "" + print \upper! + +do + a = "bunk" + with a,b,c = "", "", "" + print \upper! + +do + with j + print \upper! + +do + with k.j = "jo" + print \upper! + +do + with a + print .b + -- nested `with`s should change the scope correctly + with .c + print .d + +do + with a + -- nested `with`s with assignments should change the scope correctly + with .b = 2 + print .c + +do + _ = -> + with hi + return .a, .b + + +do + with dad + .if "yes" + y = .end.of.function diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 8c0746f..6e7db2c 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -53,9 +53,8 @@ inline std::string s(std::string_view sv) { return std::string(sv); } -const std::string_view version() { - return "0.4.15"sv; -} +const std::string_view version = "0.4.16"sv; +const std::string_view extension = "mp"sv; class MoonCompilerImpl { public: @@ -4926,7 +4925,7 @@ private: } case id(): { auto pair = static_cast(item); - macroPairs.emplace_back(_parser.toString(pair->value->name), _parser.toString(pair->key->name)); + macroPairs.emplace_back(_parser.toString(pair->value->name), _parser.toString(pair->key->name)); break; } default: diff --git a/src/MoonP/moon_compiler.h b/src/MoonP/moon_compiler.h index 37a79bf..cb57d57 100644 --- a/src/MoonP/moon_compiler.h +++ b/src/MoonP/moon_compiler.h @@ -17,7 +17,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace MoonP { -const std::string_view version(); +extern const std::string_view version; +extern const std::string_view extension; struct MoonConfig { bool lintGlobalVariable = false; diff --git a/src/MoonP/moonplus.cpp b/src/MoonP/moonplus.cpp index cb6d3ec..c775d75 100644 --- a/src/MoonP/moonplus.cpp +++ b/src/MoonP/moonplus.cpp @@ -122,7 +122,11 @@ int luaopen_moonp(lua_State* L) { lua_getfield(L, -1, "loaded"); // package loaded lua_createtable(L, 0, 0); // package loaded moonp lua_pushcfunction(L, moontolua); // package loaded moonp func - lua_setfield(L, -2, "to_lua"); // moonp["to_lua"] = func, package loaded tb + lua_setfield(L, -2, "to_lua"); // moonp["to_lua"] = func, package loaded moonp + lua_pushlstring(L, &MoonP::version.front(), MoonP::version.size()); // package loaded moonp version + lua_setfield(L, -2, "version"); // loaded["version"] = version, package loaded moonp + lua_pushlstring(L, &MoonP::extension.front(), MoonP::extension.size()); // package loaded moonp ext + lua_setfield(L, -2, "extension"); // loaded["extension"] = ext, package loaded moonp lua_pushcfunction(L, init_stacktraceplus); // package loaded moonp func1 lua_setfield(L, -2, "load_stacktraceplus"); // moonp["load_stacktraceplus"] = func1, package loaded moonp lua_setfield(L, -2, "moonp"); // loaded["moonp"] = moonp, package loaded diff --git a/src/MoonP/moonplus.h b/src/MoonP/moonplus.h index 83d4c75..b18ab64 100644 --- a/src/MoonP/moonplus.h +++ b/src/MoonP/moonplus.h @@ -1,4 +1,4 @@ -R"moonscript_codes( +R"moonplus_codes( --[[ Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin @@ -73,6 +73,7 @@ get_options = function(...) end end create_moonpath = function(package_path) + local extension = moonp.extension local moonpaths do local _accum_0 = { } @@ -87,7 +88,7 @@ create_moonpath = function(package_path) _continue_0 = true break end - _accum_0[_len_0] = prefix .. ".moon" + _accum_0[_len_0] = prefix .. "." .. extension _len_0 = _len_0 + 1 _continue_0 = true until true @@ -134,7 +135,7 @@ moon_loader = function(name) end return res end - return nil, "Could not find moon file" + return nil, "Could not find moonp file" end moon_call = function(f, ...) local args = { @@ -148,7 +149,7 @@ moon_call = function(f, ...) end loadstring = function(...) local options, str, chunk_name, mode, env = get_options(...) - chunk_name = chunk_name or "=(moonscript.loadstring)" + chunk_name = chunk_name or "=(moonplus.loadstring)" local code, err = moonp.to_lua(str, options) if not code then return nil, err @@ -247,4 +248,4 @@ for k, v in pairs({ }) do moonp[k] = v end -)moonscript_codes"; +)moonplus_codes"; diff --git a/src/MoonP/stacktraceplus.h b/src/MoonP/stacktraceplus.h index d658c5c..e884a2c 100644 --- a/src/MoonP/stacktraceplus.h +++ b/src/MoonP/stacktraceplus.h @@ -335,7 +335,7 @@ local function getMoonLineNumber(fname, line) end if file_exist then local codes = moonp.read_file(file_path) - local moonFile = codes:match("^%s*--%s*%[moon%]:%s*([^\n]*)") + local moonFile = codes:match("^%s*--%s*%[moonp%]:%s*([^\n]*)") if moonFile then fname = moonFile:gsub("^%s*(.-)%s*$", "%1") source = codes diff --git a/src/moonp.cpp b/src/moonp.cpp index 68f7b10..25be015 100644 --- a/src/moonp.cpp +++ b/src/moonp.cpp @@ -174,7 +174,7 @@ int main(int narg, const char** args) { break; } }); - std::cout << "Moonscript+ "sv << MoonP::version() << '\n'; + std::cout << "Moonscript+ "sv << MoonP::version << '\n'; while (true) { count++; std::string codes; @@ -366,7 +366,7 @@ int main(int narg, const char** args) { std::cout << help; return 0; } else if (arg == "-v"sv) { - std::cout << "Moonscript+ version: "sv << MoonP::version() << '\n'; + std::cout << "Moonscript+ version: "sv << MoonP::version << '\n'; return 0; } else if (arg == "-o"sv) { ++i; @@ -382,7 +382,7 @@ int main(int narg, const char** args) { if (!item.is_directory()) { auto ext = item.path().extension().string(); for (char& ch : ext) ch = std::tolower(ch); - if (ext == ".moon"sv) { + if (!ext.empty() && ext.substr(1) == MoonP::extension) { files.emplace_back(item.path().string(), item.path().lexically_relative(arg).string()); } } @@ -453,7 +453,7 @@ int main(int narg, const char** args) { if (output) { const auto& codes = std::get<0>(result); if (config.reserveLineNumber) { - auto head = std::string("-- [moon]: "sv) + file.first + '\n'; + auto head = std::string("-- [moonp]: "sv) + file.first + '\n'; output.write(head.c_str(), head.size()); } output.write(codes.c_str(), codes.size()); -- cgit v1.2.3-55-g6feb