aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-01-10 16:30:34 +0800
committerLi Jin <dragon-fly@qq.com>2020-01-10 16:30:34 +0800
commit52a6536103f46c26a3ba9b149b0fe7b40d524d8c (patch)
tree67e4759f8e1ea922079d0e162d84ecba5e558261 /spec
parent975167856ed0b11c2ede03c6eb750ca4e4a6a7fc (diff)
downloadyuescript-52a6536103f46c26a3ba9b149b0fe7b40d524d8c.tar.gz
yuescript-52a6536103f46c26a3ba9b149b0fe7b40d524d8c.tar.bz2
yuescript-52a6536103f46c26a3ba9b149b0fe7b40d524d8c.zip
update.
Diffstat (limited to 'spec')
-rw-r--r--spec/inputs/assign.moon30
-rw-r--r--spec/inputs/bubbling.moon28
-rw-r--r--spec/inputs/class.moon213
-rw-r--r--spec/inputs/comprehension.moon52
-rw-r--r--spec/inputs/cond.moon190
-rw-r--r--spec/inputs/destructure.moon100
-rw-r--r--spec/inputs/do.moon27
-rw-r--r--spec/inputs/export.moon77
-rw-r--r--spec/inputs/funcs.moon158
-rw-r--r--spec/inputs/import.moon48
-rw-r--r--spec/inputs/lists.moon72
-rw-r--r--spec/inputs/literals.moon46
-rw-r--r--spec/inputs/local.moon94
-rw-r--r--spec/inputs/loops.moon133
-rw-r--r--spec/inputs/operators.moon72
-rw-r--r--spec/inputs/plus.moon7
-rw-r--r--spec/inputs/return.moon55
-rw-r--r--spec/inputs/string.moon66
-rw-r--r--spec/inputs/stub.moon16
-rw-r--r--spec/inputs/switch.moon64
-rw-r--r--spec/inputs/syntax.moon272
-rw-r--r--spec/inputs/tables.moon161
-rw-r--r--spec/inputs/unless_else.moon5
-rw-r--r--spec/inputs/using.moon21
-rw-r--r--spec/inputs/whitespace.moon102
-rw-r--r--spec/inputs/with.moon118
26 files changed, 2227 insertions, 0 deletions
diff --git a/spec/inputs/assign.moon b/spec/inputs/assign.moon
new file mode 100644
index 0000000..1e5e7a6
--- /dev/null
+++ b/spec/inputs/assign.moon
@@ -0,0 +1,30 @@
1
2->
3 joop = 2302
4
5 (hi) ->
6 d = 100
7 hi = 1021
8
9 a,b,c,d = 1,2,3,4
10
11 hello[232], (5+5)[121], hello, x[99] = 100, 200, 300
12
13 joop = 12
14
15joop = 2345
16
17a, b = if hello
18 "hello"
19else
20 "nothing", "yeah"
21
22
23a, b = if hello
24 if yeah then "one", "two" else "mmhh"
25else
26 print "the other"
27 "nothing", "yeah"
28
29
30
diff --git a/spec/inputs/bubbling.moon b/spec/inputs/bubbling.moon
new file mode 100644
index 0000000..d1004f9
--- /dev/null
+++ b/spec/inputs/bubbling.moon
@@ -0,0 +1,28 @@
1
2-- vararg bubbling
3f = (...) -> #{...}
4
5dont_bubble = ->
6 [x for x in ((...)-> print ...)("hello")]
7
8k = [x for x in ((...)-> print ...)("hello")]
9
10j = for i=1,10
11 (...) -> print ...
12
13-- bubble me
14
15m = (...) ->
16 [x for x in *{...} when f(...) > 4]
17
18x = for i in *{...} do i
19y = [x for x in *{...}]
20z = [x for x in hallo when f(...) > 4]
21
22
23a = for i=1,10 do ...
24
25b = for i=1,10
26 -> print ...
27
28
diff --git a/spec/inputs/class.moon b/spec/inputs/class.moon
new file mode 100644
index 0000000..9a98055
--- /dev/null
+++ b/spec/inputs/class.moon
@@ -0,0 +1,213 @@
1
2class Hello
3 new: (@test, @world) =>
4 print "creating object.."
5 hello: =>
6 print @test, @world
7 __tostring: => "hello world"
8
9x = Hello 1,2
10x\hello()
11
12print x
13
14class Simple
15 cool: => print "cool"
16
17class Yikes extends Simple
18 new: => print "created hello"
19
20x = Yikes()
21x\cool()
22
23
24class Hi
25 new: (arg) =>
26 print "init arg", arg
27
28 cool: (num) =>
29 print "num", num
30
31
32class Simple extends Hi
33 new: => super "man"
34 cool: => super 120302
35
36x = Simple()
37x\cool()
38
39print x.__class == Simple
40
41
42class Okay
43 -- what is going on
44 something: 20323
45 -- yeaha
46
47
48class Biggie extends Okay
49 something: =>
50 super 1,2,3,4
51 super.something another_self, 1,2,3,4
52 assert super == Okay
53
54
55class Yeah
56 okay: =>
57 super\something 1,2,3,4
58
59
60class What
61 something: => print "val:", @val
62
63class Hello extends What
64 val: 2323
65 something: => super\something
66
67with Hello!
68 x = \something!
69 print x
70 x!
71
72class CoolSuper
73 hi: =>
74 super(1,2,3,4) 1,2,3,4
75 super.something 1,2,3,4
76 super.something(1,2,3,4).world
77 super\yeah"world".okay hi, hi, hi
78 something.super
79 super.super.super.super
80 super\hello
81 nil
82
83
84-- selfing
85x = @hello
86x = @@hello
87
88@hello "world"
89@@hello "world"
90
91@@one @@two(4,5) @three, @four
92
93xx = (@hello, @@world, cool) ->
94
95
96-- class properties
97class ClassMan
98 @yeah: 343
99 blue: =>
100 @hello: 3434, @world: 23423
101 green: =>
102 @red: =>
103
104
105x = @
106y = @@
107
108@ something
109
110@@ something
111
112@ = @ + @ / @
113
114@ = 343
115@.hello 2,3,4
116
117hello[@].world
118
119
120class Whacko
121 @hello
122 if something
123 print "hello world"
124
125 hello = "world"
126 @another = "day"
127
128 print "yeah" if something -- this is briken
129
130
131print "hello"
132
133yyy = ->
134 class Cool
135 nil
136
137
138--
139
140class a.b.c.D
141 nil
142
143
144class a.b["hello"]
145 nil
146
147class (-> require "moon")!.Something extends Hello.World
148 nil
149
150--
151
152a = class
153b = class Something
154c = class Something extends Hello
155d = class extends World
156
157print (class WhatsUp).__name
158
159--
160
161export ^
162class Something
163 nil
164
165
166--
167
168-- hoisting
169class Something
170 val = 23
171 {:insert} = table
172 new: => print insert, val -- prints nil 23
173
174--
175
176class X
177 new: hi
178
179
180--
181
182class Cool extends Thing
183 dang: =>
184 {
185 hello: -> super!
186 world: -> super.one
187 }
188
189--
190
191class Whack extends Thing
192 dang: do_something =>
193 super!
194
195---
196
197class Wowha extends Thing
198 @butt: ->
199 super!
200 super.hello
201 super\hello!
202 super\hello
203
204
205 @zone: cool {
206 ->
207 super!
208 super.hello
209 super\hello!
210 super\hello
211 }
212
213nil
diff --git a/spec/inputs/comprehension.moon b/spec/inputs/comprehension.moon
new file mode 100644
index 0000000..1609d79
--- /dev/null
+++ b/spec/inputs/comprehension.moon
@@ -0,0 +1,52 @@
1
2-- see lists.moon for list comprehension tests
3
4items = {1,2,3,4,5,6}
5out = {k,k*2 for k in items}
6
7
8x = hello: "world", okay: 2323
9
10copy = {k,v for k,v in pairs x when k != "okay"}
11
12--
13
14{ unpack(x) for x in yes }
15{ unpack(x) for x in *yes }
16
17{ xxxx for x in yes }
18{ unpack [a*i for i, a in ipairs x] for x in *{{1,2}, {3,4}} }
19
20
21--
22
23n1 = [i for i=1,10]
24n2 = [i for i=1,10 when i % 2 == 1]
25
26aa = [{x,y} for x=1,10 for y=5,14]
27bb = [y for thing in y for i=1,10]
28cc = [y for i=1,10 for thing in y]
29dd = [y for i=1,10 when cool for thing in y when x > 3 when c + 3]
30
31{"hello", "world" for i=1,10}
32
33--
34
35j = [a for {a,b,c} in things]
36k = [a for {a,b,c} in *things]
37i = [hello for {:hello, :world} in *things]
38
39hj = {a,c for {a,b,c} in things}
40hk = {a,c for {a,b,c} in *things}
41hi = {hello,world for {:hello, :world} in *things}
42
43ok(a,b,c) for {a,b,c} in things
44
45--
46
47[item for item in *items[1 + 2,3+4]]
48[item for item in *items[hello! * 4, 2 - thing[4]]]
49
50
51
52nil
diff --git a/spec/inputs/cond.moon b/spec/inputs/cond.moon
new file mode 100644
index 0000000..18e42b9
--- /dev/null
+++ b/spec/inputs/cond.moon
@@ -0,0 +1,190 @@
1
2you_cool = false
3
4if cool
5 if you_cool
6 one
7 else if eatdic
8 yeah
9 else
10 two
11 three
12else
13 no
14
15if cool then no
16if cool then no else yes
17
18if cool then wow cool else
19 noso cool
20
21if working
22 if cool then if cool then okay else what else nah
23
24
25if yeah then no day elseif cool me then okay ya else u way
26if yeah then no dad else if cool you then okay bah else p way
27
28
29if (->)() then what ever
30
31if nil then flip me else
32 it be,rad
33
34
35if things great then no way elseif okay sure
36 what here
37
38
39if things then no chance
40elseif okay
41 what now
42
43
44if things
45 yes man
46elseif okay person then hi there else hmm sure
47
48if lets go
49 print "greetings"
50elseif "just us"
51 print "will smith" else show 5555555
52
53--
54
55if something = 10
56 print something
57else
58 print "else"
59
60hello = if something = 10
61 print something
62else
63 print "else"
64
65
66hello = 5 + if something = 10
67 print something
68
69---
70
71z = false
72
73if false
74 one
75elseif x = true
76 two
77elseif z = true
78 three
79else
80 four
81
82
83out = if false
84 one
85elseif x = true
86 two
87elseif z = true
88 three
89else
90 four
91
92kzy = ->
93 if something = true
94 1
95 elseif another = false
96 2
97
98---
99
100unless true
101 print "cool!"
102
103unless true and false
104 print "cool!"
105
106unless false then print "cool!"
107unless false then print "cool!" else print "no way!"
108
109unless nil
110 print "hello"
111else
112 print "world"
113
114--
115
116x = unless true
117 print "cool!"
118
119x = unless true and false
120 print "cool!"
121
122y = unless false then print "cool!"
123y = unless false then print "cool!" else print "no way!"
124
125z = unless nil
126 print "hello"
127else
128 print "world"
129
130print unless true
131 print "cool!"
132
133print unless true and false
134 print "cool!"
135
136print unless false then print "cool!"
137print unless false then print "cool!" else print "no way!"
138
139print unless nil
140 print "hello"
141else
142 print "world"
143
144--
145
146print "hello" unless value
147
148dddd = {1,2,3} unless value
149
150
151--
152
153do
154 j = 100
155 unless j = hi!
156 error "not j!"
157
158----------------
159
160a = 12
161a,c,b = "cool" if something
162
163
164
165---
166
167j = if 1
168 if 2
169 3
170else 6
171
172
173m = if 1
174
175
176
177 if 2
178
179
180 3
181
182
183else 6
184
185
186
187nil
188
189
190
diff --git a/spec/inputs/destructure.moon b/spec/inputs/destructure.moon
new file mode 100644
index 0000000..beb79d6
--- /dev/null
+++ b/spec/inputs/destructure.moon
@@ -0,0 +1,100 @@
1
2do
3 {a, b} = hello
4
5 {{a}, b, {c}} = hello
6
7 { :hello, :world } = value
8
9do
10 { yes: no, thing } = world
11
12 {:a,:b,:c,:d} = yeah
13
14 {a} = one, two
15 {b}, c = one
16 {d}, e = one, two
17
18 x, {y} = one, two
19
20 xx, yy = 1, 2
21 {yy, xx} = {xx, yy}
22
23 {a, :b, c, :d, e, :f, g} = tbl
24
25---
26
27do
28 futurists =
29 sculptor: "Umberto Boccioni"
30 painter: "Vladimir Burliuk"
31 poet:
32 name: "F.T. Marinetti"
33 address: {
34 "Via Roma 42R"
35 "Bellagio, Italy 22021"
36 }
37
38 {poet: {:name, address: {street, city}}} = futurists
39
40--
41
42do
43 { @world } = x
44 { a.b, c.y, func!.z } = x
45
46 { world: @world } = x
47
48--
49
50do
51 thing = {{1,2}, {3,4}}
52
53 for {x,y} in *thing
54 print x,y
55
56
57--
58
59do
60 with {a,b} = thing
61 print a, b
62
63
64--
65
66do
67 thing = nil
68 if {a} = thing
69 print a
70 else
71 print "nothing"
72
73 thang = {1,2}
74 if {a,b} = thang
75 print a,b
76
77 if {a,b} = thing
78 print a,b
79 elseif {c,d} = thang
80 print c,d
81 else
82 print "NO"
83
84--
85
86do
87 z = "yeah"
88 {a,b,c} = z
89
90do
91 {a,b,c} = z
92
93(z) ->
94 {a,b,c} = z
95
96do
97 z = "oo"
98 (k) ->
99 {a,b,c} = z
100
diff --git a/spec/inputs/do.moon b/spec/inputs/do.moon
new file mode 100644
index 0000000..334e68f
--- /dev/null
+++ b/spec/inputs/do.moon
@@ -0,0 +1,27 @@
1
2do
3 print "hello"
4 print "world"
5
6x = do
7 print "hello"
8 print "world"
9
10y = do
11 things = "shhh"
12 -> "hello: " .. things
13
14-> if something then do "yeah"
15
16t = {
17 y: do
18 number = 100
19 (x) -> x + number
20}
21
22(y=(do
23 x = 10 + 2
24 x), k=do
25 "nothing") -> do
26 "uhhh"
27
diff --git a/spec/inputs/export.moon b/spec/inputs/export.moon
new file mode 100644
index 0000000..0a56379
--- /dev/null
+++ b/spec/inputs/export.moon
@@ -0,0 +1,77 @@
1
2do
3 export a,b,c = 223, 343
4 export cool = "dad"
5
6do
7 export class Something
8 umm: "cool"
9
10do
11 export a,b,c
12 a,b,c,d = "hello"
13
14
15do
16 What = if this
17 232
18 else
19 4343
20
21 export ^
22
23 another = 3434
24 Another = 7890
25
26 if inner then Yeah = "10000"
27
28 What = if this
29 232
30 else
31 4343
32
33
34do
35 export *
36
37 What = if this
38 232
39 else
40 4343
41
42 x,y,z = 1,2,3
43
44 y = ->
45 hallo = 3434
46
47 with tmp
48 j = 2000
49
50
51do
52 export *
53 x = 3434
54 if y then
55 x = 10
56
57do
58 export *
59 if y then
60 x = 10
61 x = 3434
62
63do
64 do
65 export *
66
67 k = 1212
68
69 do
70 h = 100
71
72 y = ->
73 h = 100
74 k = 100
75
76 h = 100
77
diff --git a/spec/inputs/funcs.moon b/spec/inputs/funcs.moon
new file mode 100644
index 0000000..08a29b6
--- /dev/null
+++ b/spec/inputs/funcs.moon
@@ -0,0 +1,158 @@
1
2
3x = -> print what
4
5->
6
7-> -> ->
8
9go to the barn
10
11open -> the -> door
12
13open ->
14 the door
15 hello = ->
16 my func
17
18h = -> hi
19
20eat ->, world
21
22
23(->)()
24
25x = (...) ->
26
27hello!
28hello.world!
29
30hello!.something
31what!["ofefe"]
32
33what! the! heck!
34
35(a,b,c,d,e) ->
36
37(a,a,a,a,a) ->
38 print a
39
40(x=23023) ->
41
42(x=(y=()->) ->) ->
43
44(x = if something then yeah else no) ->
45
46something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") ->
47 print hello
48
49(x, y) =>
50(@x, @y) =>
51(x=1) =>
52(@x=1,y,@z="hello world") =>
53
54
55x -> return
56y -> return 1
57z -> return 1, "hello", "world"
58k -> if yes then return else return
59
60-> real_name if something
61
62--
63
64d(
65 ->
66 print "hello world"
67 10
68)
69
70
71
72d(
73 1,2,3
74 4
75 5
76 6
77
78 if something
79 print "okay"
80 10
81
82 10,20
83)
84
85
86f(
87
88 )(
89
90 )(
91 what
92 )(->
93 print "srue"
94 123)
95
96--
97
98x = (a,
99 b) ->
100 print "what"
101
102
103y = (a="hi",
104 b=23) ->
105 print "what"
106
107z = (
108 a="hi",
109 b=23) ->
110 print "what"
111
112
113j = (f,g,m,
114 a="hi",
115 b=23
116) ->
117 print "what"
118
119
120y = (a="hi",
121 b=23,
122 ...) ->
123 print "what"
124
125
126y = (a="hi",
127 b=23,
128 ...
129) ->
130 print "what"
131
132--
133
134args = (a
135 b) ->
136 print "what"
137
138
139args = (a="hi"
140 b=23) ->
141 print "what"
142
143args = (
144 a="hi"
145 b=23) ->
146 print "what"
147
148
149args = (f,g,m
150 a="hi"
151 b=23
152) ->
153 print "what"
154
155
156
157
158nil
diff --git a/spec/inputs/import.moon b/spec/inputs/import.moon
new file mode 100644
index 0000000..d86d724
--- /dev/null
+++ b/spec/inputs/import.moon
@@ -0,0 +1,48 @@
1
2
3import hello from yeah
4import hello, world from table["cool"]
5
6import a, \b, c from items
7
8
9import master, \ghost from find "mytable"
10
11
12a, yumm = 3434, "hello"
13
14
15_table_0 = 232
16
17import something from a table
18
19
20if indent
21 import okay, \well from tables[100]
22
23do
24 import a, b, c from z
25
26do
27 import a,
28 b, c from z
29
30do
31 import a
32 b
33 c from z
34
35do
36 import
37 a
38 b
39 c from z
40
41
42do
43 import
44 a
45 b
46 c
47 from z
48
diff --git a/spec/inputs/lists.moon b/spec/inputs/lists.moon
new file mode 100644
index 0000000..c119185
--- /dev/null
+++ b/spec/inputs/lists.moon
@@ -0,0 +1,72 @@
1
2hi = [x*2 for _, x in ipairs{1,2,3,4}]
3
4items = {1,2,3,4,5,6}
5
6[z for z in ipairs items when z > 4]
7
8rad = [{a} for a in ipairs {
9 1,2,3,4,5,6,
10} when good_number a]
11
12
13[z for z in items for j in list when z > 4]
14
15require "util"
16
17dump = (x) -> print util.dump x
18
19range = (count) ->
20 i = 0
21 return coroutine.wrap ->
22 while i < count
23 coroutine.yield i
24 i = i + 1
25
26dump [x for x in range 10]
27dump [{x, y} for x in range 5 when x > 2 for y in range 5]
28
29things = [x + y for x in range 10 when x > 5 for y in range 10 when y > 7]
30
31print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2
32
33print "hello", x for x in items
34
35[x for x in x]
36x = [x for x in x]
37
38print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2
39
40double = [x*2 for x in *items]
41
42print x for x in *double
43
44cut = [x for x in *items when x > 3]
45
46hello = [x + y for x in *items for y in *items]
47
48print z for z in *hello
49
50
51-- slice
52x = {1, 2, 3, 4, 5, 6, 7}
53print y for y in *x[2,-5,2]
54print y for y in *x[,3]
55print y for y in *x[2,]
56print y for y in *x[,,2]
57print y for y in *x[2,,2]
58
59a, b, c = 1, 5, 2
60print y for y in *x[a,b,c]
61
62
63normal = (hello) ->
64 [x for x in yeah]
65
66
67test = x 1,2,3,4,5
68print thing for thing in *test
69
70-> a = b for row in *rows
71
72
diff --git a/spec/inputs/literals.moon b/spec/inputs/literals.moon
new file mode 100644
index 0000000..c3a24a6
--- /dev/null
+++ b/spec/inputs/literals.moon
@@ -0,0 +1,46 @@
1
2
3121
4121.2323
5121.2323e-1
6121.2323e13434
72323E34
80x12323
9
100xfF2323
110xabcdef
120xABCDEF
13
14.2323
15.2323e-1
16.2323e13434
17
18
191LL
201ULL
219332LL
229332
230x2aLL
240x2aULL
25
26[[ hello world ]]
27
28[=[ hello world ]=]
29[====[ hello world ]====]
30
31"another world"
32
33'what world'
34
35
36"
37hello world
38"
39
40'yeah
41what is going on
42here is something cool'
43
44
45nil
46
diff --git a/spec/inputs/local.moon b/spec/inputs/local.moon
new file mode 100644
index 0000000..fec78b1
--- /dev/null
+++ b/spec/inputs/local.moon
@@ -0,0 +1,94 @@
1
2do
3 local a
4 local a,b,c
5
6 b,g = 23232
7
8
9do
10 x = 1212
11 something = ->
12 local x
13 x = 1212
14
15do
16 local *
17 y = 2323
18 z = 2323
19
20do
21 local *
22 print "Nothing Here!"
23
24do
25 local ^
26 x = 3434
27 y = 3434
28 X = 3434
29 Y = "yeah"
30
31do
32 local ^
33 x,y = "a", "b"
34
35do
36 local *
37 x,y = "a", "b"
38
39
40do
41 local *
42 if something
43 x = 2323
44
45do
46 local *
47 do
48 x = "one"
49
50 x = 100
51
52 do
53 x = "two"
54
55do
56 local *
57 k = if what
58 10
59 x = 100
60
61 {:a,:b, :c} = y
62
63
64do
65 local *
66
67 a = 100
68 print "hi"
69 b = 200
70
71 local *
72 c = 100
73 print "hi"
74 d = 200
75 d = 2323
76
77
78do
79 local ^
80 lowercase = 5
81 Uppercase = 3
82
83 class One
84 Five = 6
85
86 class Two
87 class No
88
89do
90 local *
91 -- this generates a nil value in the body
92 for a in *{} do a
93
94g = 2323 -- test if anything leaked
diff --git a/spec/inputs/loops.moon b/spec/inputs/loops.moon
new file mode 100644
index 0000000..a704e56
--- /dev/null
+++ b/spec/inputs/loops.moon
@@ -0,0 +1,133 @@
1
2for x=1,10
3 print "yeah"
4
5for x=1,#something
6 print "yeah"
7
8for y=100,60,-3
9 print "count down", y
10
11for a=1,10 do print "okay"
12
13for a=1,10
14 for b = 2,43
15 print a,b
16
17for i in iter
18 for j in yeah
19 x = 343 + i + j
20 print i, j
21
22for x in *something
23 print x
24
25for k,v in pairs hello do print k,v
26
27for x in y, z
28 print x
29
30for x in y, z, k
31 print x
32
33
34x = ->
35 for x in y
36 y
37
38hello = {1,2,3,4,5}
39
40x = for y in *hello
41 if y % 2 == 0
42 y
43
44x = ->
45 for x in *hello
46 y
47
48t = for i=10,20 do i * 2
49
50hmm = 0
51y = for j = 3,30, 8
52 hmm += 1
53 j * hmm
54
55->
56 for k=10,40
57 "okay"
58
59->
60 return for k=10,40
61 "okay"
62
63while true do print "name"
64
65while 5 + 5
66 print "okay world"
67 working man
68
69while also do
70 i work too
71 "okay"
72
73i = 0
74x = while i < 10
75 i += 1
76
77-- values that can'e be coerced
78
79x = for thing in *3
80 y = "hello"
81
82x = for x=1,2
83 y = "hello"
84
85
86-- continue
87
88while true
89 continue if false
90 print "yes"
91 break if true
92 print "no"
93
94
95for x=1,10
96 continue if x > 3 and x < 7
97 print x
98
99
100list = for x=1,10
101 continue if x > 3 and x < 7
102 x
103
104
105for a in *{1,2,3,4,5,6}
106 continue if a == 1
107 continue if a == 3
108 print a
109
110
111
112for x=1,10
113 continue if x % 2 == 0
114 for y = 2,12
115 continue if y % 3 == 0
116
117
118while true
119 continue if false
120 break
121
122while true
123 continue if false
124 return 22
125
126--
127
128do
129 xxx = {1,2,3,4}
130 for thing in *xxx
131 print thing
132
133
diff --git a/spec/inputs/operators.moon b/spec/inputs/operators.moon
new file mode 100644
index 0000000..142ef62
--- /dev/null
+++ b/spec/inputs/operators.moon
@@ -0,0 +1,72 @@
1
2-- binary ops
3x = 1 + 3
4
5y = 1 +
6 3
7
8z = 1 +
9 3 +
10 4
11
12--
13
14k = b and c and
15 g
16
17
18h = thing and
19 ->
20 print "hello world"
21
22-- TODO: should fail, indent still set to previous line so it thinks body is
23-- indented
24i = thing or
25 ->
26 print "hello world"
27
28p = thing and
29 ->
30print "hello world"
31
32s = thing or
33 -> and 234
34
35
36--
37u = {
38 color: 1 and 2 and
39 3
40 4
41 4
42}
43
44v = {
45 color: 1 and
46 ->
47 "yeah"
48 "great"
49 oksy: 3 ^
502
51}
52
53-- parens
54
55nno = (
56 yeah + 2 )
57
58nn = (
59 yeah + 2
60)
61
62n = hello(
63 b
64) ->
65
66hello a,
67 (
68 yeah +
69 2
70 ) -
71 okay
72
diff --git a/spec/inputs/plus.moon b/spec/inputs/plus.moon
new file mode 100644
index 0000000..fdca8be
--- /dev/null
+++ b/spec/inputs/plus.moon
@@ -0,0 +1,7 @@
1
2func a\do!\end("OK")\if "abc",123
3
4res = b.function\do!\while("OK")\if "def",998
5
6c.repeat.if\then("xyz")\else res
7
diff --git a/spec/inputs/return.moon b/spec/inputs/return.moon
new file mode 100644
index 0000000..61d3dca
--- /dev/null
+++ b/spec/inputs/return.moon
@@ -0,0 +1,55 @@
1-- testing `return` propagation
2
3-> x for x in *things
4-> [x for x in *things]
5
6
7-- doesn't make sense on purpose
8do
9 return x for x in *things
10
11do
12 return [x for x in *things]
13
14do
15 return {x,y for x,y in *things}
16
17->
18 if a
19 if a
20 a
21 else
22 b
23 elseif b
24 if a
25 a
26 else
27 b
28 else
29 if a
30 a
31 else
32 b
33
34
35do
36 return if a
37 if a
38 a
39 else
40 b
41 elseif b
42 if a
43 a
44 else
45 b
46 else
47 if a
48 a
49 else
50 b
51
52-> a\b
53do a\b
54
55
diff --git a/spec/inputs/string.moon b/spec/inputs/string.moon
new file mode 100644
index 0000000..897056a
--- /dev/null
+++ b/spec/inputs/string.moon
@@ -0,0 +1,66 @@
1
2hi = "hello"
3hello = "what the heckyes"
4print hi
5
6umm = 'umm'
7
8here, another = "yeah", 'world'
9
10aye = "YU'M"
11you '"hmmm" I said'
12
13print aye, you
14
15another = [[ hello world ]]
16
17
18hi_there = [[
19 hi there
20]]
21
22well = [==[ "helo" ]==]
23
24hola = [===[
25 eat noots]===]
26
27mm = [[well trhere]]
28
29oo = ""
30
31x = "\\"
32x = "a\\b"
33x = "\\\n"
34x = "\""
35
36--
37
38a = "hello #{hello} hello"
39b = "#{hello} hello"
40c = "hello #{5+1}"
41d = "#{hello world}"
42e = "#{1} #{2} #{3}"
43
44f = [[hello #{world} world]]
45
46--
47
48a = 'hello #{hello} hello'
49b = '#{hello} hello'
50c = 'hello #{hello}'
51
52
53--
54
55"hello"
56"hello"\format 1
57"hello"\format(1,2,3)
58"hello"\format(1,2,3) 1,2,3
59
60"hello"\world!
61"hello"\format!.hello 1,2,3
62"hello"\format 1,2,3
63
64something"hello"\world!
65something "hello"\world!
66
diff --git a/spec/inputs/stub.moon b/spec/inputs/stub.moon
new file mode 100644
index 0000000..f8f6c3f
--- /dev/null
+++ b/spec/inputs/stub.moon
@@ -0,0 +1,16 @@
1
2
3x = {
4 val: 100
5 hello: =>
6 print @val
7}
8
9fn = x\val
10print fn!
11print x\val!
12
13
14-- ... should be bubbled up anon functions
15x = hello(...)\world
16
diff --git a/spec/inputs/switch.moon b/spec/inputs/switch.moon
new file mode 100644
index 0000000..3bc179b
--- /dev/null
+++ b/spec/inputs/switch.moon
@@ -0,0 +1,64 @@
1
2switch value
3 when "cool"
4 print "hello world"
5
6
7switch value
8 when "cool"
9 print "hello world"
10 else
11 print "okay rad"
12
13
14switch value
15 when "cool"
16 print "hello world"
17 when "yeah"
18 [[FFFF]] + [[MMMM]]
19 when 2323 + 32434
20 print "okay"
21 else
22 print "okay rad"
23
24out = switch value
25 when "cool" then print "hello world"
26 else print "okay rad"
27
28out = switch value
29 when "cool" then xxxx
30 when "umm" then 34340
31 else error "this failed big time"
32
33with something
34 switch \value!
35 when .okay
36 "world"
37 else
38 "yesh"
39
40fix this
41call_func switch something
42 when 1 then "yes"
43 else "no"
44
45--
46
47switch hi
48 when hello or world
49 greene
50
51--
52
53switch hi
54 when "one", "two"
55 print "cool"
56 when "dad"
57 no
58
59switch hi
60 when 3+1, hello!, (-> 4)!
61 yello
62 else
63 print "cool"
64
diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon
new file mode 100644
index 0000000..854f629
--- /dev/null
+++ b/spec/inputs/syntax.moon
@@ -0,0 +1,272 @@
1#!/this/is/ignored
2
3a = 1 + 2* 3 / 6
4
5a, bunch, go, here = another, world
6
7func arg1, arg2, another, arg3
8
9here, we = () ->, yeah
10the, different = () -> approach; yeah
11
12dad()
13dad(lord)
14hello(one,two)()
15(5 + 5)(world)
16
17fun(a)(b)
18
19fun(a) b
20
21fun(a) b, bad hello
22
23hello world what are you doing here
24
25
26what(the)[3243] world, yeck heck
27
28hairy[hands][are](gross) okay okay[world]
29
30(get[something] + 5)[years]
31
32i,x = 200, 300
33
34yeah = (1 + 5) * 3
35yeah = ((1+5)*3)/2
36yeah = ((1+5)*3)/2 + i % 100
37
38whoa = (1+2) * (3+4) * (4+5)
39
40->
41 if something
42 return 1,2,4
43
44 print "hello"
45
46->
47 if hello
48 "heloo", "world"
49 else
50 no, way
51
52
53-> 1,2,34
54
55return 5 + () -> 4 + 2
56
57return 5 + (() -> 4) + 2
58
59print 5 + () ->
60 34
61 good nads
62
63
64something 'else', "ya"
65
66something'else'
67something"else"
68
69something[[hey]] * 2
70something[======[hey]======] * 2
71
72
73something'else', 2
74something"else", 2
75something[[else]], 2
76
77something 'else', 2
78something "else", 2
79something [[else]], 2
80
81here(we)"go"[12123]
82
83-- this runs
84something =
85 test: 12323
86 what: -> print "hello world"
87
88print something.test
89
90frick = hello: "world"
91
92argon =
93 num: 100
94 world: (self) ->
95 print self.num
96 return {
97 something: -> print "hi from something"
98 }
99 somethin: (self, str) ->
100 print "string is", str
101 return world: (a,b) -> print "sum", a + b
102
103something.what()
104argon\world().something()
105
106argon\somethin"200".world(1,2)
107
108x = -434
109
110x = -hello world one two
111
112hi = -"herfef"
113
114x = -[x for x in x]
115
116print "hello" if cool
117print "hello" unless cool
118print "hello" unless 1212 and 3434 -- hello
119print "hello" for i=1,10
120
121print "nutjob"
122
123if hello then 343
124
125print "what" if cool else whack
126
127arg = {...}
128
129x = (...) ->
130 dump {...}
131
132
133x = not true
134
135y = not(5+5)
136
137
138y = #"hello"
139
140x = #{#{},#{1},#{1,2}}
141
142hello, world
143
144something\hello(what) a,b
145something\hello what
146something.hello\world a,b
147something.hello\world(1,2,3) a,b
148
149
150x = 1232
151x += 10 + 3
152j -= "hello"
153y *= 2
154y /= 100
155m %= 2
156hello ..= "world"
157
158@@something += 10
159@something += 10
160
161a["hello"] += 10
162a["hello#{tostring ff}"] += 10
163a[four].x += 10
164
165x = 0
166(if ntype(v) == "fndef" then x += 1) for v in *values
167
168
169hello =
170 something: world
171 if: "hello"
172 else: 3434
173 function: "okay"
174 good: 230203
175
176
177div class: "cool"
178
1795 + what wack
180what whack + 5
181
1825 - what wack
183what whack - 5
184
185x = hello - world - something
186
187((something = with what
188 \cool 100) ->
189 print something)!
190
191if something
192 03589
193
194-- okay what about this
195
196else
197 3434
198
199
200if something
201 yeah
202
203
204elseif "ymmm"
205
206 print "cool"
207
208else
209
210 okay
211
212
213-- test names containing keywords
214x = notsomething
215y = ifsomething
216z = x and b
217z = x andb
218
219
220-- undelimited tables
221
222while 10 > something
223 something: "world"
224 print "yeah"
225
226x =
227 okay: sure
228
229yeah
230 okay: man
231 sure: sir
232
233hello "no comma"
234 yeah: dada
235 another: world
236
237hello "comma",
238 something: hello_world
239 frick: you
240
241-- creates two tables
242another hello, one,
243 two, three, four, yeah: man
244 okay: yeah
245
246--
247a += 3 - 5
248a *= 3 + 5
249a *= 3
250a >>= 3
251a <<= 3
252a /= func "cool"
253
254---
255
256x.then = "hello"
257x.while.true = "hello"
258
259--
260
261x or= "hello"
262x and= "hello"
263
264--
265
266z = a-b
267z = a -b
268z = a - b
269z = a- b
270
271
272-- cooool
diff --git a/spec/inputs/tables.moon b/spec/inputs/tables.moon
new file mode 100644
index 0000000..2bf66d7
--- /dev/null
+++ b/spec/inputs/tables.moon
@@ -0,0 +1,161 @@
1
2backpack =
3 something:
4 yeah: 200
5 they: ->
6 print "hello"
7 yor_feet"small"
8 pretty: hair
9 gold: hmm
10 yow: 1000
11
12 eat: goo
13 yeah: dudd
14
15
16start =
17 something: "cold"
18
19bathe =
20 on: "fire"
21
22another =
23 [4]: 232
24 ["good food"]: "is the best"
25
26fwip =
27 something: hello"what", number: 2323,
28 what: yo "momma", "yeah",
29 fruit: basket
30 nuts: day
31
32
33frick = hello: "world"
34
35frack, best = hello: "world", rice: 3434, "what"
36
37ya = { 1,2,3, key: 100, 343, "hello", umm: 232 }
38
39
40x = { 1,2,
41 4343, 343 ,343 }
42
43
44g, p = {
45 1,2, nowy: "yes", 3,4,
46 hey: 232, another: "day"
47}, 234
48
49annother = {
50 1,2,3
51 3,4,5
52 6,7,8
53}
54
55yeah = {
56 [232]: 3434, "helo"
57 ice: "cake"
58}
59
60-- confusing stuff...
61whatabout = {
62 hello world, another
63 what, about, now
64
65 hello"world", yeah
66 hello "world", yeah
67}
68
69x =
70 -- yeah
71 something: => "hello"
72 cool: -- umm
73 --so ething
74 bed: {
75 2323,2323
76 }
77 red: 2343 -- here
78 -- what
79 name: (node) => @value node -- here
80 -- comment me
81-- okay
82
83
84x = { :something, something: something }
85
86y = {
87 :hi, :there, :how, :you
88 :thing
89}
90
91call_me "hello", :x, :y, :z
92
93t = {
94 a: 'a'
95 [b]: 'b'
96}
97
98xam = {
99 hello: 1234
100 "hello": 12354
101 ["hello"]: 12354
102}
103
104
105kam = {
106 hello: 12
107 goodcheese:
108 "mmm"
109
110 yeah:
111 12 + 232
112
113 lets:
114 keepit going: true,
115 okay: "yeah"
116
117 more:
118 {
119 1, [x for x=1,10]
120 }
121
122 [{"one", "two"}]:
123 one_thing =>
124}
125
126-- TODO: both of these have undesirable output
127keepit going: true,
128 okay: "yeah",
129 workd: "okay"
130
131thing what:
132 "great", no:
133 "more"
134 okay: 123
135
136
137--
138thing what:
139 "great", no:
140 "more"
141okay: 123 -- a anon table
142
143
144--
145
146k = { "hello": "world" }
147k = { 'hello': 'world' }
148k = { "hello": 'world', "hat": "zat" }
149
150please "hello": "world"
151k = "hello": "world", "one": "zone"
152
153f = "one", "two": three, "four"
154f = "two": three, "four"
155f = { "one", "two": three, "four" }
156
157
158j = "one", "two": three, "four": five, 6, 7
159
160
161nil
diff --git a/spec/inputs/unless_else.moon b/spec/inputs/unless_else.moon
new file mode 100644
index 0000000..fe96c0b
--- /dev/null
+++ b/spec/inputs/unless_else.moon
@@ -0,0 +1,5 @@
1if a
2 unless b
3 print "hi"
4 elseif c
5 print "not hi"
diff --git a/spec/inputs/using.moon b/spec/inputs/using.moon
new file mode 100644
index 0000000..55a16a7
--- /dev/null
+++ b/spec/inputs/using.moon
@@ -0,0 +1,21 @@
1
2hello = "hello"
3world = "world"
4
5(using nil) ->
6 hello = 3223
7
8(a using nil) ->
9 hello = 3223
10 a = 323
11
12(a,b,c using a,b,c) ->
13 a,b,c = 1,2,3
14 world = 12321
15
16(a,e,f using a,b,c, hello) ->
17 a,b,c = 1,2,3
18 hello = 12321
19 world = "yeah"
20
21
diff --git a/spec/inputs/whitespace.moon b/spec/inputs/whitespace.moon
new file mode 100644
index 0000000..4a2ff1f
--- /dev/null
+++ b/spec/inputs/whitespace.moon
@@ -0,0 +1,102 @@
1
2{
3 1, 2
4}
5
6{ 1, 2
7}
8
9{ 1, 2 }
10
11{1,2}
12
13{
141,2
15
16}
17
18{ something 1,2,
19 4,5,6,
20 3,4,5
21}
22
23{
24 a 1,2,3,
25 4,5,6
26 1,2,3
27}
28
29
30{
31 b 1,2,3,
32 4,5,6
33 1,2,3,
34 1,2,3
35}
36
37{ 1,2,3 }
38
39{ c 1,2,3,
40}
41
42
43hello 1,2,3,4,
44 1,2,3,4,4,5
45
46x 1,
47 2, 3,
48 4, 5, 6
49
50
51hello 1,2,3,
52 world 4,5,6,
53 5,6,7,8
54
55hello 1,2,3,
56 world 4,5,6,
57 5,6,7,8,
58 9,9
59
60
61{
62 hello 1,2,
63 3,4,
64 5, 6
65}
66
67x = {
68 hello 1,2,3,4,
69 5,6,7
70 1,2,3,4
71}
72
73if hello 1,2,3,
74 world,
75 world
76 print "hello"
77
78if hello 1,2,3,
79 world,
80 world
81 print "hello"
82
83
84--
85
86a(
87 one, two, three
88)
89
90b(
91 one,
92 two,
93 three
94)
95
96
97c(one, two,
98 three, four)
99
100--
101
102nil
diff --git a/spec/inputs/with.moon b/spec/inputs/with.moon
new file mode 100644
index 0000000..ae3c8c0
--- /dev/null
+++ b/spec/inputs/with.moon
@@ -0,0 +1,118 @@
1
2do
3 a = ->
4 with something
5 print .hello
6 print hi
7 print "world"
8
9do
10 with leaf
11 .world!
12 .world 1,2,3
13
14 g = .what.is.this
15
16 .hi 1,2,3
17
18 \hi(1,2).world 2323
19
20 \hi "yeah", "man"
21 .world = 200
22
23do
24 zyzyzy = with something
25 .set_state "hello world"
26
27do
28 x = 5 + with Something!
29 \write "hello world"
30
31
32do
33 x = {
34 hello: with yeah
35 \okay!
36 }
37
38do
39 with foo
40 \prop"something".hello
41 .prop\send(one)
42 .prop\send one
43
44
45--
46
47do
48 with a, b -- b is lost
49 print .world
50
51 mod = with _M = {}
52 .Thing = "hi"
53
54 -- operate on a only
55 with a, b = something, pooh
56 print .world
57
58 x = with a, b = 1, 2
59 print a + b
60
61 print with a, b = 1, 2
62 print a + b
63
64 -- assignment lhs must be evaluated in the order they appear
65 p = with hello!.x, world!.y = 1, 2
66 print a + b
67
68--
69
70do
71 x = "hello"
72 with x
73 x\upper!
74
75do
76 with k = "jo"
77 print \upper!
78
79do
80 with a,b,c = "", "", ""
81 print \upper!
82
83do
84 a = "bunk"
85 with a,b,c = "", "", ""
86 print \upper!
87
88do
89 with j
90 print \upper!
91
92do
93 with k.j = "jo"
94 print \upper!
95
96do
97 with a
98 print .b
99 -- nested `with`s should change the scope correctly
100 with .c
101 print .d
102
103do
104 with a
105 -- nested `with`s with assignments should change the scope correctly
106 with .b = 2
107 print .c
108
109do
110 ->
111 with hi
112 return .a, .b
113
114
115do
116 with dad
117 .if "yes"
118 y = .end.of.function