From 8d1af508f4173e4af6a4ea98584c1a86619f6a20 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sat, 18 Jan 2020 18:15:24 +0800 Subject: fix Moonscript issue 122, add support for ? operator. --- spec/inputs/assign.moon | 2 +- spec/inputs/class.moon | 30 ++++++++++---------- spec/inputs/comprehension.moon | 14 +++++----- spec/inputs/cond.moon | 12 ++++---- spec/inputs/destructure.moon | 2 +- spec/inputs/do.moon | 2 +- spec/inputs/existential.moon | 8 ++++++ spec/inputs/funcs.moon | 30 ++++++++++---------- spec/inputs/lists.moon | 8 +++--- spec/inputs/literals.moon | 62 +++++++++++++++++++++--------------------- spec/inputs/local.moon | 2 +- spec/inputs/loops.moon | 12 ++++---- spec/inputs/return.moon | 8 +++--- spec/inputs/string.moon | 2 +- spec/inputs/switch.moon | 10 +++---- spec/inputs/syntax.moon | 42 ++++++++++++++-------------- spec/inputs/tables.moon | 2 +- spec/inputs/using.moon | 8 +++--- spec/inputs/whitespace.moon | 22 +++++++-------- spec/inputs/with.moon | 4 +-- 20 files changed, 145 insertions(+), 137 deletions(-) create mode 100644 spec/inputs/existential.moon (limited to 'spec') diff --git a/spec/inputs/assign.moon b/spec/inputs/assign.moon index 1e5e7a6..3e66491 100644 --- a/spec/inputs/assign.moon +++ b/spec/inputs/assign.moon @@ -1,5 +1,5 @@ --> +_ = -> joop = 2302 (hi) -> diff --git a/spec/inputs/class.moon b/spec/inputs/class.moon index 9a98055..2290bc7 100644 --- a/spec/inputs/class.moon +++ b/spec/inputs/class.moon @@ -73,11 +73,11 @@ 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.something(1,2,3,4).world super\yeah"world".okay hi, hi, hi - something.super - super.super.super.super - super\hello + _ = something.super + _ = super.super.super.super + _ = super\hello nil @@ -114,11 +114,11 @@ y = @@ @ = 343 @.hello 2,3,4 -hello[@].world +_ = hello[@].world class Whacko - @hello + _ = @hello if something print "hello world" @@ -132,20 +132,20 @@ print "hello" yyy = -> class Cool - nil + _ = nil -- class a.b.c.D - nil + _ = nil class a.b["hello"] - nil + _ = nil class (-> require "moon")!.Something extends Hello.World - nil + _ = nil -- @@ -160,7 +160,7 @@ print (class WhatsUp).__name export ^ class Something - nil + _ = nil -- @@ -197,17 +197,17 @@ class Whack extends Thing class Wowha extends Thing @butt: -> super! - super.hello + _ = super.hello super\hello! - super\hello + _ = super\hello @zone: cool { -> super! - super.hello + _ = super.hello super\hello! - super\hello + _ = super\hello } nil diff --git a/spec/inputs/comprehension.moon b/spec/inputs/comprehension.moon index 1609d79..f07cf89 100644 --- a/spec/inputs/comprehension.moon +++ b/spec/inputs/comprehension.moon @@ -11,11 +11,11 @@ copy = {k,v for k,v in pairs x when k != "okay"} -- -{ unpack(x) for x in yes } -{ unpack(x) for x in *yes } +_ = { 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}} } +_ = { xxxx for x in yes } +_ = { unpack [a*i for i, a in ipairs x] for x in *{{1,2}, {3,4}} } -- @@ -28,7 +28,7 @@ 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} +_ = {"hello", "world" for i=1,10} -- @@ -44,8 +44,8 @@ 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]]] +_ = [item for item in *items[1 + 2,3+4]] +_ = [item for item in *items[hello! * 4, 2 - thing[4]]] diff --git a/spec/inputs/cond.moon b/spec/inputs/cond.moon index 18e42b9..e8b6283 100644 --- a/spec/inputs/cond.moon +++ b/spec/inputs/cond.moon @@ -1,25 +1,25 @@ you_cool = false -if cool +_ = if cool if you_cool one else if eatdic yeah else - two + _ = two three else no -if cool then no -if cool then no else yes +_ = 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 cool then if cool then okay else what else nah if yeah then no day elseif cool me then okay ya else u way @@ -70,7 +70,7 @@ hello = 5 + if something = 10 z = false -if false +_ = if false one elseif x = true two diff --git a/spec/inputs/destructure.moon b/spec/inputs/destructure.moon index beb79d6..2509968 100644 --- a/spec/inputs/destructure.moon +++ b/spec/inputs/destructure.moon @@ -90,7 +90,7 @@ do do {a,b,c} = z -(z) -> +_ = (z) -> {a,b,c} = z do diff --git a/spec/inputs/do.moon b/spec/inputs/do.moon index 334e68f..21e2127 100644 --- a/spec/inputs/do.moon +++ b/spec/inputs/do.moon @@ -11,7 +11,7 @@ y = do things = "shhh" -> "hello: " .. things --> if something then do "yeah" +_ = -> if something then do "yeah" t = { y: do diff --git a/spec/inputs/existential.moon b/spec/inputs/existential.moon new file mode 100644 index 0000000..97e8de0 --- /dev/null +++ b/spec/inputs/existential.moon @@ -0,0 +1,8 @@ +if {:x} = a?.if?\then?(123)? @?\function 998 + print x + +with abc?!\func?! + if \p? "abc" + return 123 + +@?\func 998 diff --git a/spec/inputs/funcs.moon b/spec/inputs/funcs.moon index 08a29b6..7a4d5d6 100644 --- a/spec/inputs/funcs.moon +++ b/spec/inputs/funcs.moon @@ -2,9 +2,9 @@ x = -> print what --> +_ = -> --> -> -> +_ = -> -> -> go to the barn @@ -27,29 +27,29 @@ x = (...) -> hello! hello.world! -hello!.something -what!["ofefe"] +_ = hello!.something +_ = what!["ofefe"] what! the! heck! -(a,b,c,d,e) -> +_ = (a,b,c,d,e) -> -(a,a,a,a,a) -> +_ = (a,a,a,a,a) -> print a -(x=23023) -> +_ = (x=23023) -> -(x=(y=()->) ->) -> +_ = (x=(y=()->) ->) -> -(x = if something then yeah else no) -> +_ = (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, y) => +_ = (@x, @y) => +_ = (x=1) => +_ = (@x=1,y,@z="hello world") => x -> return @@ -57,7 +57,7 @@ y -> return 1 z -> return 1, "hello", "world" k -> if yes then return else return --> real_name if something +_ = -> real_name if something -- @@ -97,7 +97,7 @@ f( x = (a, b) -> - print "what" + print "what" y = (a="hi", diff --git a/spec/inputs/lists.moon b/spec/inputs/lists.moon index c119185..e377d5e 100644 --- a/spec/inputs/lists.moon +++ b/spec/inputs/lists.moon @@ -3,14 +3,14 @@ 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] +_ = [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] +_ = [z for z in items for j in list when z > 4] require "util" @@ -32,7 +32,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 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 @@ -67,6 +67,6 @@ normal = (hello) -> test = x 1,2,3,4,5 print thing for thing in *test --> a = b for row in *rows +_ = -> a = b for row in *rows diff --git a/spec/inputs/literals.moon b/spec/inputs/literals.moon index c3a24a6..d4b0326 100644 --- a/spec/inputs/literals.moon +++ b/spec/inputs/literals.moon @@ -1,46 +1,46 @@ +_ = { + 121 + 121.2323 + 121.2323e-1 + 121.2323e13434 + 2323E34 + 0x12323 -121 -121.2323 -121.2323e-1 -121.2323e13434 -2323E34 -0x12323 + 0xfF2323 + 0xabcdef + 0xABCDEF -0xfF2323 -0xabcdef -0xABCDEF + .2323 + .2323e-1 + .2323e13434 -.2323 -.2323e-1 -.2323e13434 + 1LL + 1ULL + 9332LL + 9332 + 0x2aLL + 0x2aULL -1LL -1ULL -9332LL -9332 -0x2aLL -0x2aULL + [[ hello world ]] -[[ hello world ]] + [=[ hello world ]=] + [====[ hello world ]====] -[=[ hello world ]=] -[====[ hello world ]====] + "another world" -"another world" + 'what world' -'what world' + " + hello world + " -" -hello world -" - -'yeah -what is going on -here is something cool' - + 'yeah + what is going on + here is something cool' +} nil diff --git a/spec/inputs/local.moon b/spec/inputs/local.moon index fec78b1..f14f575 100644 --- a/spec/inputs/local.moon +++ b/spec/inputs/local.moon @@ -89,6 +89,6 @@ do do local * -- this generates a nil value in the body - for a in *{} do a + for a in *{} do _ = a g = 2323 -- test if anything leaked diff --git a/spec/inputs/loops.moon b/spec/inputs/loops.moon index a704e56..130570e 100644 --- a/spec/inputs/loops.moon +++ b/spec/inputs/loops.moon @@ -33,7 +33,7 @@ for x in y, z, k x = -> for x in y - y + _ = y hello = {1,2,3,4,5} @@ -43,7 +43,7 @@ x = for y in *hello x = -> for x in *hello - y + _ = y t = for i=10,20 do i * 2 @@ -52,11 +52,11 @@ y = for j = 3,30, 8 hmm += 1 j * hmm --> +_ = -> for k=10,40 - "okay" + _ = "okay" --> +_ = -> return for k=10,40 "okay" @@ -68,7 +68,7 @@ while 5 + 5 while also do i work too - "okay" + _ = "okay" i = 0 x = while i < 10 diff --git a/spec/inputs/return.moon b/spec/inputs/return.moon index 61d3dca..98c3104 100644 --- a/spec/inputs/return.moon +++ b/spec/inputs/return.moon @@ -1,7 +1,7 @@ -- testing `return` propagation --> x for x in *things --> [x for x in *things] +_ = -> _ = x for x in *things +_ = -> [x for x in *things] -- doesn't make sense on purpose @@ -14,7 +14,7 @@ do do return {x,y for x,y in *things} --> +_ = -> if a if a a @@ -49,7 +49,7 @@ do else b --> a\b +_ = -> a\b do a\b diff --git a/spec/inputs/string.moon b/spec/inputs/string.moon index 897056a..5d8f772 100644 --- a/spec/inputs/string.moon +++ b/spec/inputs/string.moon @@ -52,7 +52,7 @@ c = 'hello #{hello}' -- -"hello" +_ = "hello" "hello"\format 1 "hello"\format(1,2,3) "hello"\format(1,2,3) 1,2,3 diff --git a/spec/inputs/switch.moon b/spec/inputs/switch.moon index 3bc179b..a028f98 100644 --- a/spec/inputs/switch.moon +++ b/spec/inputs/switch.moon @@ -15,7 +15,7 @@ switch value when "cool" print "hello world" when "yeah" - [[FFFF]] + [[MMMM]] + _ = [[FFFF]] + [[MMMM]] when 2323 + 32434 print "okay" else @@ -33,9 +33,9 @@ out = switch value with something switch \value! when .okay - "world" + _ = "world" else - "yesh" + _ = "yesh" fix this call_func switch something @@ -46,7 +46,7 @@ call_func switch something switch hi when hello or world - greene + _ = greene -- @@ -54,7 +54,7 @@ switch hi when "one", "two" print "cool" when "dad" - no + _ = no switch hi when 3+1, hello!, (-> 4)! diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon index 854f629..351b22c 100644 --- a/spec/inputs/syntax.moon +++ b/spec/inputs/syntax.moon @@ -27,7 +27,7 @@ what(the)[3243] world, yeck heck hairy[hands][are](gross) okay okay[world] -(get[something] + 5)[years] +_ = (get[something] + 5)[years] i,x = 200, 300 @@ -37,27 +37,27 @@ 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 +_ = -> 1,2,34 return 5 + () -> 4 + 2 return 5 + (() -> 4) + 2 print 5 + () -> - 34 + _ = 34 good nads @@ -66,19 +66,19 @@ something 'else', "ya" something'else' something"else" -something[[hey]] * 2 -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 something "else", 2 something [[else]], 2 -here(we)"go"[12123] +_ = here(we)"go"[12123] -- this runs something = @@ -120,9 +120,9 @@ print "hello" for i=1,10 print "nutjob" -if hello then 343 +if hello then _ = 343 -print "what" if cool else whack +print "what" if cool else whack! arg = {...} @@ -139,7 +139,7 @@ y = #"hello" x = #{#{},#{1},#{1,2}} -hello, world +_ = hello, world something\hello(what) a,b something\hello what @@ -163,7 +163,7 @@ a["hello#{tostring ff}"] += 10 a[four].x += 10 x = 0 -(if ntype(v) == "fndef" then x += 1) for v in *values +_ = (if ntype(v) == "fndef" then x += 1) for v in *values hello = @@ -176,10 +176,10 @@ hello = div class: "cool" -5 + what wack +_ = 5 + what wack what whack + 5 -5 - what wack +_ = 5 - what wack what whack - 5 x = hello - world - something @@ -189,16 +189,16 @@ x = hello - world - something print something)! if something - 03589 + _ = 03589 -- okay what about this else - 3434 + _ = 3434 if something - yeah + _ = yeah elseif "ymmm" @@ -207,7 +207,7 @@ elseif "ymmm" else - okay + _ = okay -- test names containing keywords diff --git a/spec/inputs/tables.moon b/spec/inputs/tables.moon index 2bf66d7..10bccde 100644 --- a/spec/inputs/tables.moon +++ b/spec/inputs/tables.moon @@ -138,7 +138,7 @@ thing what: thing what: "great", no: "more" -okay: 123 -- a anon table +_ = okay: 123 -- a anon table -- diff --git a/spec/inputs/using.moon b/spec/inputs/using.moon index 55a16a7..e407983 100644 --- a/spec/inputs/using.moon +++ b/spec/inputs/using.moon @@ -2,18 +2,18 @@ hello = "hello" world = "world" -(using nil) -> +_ = (using nil) -> hello = 3223 -(a using nil) -> +_ = (a using nil) -> hello = 3223 a = 323 -(a,b,c using a,b,c) -> +_ = (a,b,c using a,b,c) -> a,b,c = 1,2,3 world = 12321 -(a,e,f using a,b,c, hello) -> +_ = (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 index 4a2ff1f..e505b1b 100644 --- a/spec/inputs/whitespace.moon +++ b/spec/inputs/whitespace.moon @@ -1,42 +1,42 @@ -{ +_ = { 1, 2 } -{ 1, 2 +_ = { 1, 2 } -{ 1, 2 } +_ = { 1, 2 } -{1,2} +_ = {1,2} -{ +_ = { 1,2 } -{ something 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 } +_ = { 1,2,3 } -{ c 1,2,3, +_ = { c 1,2,3, } @@ -58,7 +58,7 @@ hello 1,2,3, 9,9 -{ +_ = { hello 1,2, 3,4, 5, 6 diff --git a/spec/inputs/with.moon b/spec/inputs/with.moon index ae3c8c0..f543356 100644 --- a/spec/inputs/with.moon +++ b/spec/inputs/with.moon @@ -37,7 +37,7 @@ do do with foo - \prop"something".hello + _ = \prop"something".hello .prop\send(one) .prop\send one @@ -107,7 +107,7 @@ do print .c do - -> + _ = -> with hi return .a, .b -- cgit v1.2.3-55-g6feb