summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-01-25 17:48:03 +0800
committerLi Jin <dragon-fly@qq.com>2020-01-25 17:48:03 +0800
commited317e62eb1cf98fde4461fc90c6cb1045ebc7e8 (patch)
tree427e365939da39f31dbfa755675fb60bb141583d
parent4827d200604a086e2ad94edb4257c3abc7a3c4fc (diff)
downloadyuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.gz
yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.bz2
yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.zip
fix Moonscript issue 375.
-rw-r--r--README.md66
-rw-r--r--spec/inputs/assign.moon24
-rw-r--r--spec/inputs/bubbling.moon8
-rw-r--r--spec/inputs/class.moon158
-rw-r--r--spec/inputs/cond.moon104
-rw-r--r--spec/inputs/destructure.moon112
-rw-r--r--spec/inputs/do.moon26
-rw-r--r--spec/inputs/existential.moon22
-rw-r--r--spec/inputs/export.moon90
-rw-r--r--spec/inputs/funcs.moon104
-rw-r--r--spec/inputs/import.moon54
-rw-r--r--spec/inputs/lists.moon14
-rw-r--r--spec/inputs/local.moon108
-rw-r--r--spec/inputs/loops.moon102
-rw-r--r--spec/inputs/operators.moon54
-rw-r--r--spec/inputs/plus.moon6
-rw-r--r--spec/inputs/return.moon66
-rw-r--r--spec/inputs/stub.moon6
-rw-r--r--spec/inputs/switch.moon72
-rw-r--r--spec/inputs/syntax.moon78
-rw-r--r--spec/inputs/tables.moon138
-rw-r--r--spec/inputs/unless_else.moon8
-rw-r--r--spec/inputs/using.moon16
-rw-r--r--spec/inputs/whitespace.moon70
-rw-r--r--spec/inputs/with.moon136
-rw-r--r--src/MoonP/moon_ast.h3
-rw-r--r--src/MoonP/moon_compiler.cpp1
-rw-r--r--src/MoonP/moon_parser.cpp4
28 files changed, 867 insertions, 783 deletions
diff --git a/README.md b/README.md
index 2385a11..7421829 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
1# MoonPlus 1# MoonPlus
2 2
3![CI](https://github.com/pigpigyyy/MoonPlus/workflows/build-test/badge.svg) 3![CI](https://github.com/pigpigyyy/MoonPlus/workflows/build-test/badge.svg)
4MoonPlus is a compiler adopting features from Moonscript language 0.5.0 and could be 2~4 times faster than the original Moonscript compiler. 4MoonPlus is a compiler with features from Moonscript language 0.5.0 and could be 2~4 times faster than the original Moonscript compiler.
5 5
6## Features 6## Features
7 7
@@ -10,19 +10,75 @@ MoonPlus is a compiler adopting features from Moonscript language 0.5.0 and coul
10* Support full Moonscript language features, generate the same Lua codes with original compiler. 10* Support full Moonscript language features, generate the same Lua codes with original compiler.
11* Reserve line numbers from source Moonscript codes in compiled Lua codes to help with debugging. 11* Reserve line numbers from source Moonscript codes in compiled Lua codes to help with debugging.
12 12
13## Minor Changes 13## Changes
14 14
15* Can do slash call with Lua keyword. Generate codes from: 15* Add existential operator support. Generate codes from:
16```Moonscript 16```Moonscript
17c.repeat.if\then("xyz")\else res 17func?!
18
19x = tab?.value
20
21print abc?["hello world"]?.xyz
22
23if print and x?
24 print x
18``` 25```
19&emsp;&emsp;to: 26&emsp;&emsp;to:
27```Lua
28if func ~= nil then
29 func()
30end
31local x
32if tab ~= nil then
33 x = tab.value
34end
35print((function()
36 if abc ~= nil then
37 local _obj_0 = abc["hello world"]
38 if _obj_0 ~= nil then
39 return _obj_0.xyz
40 end
41 return nil
42 end
43 return nil
44end)())
45if print and (x ~= nil) then
46 print(x)
47end
48```
49
50* Can do slash call with Lua keywords. Generate codes from:
20```Moonscript 51```Moonscript
52c.repeat.if\then("xyz")\else res
53```
54&emsp;&emsp;to:
55```Lua
21local _call_3 = c["repeat"]["if"] 56local _call_3 = c["repeat"]["if"]
22local _call_4 = _call_3["then"](_call_3, "xyz") 57local _call_4 = _call_3["then"](_call_3, "xyz")
23_call_4["else"](_call_4, res) 58_call_4["else"](_call_4, res)
24``` 59```
25 60
61* Add more usage for `import` keyword. Will compile codes from:
62```Moonscript
63import 'module'
64import "module.part"
65import "d-a-s-h-e-s"
66import "player" as Player
67import "lpeg" as {:C, :Ct, :Cmt}
68```
69&emsp;&emsp;to:
70```Lua
71local module = require('module')
72local part = require("module.part")
73local d_a_s_h_e_s = require("d-a-s-h-e-s")
74local Player = require("player")
75local C, Ct, Cmt
76do
77 local _obj_0 = require("lpeg")
78 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
79end
80```
81
26* Add feature of `reusing variable` which helps generate reduced Lua codes. For example, MoonPlus will generate codes from: 82* Add feature of `reusing variable` which helps generate reduced Lua codes. For example, MoonPlus will generate codes from:
27```Moonscript 83```Moonscript
28with leaf 84with leaf
@@ -36,7 +92,7 @@ for x in *something
36 print x 92 print x
37``` 93```
38&emsp;&emsp;to: 94&emsp;&emsp;to:
39```lua 95```Lua
40leaf.world(1, 2, 3) 96leaf.world(1, 2, 3)
41do 97do
42 local g = leaf.what.is.this 98 local g = leaf.what.is.this
diff --git a/spec/inputs/assign.moon b/spec/inputs/assign.moon
index 3e66491..4e50147 100644
--- a/spec/inputs/assign.moon
+++ b/spec/inputs/assign.moon
@@ -1,30 +1,30 @@
1 1
2_ = -> 2_ = ->
3 joop = 2302 3 joop = 2302
4 4
5 (hi) -> 5 (hi) ->
6 d = 100 6 d = 100
7 hi = 1021 7 hi = 1021
8 8
9 a,b,c,d = 1,2,3,4 9 a,b,c,d = 1,2,3,4
10 10
11 hello[232], (5+5)[121], hello, x[99] = 100, 200, 300 11 hello[232], (5+5)[121], hello, x[99] = 100, 200, 300
12 12
13 joop = 12 13 joop = 12
14 14
15joop = 2345 15joop = 2345
16 16
17a, b = if hello 17a, b = if hello
18 "hello" 18 "hello"
19else 19else
20 "nothing", "yeah" 20 "nothing", "yeah"
21 21
22 22
23a, b = if hello 23a, b = if hello
24 if yeah then "one", "two" else "mmhh" 24 if yeah then "one", "two" else "mmhh"
25else 25else
26 print "the other" 26 print "the other"
27 "nothing", "yeah" 27 "nothing", "yeah"
28 28
29 29
30 30
diff --git a/spec/inputs/bubbling.moon b/spec/inputs/bubbling.moon
index d1004f9..62d1550 100644
--- a/spec/inputs/bubbling.moon
+++ b/spec/inputs/bubbling.moon
@@ -3,17 +3,17 @@
3f = (...) -> #{...} 3f = (...) -> #{...}
4 4
5dont_bubble = -> 5dont_bubble = ->
6 [x for x in ((...)-> print ...)("hello")] 6 [x for x in ((...)-> print ...)("hello")]
7 7
8k = [x for x in ((...)-> print ...)("hello")] 8k = [x for x in ((...)-> print ...)("hello")]
9 9
10j = for i=1,10 10j = for i=1,10
11 (...) -> print ... 11 (...) -> print ...
12 12
13-- bubble me 13-- bubble me
14 14
15m = (...) -> 15m = (...) ->
16 [x for x in *{...} when f(...) > 4] 16 [x for x in *{...} when f(...) > 4]
17 17
18x = for i in *{...} do i 18x = for i in *{...} do i
19y = [x for x in *{...}] 19y = [x for x in *{...}]
@@ -23,6 +23,6 @@ z = [x for x in hallo when f(...) > 4]
23a = for i=1,10 do ... 23a = for i=1,10 do ...
24 24
25b = for i=1,10 25b = for i=1,10
26 -> print ... 26 -> print ...
27 27
28 28
diff --git a/spec/inputs/class.moon b/spec/inputs/class.moon
index 60361ca..83f3760 100644
--- a/spec/inputs/class.moon
+++ b/spec/inputs/class.moon
@@ -1,10 +1,10 @@
1 1
2class Hello 2class Hello
3 new: (@test, @world) => 3 new: (@test, @world) =>
4 print "creating object.." 4 print "creating object.."
5 hello: => 5 hello: =>
6 print @test, @world 6 print @test, @world
7 __tostring: => "hello world" 7 __tostring: => "hello world"
8 8
9x = Hello 1,2 9x = Hello 1,2
10x\hello() 10x\hello()
@@ -12,26 +12,26 @@ x\hello()
12print x 12print x
13 13
14class Simple 14class Simple
15 cool: => print "cool" 15 cool: => print "cool"
16 16
17class Yikes extends Simple 17class Yikes extends Simple
18 new: => print "created hello" 18 new: => print "created hello"
19 19
20x = Yikes() 20x = Yikes()
21x\cool() 21x\cool()
22 22
23 23
24class Hi 24class Hi
25 new: (arg) => 25 new: (arg) =>
26 print "init arg", arg 26 print "init arg", arg
27 27
28 cool: (num) => 28 cool: (num) =>
29 print "num", num 29 print "num", num
30 30
31 31
32class Simple extends Hi 32class Simple extends Hi
33 new: => super "man" 33 new: => super "man"
34 cool: => super 120302 34 cool: => super 120302
35 35
36x = Simple() 36x = Simple()
37x\cool() 37x\cool()
@@ -40,45 +40,45 @@ print x.__class == Simple
40 40
41 41
42class Okay 42class Okay
43 -- what is going on 43 -- what is going on
44 something: 20323 44 something: 20323
45 -- yeaha 45 -- yeaha
46 46
47 47
48class Biggie extends Okay 48class Biggie extends Okay
49 something: => 49 something: =>
50 super 1,2,3,4 50 super 1,2,3,4
51 super.something another_self, 1,2,3,4 51 super.something another_self, 1,2,3,4
52 assert super == Okay 52 assert super == Okay
53 53
54 54
55class Yeah 55class Yeah
56 okay: => 56 okay: =>
57 super\something 1,2,3,4 57 super\something 1,2,3,4
58 58
59 59
60class What 60class What
61 something: => print "val:", @val 61 something: => print "val:", @val
62 62
63class Hello extends What 63class Hello extends What
64 val: 2323 64 val: 2323
65 something: => super\something 65 something: => super\something
66 66
67with Hello! 67with Hello!
68 x = \something! 68 x = \something!
69 print x 69 print x
70 x! 70 x!
71 71
72class CoolSuper 72class CoolSuper
73 hi: => 73 hi: =>
74 super(1,2,3,4) 1,2,3,4 74 super(1,2,3,4) 1,2,3,4
75 super.something 1,2,3,4 75 super.something 1,2,3,4
76 _ = super.something(1,2,3,4).world 76 _ = super.something(1,2,3,4).world
77 super\yeah"world".okay hi, hi, hi 77 super\yeah"world".okay hi, hi, hi
78 _ = something.super 78 _ = something.super
79 _ = super.super.super.super 79 _ = super.super.super.super
80 _ = super\hello 80 _ = super\hello
81 nil 81 nil
82 82
83 83
84-- selfing 84-- selfing
@@ -95,11 +95,11 @@ xx = (@hello, @@world, cool) ->
95 95
96-- class properties 96-- class properties
97class ClassMan 97class ClassMan
98 @yeah: 343 98 @yeah: 343
99 blue: => 99 blue: =>
100 @hello: 3434, @world: 23423 100 @hello: 3434, @world: 23423
101 green: => 101 green: =>
102 @red: => 102 @red: =>
103 103
104 104
105x = @ 105x = @
@@ -118,34 +118,34 @@ _ = hello[@].world
118 118
119 119
120class Whacko 120class Whacko
121 _ = @hello 121 _ = @hello
122 if something 122 if something
123 print "hello world" 123 print "hello world"
124 124
125 hello = "world" 125 hello = "world"
126 @another = "day" 126 @another = "day"
127 127
128 print "yeah" if something -- this is briken 128 print "yeah" if something -- this is briken
129 129
130 130
131print "hello" 131print "hello"
132 132
133yyy = -> 133yyy = ->
134 class Cool 134 class Cool
135 _ = nil 135 _ = nil
136 136
137 137
138-- 138--
139 139
140class a.b.c.D 140class a.b.c.D
141 _ = nil 141 _ = nil
142 142
143 143
144class a.b["hello"] 144class a.b["hello"]
145 _ = nil 145 _ = nil
146 146
147class (-> require "moon")!.Something extends Hello.World 147class (-> require "moon")!.Something extends Hello.World
148 _ = nil 148 _ = nil
149 149
150-- 150--
151 151
@@ -160,54 +160,54 @@ print (class WhatsUp).__name
160 160
161export ^ 161export ^
162class Something 162class Something
163 _ = nil 163 _ = nil
164 164
165 165
166-- 166--
167 167
168-- hoisting 168-- hoisting
169class Something 169class Something
170 val = 23 170 val = 23
171 {:insert} = table 171 {:insert} = table
172 new: => print insert, val -- prints nil 23 172 new: => print insert, val -- prints nil 23
173 173
174-- 174--
175 175
176class X 176class X
177 new: hi 177 new: hi
178 178
179 179
180-- 180--
181 181
182class Cool extends Thing 182class Cool extends Thing
183 dang: => 183 dang: =>
184 { 184 {
185 hello: -> super! 185 hello: -> super!
186 world: -> super.one 186 world: -> super.one
187 } 187 }
188 188
189-- 189--
190 190
191class Whack extends Thing 191class Whack extends Thing
192 dang: do_something => 192 dang: do_something =>
193 super! 193 super!
194 194
195--- 195---
196 196
197class Wowha extends Thing 197class Wowha extends Thing
198 @butt: -> 198 @butt: ->
199 super! 199 super!
200 _ = super.hello 200 _ = super.hello
201 super\hello! 201 super\hello!
202 super\hello 202 super\hello
203 203
204 204
205 @zone: cool { 205 @zone: cool {
206 -> 206 ->
207 super! 207 super!
208 _ = super.hello 208 _ = super.hello
209 super\hello! 209 super\hello!
210 super\hello 210 super\hello
211 } 211 }
212 212
213nil 213nil
diff --git a/spec/inputs/cond.moon b/spec/inputs/cond.moon
index e8b6283..3dee99b 100644
--- a/spec/inputs/cond.moon
+++ b/spec/inputs/cond.moon
@@ -2,24 +2,24 @@
2you_cool = false 2you_cool = false
3 3
4_ = if cool 4_ = if cool
5 if you_cool 5 if you_cool
6 one 6 one
7 else if eatdic 7 else if eatdic
8 yeah 8 yeah
9 else 9 else
10 _ = two 10 _ = two
11 three 11 three
12else 12else
13 no 13 no
14 14
15_ = if cool then no 15_ = if cool then no
16_ = if cool then no else yes 16_ = if cool then no else yes
17 17
18if cool then wow cool else 18if cool then wow cool else
19 noso cool 19 noso cool
20 20
21if working 21if working
22 _ = if cool then if cool then okay else what else nah 22 _ = if cool then if cool then okay else what else nah
23 23
24 24
25if yeah then no day elseif cool me then okay ya else u way 25if yeah then no day elseif cool me then okay ya else u way
@@ -29,117 +29,117 @@ if yeah then no dad else if cool you then okay bah else p way
29if (->)() then what ever 29if (->)() then what ever
30 30
31if nil then flip me else 31if nil then flip me else
32 it be,rad 32 it be,rad
33 33
34 34
35if things great then no way elseif okay sure 35if things great then no way elseif okay sure
36 what here 36 what here
37 37
38 38
39if things then no chance 39if things then no chance
40elseif okay 40elseif okay
41 what now 41 what now
42 42
43 43
44if things 44if things
45 yes man 45 yes man
46elseif okay person then hi there else hmm sure 46elseif okay person then hi there else hmm sure
47 47
48if lets go 48if lets go
49 print "greetings" 49 print "greetings"
50elseif "just us" 50elseif "just us"
51 print "will smith" else show 5555555 51 print "will smith" else show 5555555
52 52
53-- 53--
54 54
55if something = 10 55if something = 10
56 print something 56 print something
57else 57else
58 print "else" 58 print "else"
59 59
60hello = if something = 10 60hello = if something = 10
61 print something 61 print something
62else 62else
63 print "else" 63 print "else"
64 64
65 65
66hello = 5 + if something = 10 66hello = 5 + if something = 10
67 print something 67 print something
68 68
69--- 69---
70 70
71z = false 71z = false
72 72
73_ = if false 73_ = if false
74 one 74 one
75elseif x = true 75elseif x = true
76 two 76 two
77elseif z = true 77elseif z = true
78 three 78 three
79else 79else
80 four 80 four
81 81
82 82
83out = if false 83out = if false
84 one 84 one
85elseif x = true 85elseif x = true
86 two 86 two
87elseif z = true 87elseif z = true
88 three 88 three
89else 89else
90 four 90 four
91 91
92kzy = -> 92kzy = ->
93 if something = true 93 if something = true
94 1 94 1
95 elseif another = false 95 elseif another = false
96 2 96 2
97 97
98--- 98---
99 99
100unless true 100unless true
101 print "cool!" 101 print "cool!"
102 102
103unless true and false 103unless true and false
104 print "cool!" 104 print "cool!"
105 105
106unless false then print "cool!" 106unless false then print "cool!"
107unless false then print "cool!" else print "no way!" 107unless false then print "cool!" else print "no way!"
108 108
109unless nil 109unless nil
110 print "hello" 110 print "hello"
111else 111else
112 print "world" 112 print "world"
113 113
114-- 114--
115 115
116x = unless true 116x = unless true
117 print "cool!" 117 print "cool!"
118 118
119x = unless true and false 119x = unless true and false
120 print "cool!" 120 print "cool!"
121 121
122y = unless false then print "cool!" 122y = unless false then print "cool!"
123y = unless false then print "cool!" else print "no way!" 123y = unless false then print "cool!" else print "no way!"
124 124
125z = unless nil 125z = unless nil
126 print "hello" 126 print "hello"
127else 127else
128 print "world" 128 print "world"
129 129
130print unless true 130print unless true
131 print "cool!" 131 print "cool!"
132 132
133print unless true and false 133print unless true and false
134 print "cool!" 134 print "cool!"
135 135
136print unless false then print "cool!" 136print unless false then print "cool!"
137print unless false then print "cool!" else print "no way!" 137print unless false then print "cool!" else print "no way!"
138 138
139print unless nil 139print unless nil
140 print "hello" 140 print "hello"
141else 141else
142 print "world" 142 print "world"
143 143
144-- 144--
145 145
@@ -151,9 +151,9 @@ dddd = {1,2,3} unless value
151-- 151--
152 152
153do 153do
154 j = 100 154 j = 100
155 unless j = hi! 155 unless j = hi!
156 error "not j!" 156 error "not j!"
157 157
158---------------- 158----------------
159 159
@@ -165,8 +165,8 @@ a,c,b = "cool" if something
165--- 165---
166 166
167j = if 1 167j = if 1
168 if 2 168 if 2
169 3 169 3
170else 6 170else 6
171 171
172 172
@@ -174,10 +174,10 @@ m = if 1
174 174
175 175
176 176
177 if 2 177 if 2
178 178
179 179
180 3 180 3
181 181
182 182
183else 6 183else 6
diff --git a/spec/inputs/destructure.moon b/spec/inputs/destructure.moon
index 5bc7810..e0f2198 100644
--- a/spec/inputs/destructure.moon
+++ b/spec/inputs/destructure.moon
@@ -1,105 +1,105 @@
1 1
2do 2do
3 {a, b} = hello 3 {a, b} = hello
4 4
5 {{a}, b, {c}} = hello 5 {{a}, b, {c}} = hello
6 6
7 { :hello, :world } = value 7 { :hello, :world } = value
8 8
9do 9do
10 { yes: no, thing } = world 10 { yes: no, thing } = world
11 11
12 {:a,:b,:c,:d} = yeah 12 {:a,:b,:c,:d} = yeah
13 13
14 {a} = one, two 14 {a} = one, two
15 {b}, c = one 15 {b}, c = one
16 {d}, e = one, two 16 {d}, e = one, two
17 17
18 x, {y} = one, two 18 x, {y} = one, two
19 19
20 xx, yy = 1, 2 20 xx, yy = 1, 2
21 {yy, xx} = {xx, yy} 21 {yy, xx} = {xx, yy}
22 22
23 {a, :b, c, :d, e, :f, g} = tbl 23 {a, :b, c, :d, e, :f, g} = tbl
24 24
25--- 25---
26 26
27do 27do
28 futurists = 28 futurists =
29 sculptor: "Umberto Boccioni" 29 sculptor: "Umberto Boccioni"
30 painter: "Vladimir Burliuk" 30 painter: "Vladimir Burliuk"
31 poet: 31 poet:
32 name: "F.T. Marinetti" 32 name: "F.T. Marinetti"
33 address: { 33 address: {
34 "Via Roma 42R" 34 "Via Roma 42R"
35 "Bellagio, Italy 22021" 35 "Bellagio, Italy 22021"
36 } 36 }
37 37
38 {poet: {:name, address: {street, city}}} = futurists 38 {poet: {:name, address: {street, city}}} = futurists
39 39
40-- 40--
41 41
42do 42do
43 { @world } = x 43 { @world } = x
44 { a.b, c.y, func!.z } = x 44 { a.b, c.y, func!.z } = x
45 45
46 { world: @world } = x 46 { world: @world } = x
47 47
48-- 48--
49 49
50do 50do
51 thing = {{1,2}, {3,4}} 51 thing = {{1,2}, {3,4}}
52 52
53 for {x,y} in *thing 53 for {x,y} in *thing
54 print x,y 54 print x,y
55 55
56 56
57-- 57--
58 58
59do 59do
60 with {a,b} = thing 60 with {a,b} = thing
61 print a, b 61 print a, b
62 62
63 63
64-- 64--
65 65
66do 66do
67 thing = nil 67 thing = nil
68 if {a} = thing 68 if {a} = thing
69 print a 69 print a
70 else 70 else
71 print "nothing" 71 print "nothing"
72 72
73 thang = {1,2} 73 thang = {1,2}
74 if {a,b} = thang 74 if {a,b} = thang
75 print a,b 75 print a,b
76 76
77 if {a,b} = thing 77 if {a,b} = thing
78 print a,b 78 print a,b
79 elseif {c,d} = thang 79 elseif {c,d} = thang
80 print c,d 80 print c,d
81 else 81 else
82 print "NO" 82 print "NO"
83 83
84-- 84--
85 85
86do 86do
87 z = "yeah" 87 z = "yeah"
88 {a,b,c} = z 88 {a,b,c} = z
89 89
90do 90do
91 {a,b,c} = z 91 {a,b,c} = z
92 92
93_ = (z) -> 93_ = (z) ->
94 {a,b,c} = z 94 {a,b,c} = z
95 95
96do 96do
97 z = "oo" 97 z = "oo"
98 _ = (k) -> 98 _ = (k) ->
99 {a,b,c} = z 99 {a,b,c} = z
100 100
101do 101do
102 {function:{end:endVar}} = thing 102 {function:{end:endVar}} = thing
103 103
104do 104do
105 {if:{a,b,c}} = thing 105 {if:{a,b,c}} = thing
diff --git a/spec/inputs/do.moon b/spec/inputs/do.moon
index 21e2127..2fbcbb9 100644
--- a/spec/inputs/do.moon
+++ b/spec/inputs/do.moon
@@ -1,27 +1,27 @@
1 1
2do 2do
3 print "hello" 3 print "hello"
4 print "world" 4 print "world"
5 5
6x = do 6x = do
7 print "hello" 7 print "hello"
8 print "world" 8 print "world"
9 9
10y = do 10y = do
11 things = "shhh" 11 things = "shhh"
12 -> "hello: " .. things 12 -> "hello: " .. things
13 13
14_ = -> if something then do "yeah" 14_ = -> if something then do "yeah"
15 15
16t = { 16t = {
17 y: do 17 y: do
18 number = 100 18 number = 100
19 (x) -> x + number 19 (x) -> x + number
20} 20}
21 21
22(y=(do 22(y=(do
23 x = 10 + 2 23 x = 10 + 2
24 x), k=do 24 x), k=do
25 "nothing") -> do 25 "nothing") -> do
26 "uhhh" 26 "uhhh"
27 27
diff --git a/spec/inputs/existential.moon b/spec/inputs/existential.moon
index f7d5ebd..2264768 100644
--- a/spec/inputs/existential.moon
+++ b/spec/inputs/existential.moon
@@ -1,5 +1,7 @@
1 1
2f?! 2f1?!
3
4f2? "arg0",123
3 5
4x = tab?.value 6x = tab?.value
5 7
@@ -19,3 +21,21 @@ if {:x} = a?.if?\then?(123)? @?\function 998
19 21
20res = b.function\do!\while?("OK")\if("def",998)\f? 22res = b.function\do!\while?("OK")\if("def",998)\f?
21print res 23print res
24
25solipsism = true if mind? and not world?
26
27speed = 0
28speed or= 15
29
30footprints = yeti or "bear"
31
32major = 'Computer Science'
33
34unless major?
35 signUpForClass 'Introduction to Wines'
36
37if window?
38 environment = 'browser (probably)'
39
40zip = lottery.drawWinner?!.address?.zipcode
41
diff --git a/spec/inputs/export.moon b/spec/inputs/export.moon
index 0a56379..a8c782c 100644
--- a/spec/inputs/export.moon
+++ b/spec/inputs/export.moon
@@ -1,77 +1,77 @@
1 1
2do 2do
3 export a,b,c = 223, 343 3 export a,b,c = 223, 343
4 export cool = "dad" 4 export cool = "dad"
5 5
6do 6do
7 export class Something 7 export class Something
8 umm: "cool" 8 umm: "cool"
9 9
10do 10do
11 export a,b,c 11 export a,b,c
12 a,b,c,d = "hello" 12 a,b,c,d = "hello"
13 13
14 14
15do 15do
16 What = if this 16 What = if this
17 232 17 232
18 else 18 else
19 4343 19 4343
20 20
21 export ^ 21 export ^
22 22
23 another = 3434 23 another = 3434
24 Another = 7890 24 Another = 7890
25 25
26 if inner then Yeah = "10000" 26 if inner then Yeah = "10000"
27 27
28 What = if this 28 What = if this
29 232 29 232
30 else 30 else
31 4343 31 4343
32 32
33 33
34do 34do
35 export * 35 export *
36 36
37 What = if this 37 What = if this
38 232 38 232
39 else 39 else
40 4343 40 4343
41 41
42 x,y,z = 1,2,3 42 x,y,z = 1,2,3
43 43
44 y = -> 44 y = ->
45 hallo = 3434 45 hallo = 3434
46 46
47 with tmp 47 with tmp
48 j = 2000 48 j = 2000
49 49
50 50
51do 51do
52 export * 52 export *
53 x = 3434 53 x = 3434
54 if y then 54 if y then
55 x = 10 55 x = 10
56 56
57do 57do
58 export * 58 export *
59 if y then 59 if y then
60 x = 10 60 x = 10
61 x = 3434 61 x = 3434
62 62
63do 63do
64 do 64 do
65 export * 65 export *
66 66
67 k = 1212 67 k = 1212
68 68
69 do 69 do
70 h = 100 70 h = 100
71 71
72 y = -> 72 y = ->
73 h = 100 73 h = 100
74 k = 100 74 k = 100
75 75
76 h = 100 76 h = 100
77 77
diff --git a/spec/inputs/funcs.moon b/spec/inputs/funcs.moon
index da42db6..4176e33 100644
--- a/spec/inputs/funcs.moon
+++ b/spec/inputs/funcs.moon
@@ -11,9 +11,9 @@ go to the barn
11open -> the -> door 11open -> the -> door
12 12
13open -> 13open ->
14 the door 14 the door
15 hello = -> 15 hello = ->
16 my func 16 my func
17 17
18h = -> hi 18h = -> hi
19 19
@@ -35,7 +35,7 @@ what! the! heck!
35_ = (a,b,c,d,e) -> 35_ = (a,b,c,d,e) ->
36 36
37_ = (a,a,a,a,a) -> 37_ = (a,a,a,a,a) ->
38 print a 38 print a
39 39
40_ = (x=23023) -> 40_ = (x=23023) ->
41 41
@@ -44,7 +44,7 @@ _ = (x=(y=()->) ->) ->
44_ = (x = if something then yeah else no) -> 44_ = (x = if something then yeah else no) ->
45 45
46something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") -> 46something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") ->
47 print hello 47 print hello
48 48
49_ = (x, y) => 49_ = (x, y) =>
50_ = (@x, @y) => 50_ = (@x, @y) =>
@@ -62,99 +62,99 @@ _ = -> real_name if something
62-- 62--
63 63
64d( 64d(
65 -> 65 ->
66 print "hello world" 66 print "hello world"
67 10 67 10
68) 68)
69 69
70 70
71 71
72d( 72d(
73 1,2,3 73 1,2,3
74 4 74 4
75 5 75 5
76 6 76 6
77 77
78 if something 78 if something
79 print "okay" 79 print "okay"
80 10 80 10
81 81
82 10,20 82 10,20
83) 83)
84 84
85 85
86f( 86f(
87 87
88 )( 88 )(
89 89
90 )( 90 )(
91 what 91 what
92 )(-> 92 )(->
93 print "srue" 93 print "srue"
94 123) 94 123)
95 95
96-- 96--
97 97
98x = (a, 98x = (a,
99 b) -> 99 b) ->
100 print "what" 100 print "what"
101 101
102 102
103y = (a="hi", 103y = (a="hi",
104 b=23) -> 104 b=23) ->
105 print "what" 105 print "what"
106 106
107z = ( 107z = (
108 a="hi", 108 a="hi",
109 b=23) -> 109 b=23) ->
110 print "what" 110 print "what"
111 111
112 112
113j = (f,g,m, 113j = (f,g,m,
114 a="hi", 114 a="hi",
115 b=23 115 b=23
116) -> 116) ->
117 print "what" 117 print "what"
118 118
119 119
120y = (a="hi", 120y = (a="hi",
121 b=23, 121 b=23,
122 ...) -> 122 ...) ->
123 print "what" 123 print "what"
124 124
125 125
126y = (a="hi", 126y = (a="hi",
127 b=23, 127 b=23,
128 ... 128 ...
129) -> 129) ->
130 print "what" 130 print "what"
131 131
132-- 132--
133 133
134args = (a 134args = (a
135 b) -> 135 b) ->
136 print "what" 136 print "what"
137 137
138 138
139args = (a="hi" 139args = (a="hi"
140 b=23) -> 140 b=23) ->
141 print "what" 141 print "what"
142 142
143args = ( 143args = (
144 a="hi" 144 a="hi"
145 b=23) -> 145 b=23) ->
146 print "what" 146 print "what"
147 147
148 148
149args = (f,g,m 149args = (f,g,m
150 a="hi" 150 a="hi"
151 b=23 151 b=23
152) -> 152) ->
153 print "what" 153 print "what"
154 154
155 155
156@ = (n)-> 156@ = (n)->
157 return 1 if n == 0 157 return 1 if n == 0
158 n * @(n-1) 158 n * @(n-1)
159 159
160nil 160nil
diff --git a/spec/inputs/import.moon b/spec/inputs/import.moon
index ef6f4ee..ded1ffd 100644
--- a/spec/inputs/import.moon
+++ b/spec/inputs/import.moon
@@ -18,50 +18,50 @@ import something from a table
18 18
19 19
20if indent 20if indent
21 import okay, \well from tables[100] 21 import okay, \well from tables[100]
22 22
23do 23do
24 import a, b, c from z 24 import a, b, c from z
25 25
26do 26do
27 import a, 27 import a,
28 b, c from z 28 b, c from z
29 29
30do 30do
31 import a 31 import a
32 b 32 b
33 c from z 33 c from z
34 34
35do 35do
36 import 36 import
37 a 37 a
38 b 38 b
39 c from z 39 c from z
40 40
41 41
42do 42do
43 import 43 import
44 a 44 a
45 b 45 b
46 c 46 c
47 from z 47 from z
48 48
49 49
50do 50do
51 import 'module' 51 import 'module'
52 import 'module_x' 52 import 'module_x'
53 import "d-a-s-h-e-s" 53 import "d-a-s-h-e-s"
54 import "module.part" 54 import "module.part"
55 55
56do 56do
57 import "player" as Player 57 import "player" as Player
58 import "lpeg" as {:C, :Ct, :Cmt} 58 import "lpeg" as {:C, :Ct, :Cmt}
59 59
60do 60do
61 export * 61 export *
62 import 'module' 62 import 'module'
63 import 'module_x' 63 import 'module_x'
64 import "org.package.module-y" 64 import "org.package.module-y"
65 65
66do 66do
67 import "org.package.module" as {function:func,if:ifVar} 67 import "org.package.module" as {function:func,if:ifVar}
diff --git a/spec/inputs/lists.moon b/spec/inputs/lists.moon
index ef5650c..15eb9ab 100644
--- a/spec/inputs/lists.moon
+++ b/spec/inputs/lists.moon
@@ -6,7 +6,7 @@ items = {1,2,3,4,5,6}
6_ = [z for z in ipairs items when z > 4] 6_ = [z for z in ipairs items when z > 4]
7 7
8rad = [{a} for a in ipairs { 8rad = [{a} for a in ipairs {
9 1,2,3,4,5,6, 9 1,2,3,4,5,6,
10} when good_number a] 10} when good_number a]
11 11
12 12
@@ -17,11 +17,11 @@ require "util"
17dump = (x) -> print util.dump x 17dump = (x) -> print util.dump x
18 18
19range = (count) -> 19range = (count) ->
20 i = 0 20 i = 0
21 return coroutine.wrap -> 21 return coroutine.wrap ->
22 while i < count 22 while i < count
23 coroutine.yield i 23 coroutine.yield i
24 i = i + 1 24 i = i + 1
25 25
26dump [x for x in range 10] 26dump [x for x in range 10]
27dump [{x, y} for x in range 5 when x > 2 for y in range 5] 27dump [{x, y} for x in range 5 when x > 2 for y in range 5]
@@ -61,7 +61,7 @@ print y for y in *x[a,b,c]
61 61
62 62
63normal = (hello) -> 63normal = (hello) ->
64 [x for x in yeah] 64 [x for x in yeah]
65 65
66 66
67test = x 1,2,3,4,5 67test = x 1,2,3,4,5
diff --git a/spec/inputs/local.moon b/spec/inputs/local.moon
index f14f575..33251a9 100644
--- a/spec/inputs/local.moon
+++ b/spec/inputs/local.moon
@@ -1,94 +1,94 @@
1 1
2do 2do
3 local a 3 local a
4 local a,b,c 4 local a,b,c
5 5
6 b,g = 23232 6 b,g = 23232
7 7
8 8
9do 9do
10 x = 1212 10 x = 1212
11 something = -> 11 something = ->
12 local x 12 local x
13 x = 1212 13 x = 1212
14 14
15do 15do
16 local * 16 local *
17 y = 2323 17 y = 2323
18 z = 2323 18 z = 2323
19 19
20do 20do
21 local * 21 local *
22 print "Nothing Here!" 22 print "Nothing Here!"
23 23
24do 24do
25 local ^ 25 local ^
26 x = 3434 26 x = 3434
27 y = 3434 27 y = 3434
28 X = 3434 28 X = 3434
29 Y = "yeah" 29 Y = "yeah"
30 30
31do 31do
32 local ^ 32 local ^
33 x,y = "a", "b" 33 x,y = "a", "b"
34 34
35do 35do
36 local * 36 local *
37 x,y = "a", "b" 37 x,y = "a", "b"
38 38
39 39
40do 40do
41 local * 41 local *
42 if something 42 if something
43 x = 2323 43 x = 2323
44 44
45do 45do
46 local * 46 local *
47 do 47 do
48 x = "one" 48 x = "one"
49 49
50 x = 100 50 x = 100
51 51
52 do 52 do
53 x = "two" 53 x = "two"
54 54
55do 55do
56 local * 56 local *
57 k = if what 57 k = if what
58 10 58 10
59 x = 100 59 x = 100
60 60
61 {:a,:b, :c} = y 61 {:a,:b, :c} = y
62 62
63 63
64do 64do
65 local * 65 local *
66 66
67 a = 100 67 a = 100
68 print "hi" 68 print "hi"
69 b = 200 69 b = 200
70 70
71 local * 71 local *
72 c = 100 72 c = 100
73 print "hi" 73 print "hi"
74 d = 200 74 d = 200
75 d = 2323 75 d = 2323
76 76
77 77
78do 78do
79 local ^ 79 local ^
80 lowercase = 5 80 lowercase = 5
81 Uppercase = 3 81 Uppercase = 3
82 82
83 class One 83 class One
84 Five = 6 84 Five = 6
85 85
86 class Two 86 class Two
87 class No 87 class No
88 88
89do 89do
90 local * 90 local *
91 -- this generates a nil value in the body 91 -- this generates a nil value in the body
92 for a in *{} do _ = a 92 for a in *{} do _ = a
93 93
94g = 2323 -- test if anything leaked 94g = 2323 -- test if anything leaked
diff --git a/spec/inputs/loops.moon b/spec/inputs/loops.moon
index 130570e..35427f6 100644
--- a/spec/inputs/loops.moon
+++ b/spec/inputs/loops.moon
@@ -1,133 +1,133 @@
1 1
2for x=1,10 2for x=1,10
3 print "yeah" 3 print "yeah"
4 4
5for x=1,#something 5for x=1,#something
6 print "yeah" 6 print "yeah"
7 7
8for y=100,60,-3 8for y=100,60,-3
9 print "count down", y 9 print "count down", y
10 10
11for a=1,10 do print "okay" 11for a=1,10 do print "okay"
12 12
13for a=1,10 13for a=1,10
14 for b = 2,43 14 for b = 2,43
15 print a,b 15 print a,b
16 16
17for i in iter 17for i in iter
18 for j in yeah 18 for j in yeah
19 x = 343 + i + j 19 x = 343 + i + j
20 print i, j 20 print i, j
21 21
22for x in *something 22for x in *something
23 print x 23 print x
24 24
25for k,v in pairs hello do print k,v 25for k,v in pairs hello do print k,v
26 26
27for x in y, z 27for x in y, z
28 print x 28 print x
29 29
30for x in y, z, k 30for x in y, z, k
31 print x 31 print x
32 32
33 33
34x = -> 34x = ->
35 for x in y 35 for x in y
36 _ = y 36 _ = y
37 37
38hello = {1,2,3,4,5} 38hello = {1,2,3,4,5}
39 39
40x = for y in *hello 40x = for y in *hello
41 if y % 2 == 0 41 if y % 2 == 0
42 y 42 y
43 43
44x = -> 44x = ->
45 for x in *hello 45 for x in *hello
46 _ = y 46 _ = y
47 47
48t = for i=10,20 do i * 2 48t = for i=10,20 do i * 2
49 49
50hmm = 0 50hmm = 0
51y = for j = 3,30, 8 51y = for j = 3,30, 8
52 hmm += 1 52 hmm += 1
53 j * hmm 53 j * hmm
54 54
55_ = -> 55_ = ->
56 for k=10,40 56 for k=10,40
57 _ = "okay" 57 _ = "okay"
58 58
59_ = -> 59_ = ->
60 return for k=10,40 60 return for k=10,40
61 "okay" 61 "okay"
62 62
63while true do print "name" 63while true do print "name"
64 64
65while 5 + 5 65while 5 + 5
66 print "okay world" 66 print "okay world"
67 working man 67 working man
68 68
69while also do 69while also do
70 i work too 70 i work too
71 _ = "okay" 71 _ = "okay"
72 72
73i = 0 73i = 0
74x = while i < 10 74x = while i < 10
75 i += 1 75 i += 1
76 76
77-- values that can'e be coerced 77-- values that can'e be coerced
78 78
79x = for thing in *3 79x = for thing in *3
80 y = "hello" 80 y = "hello"
81 81
82x = for x=1,2 82x = for x=1,2
83 y = "hello" 83 y = "hello"
84 84
85 85
86-- continue 86-- continue
87 87
88while true 88while true
89 continue if false 89 continue if false
90 print "yes" 90 print "yes"
91 break if true 91 break if true
92 print "no" 92 print "no"
93 93
94 94
95for x=1,10 95for x=1,10
96 continue if x > 3 and x < 7 96 continue if x > 3 and x < 7
97 print x 97 print x
98 98
99 99
100list = for x=1,10 100list = for x=1,10
101 continue if x > 3 and x < 7 101 continue if x > 3 and x < 7
102 x 102 x
103 103
104 104
105for a in *{1,2,3,4,5,6} 105for a in *{1,2,3,4,5,6}
106 continue if a == 1 106 continue if a == 1
107 continue if a == 3 107 continue if a == 3
108 print a 108 print a
109 109
110 110
111 111
112for x=1,10 112for x=1,10
113 continue if x % 2 == 0 113 continue if x % 2 == 0
114 for y = 2,12 114 for y = 2,12
115 continue if y % 3 == 0 115 continue if y % 3 == 0
116 116
117 117
118while true 118while true
119 continue if false 119 continue if false
120 break 120 break
121 121
122while true 122while true
123 continue if false 123 continue if false
124 return 22 124 return 22
125 125
126-- 126--
127 127
128do 128do
129 xxx = {1,2,3,4} 129 xxx = {1,2,3,4}
130 for thing in *xxx 130 for thing in *xxx
131 print thing 131 print thing
132 132
133 133
diff --git a/spec/inputs/operators.moon b/spec/inputs/operators.moon
index 142ef62..57e58d6 100644
--- a/spec/inputs/operators.moon
+++ b/spec/inputs/operators.moon
@@ -3,70 +3,70 @@
3x = 1 + 3 3x = 1 + 3
4 4
5y = 1 + 5y = 1 +
6 3 6 3
7 7
8z = 1 + 8z = 1 +
9 3 + 9 3 +
10 4 10 4
11 11
12-- 12--
13 13
14k = b and c and 14k = b and c and
15 g 15 g
16 16
17 17
18h = thing and 18h = thing and
19 -> 19 ->
20 print "hello world" 20 print "hello world"
21 21
22-- TODO: should fail, indent still set to previous line so it thinks body is 22-- TODO: should fail, indent still set to previous line so it thinks body is
23-- indented 23-- indented
24i = thing or 24i = thing or
25 -> 25 ->
26 print "hello world" 26 print "hello world"
27 27
28p = thing and 28p = thing and
29 -> 29 ->
30print "hello world" 30print "hello world"
31 31
32s = thing or 32s = thing or
33 -> and 234 33 -> and 234
34 34
35 35
36-- 36--
37u = { 37u = {
38 color: 1 and 2 and 38 color: 1 and 2 and
39 3 39 3
40 4 40 4
41 4 41 4
42} 42}
43 43
44v = { 44v = {
45 color: 1 and 45 color: 1 and
46 -> 46 ->
47 "yeah" 47 "yeah"
48 "great" 48 "great"
49 oksy: 3 ^ 49 oksy: 3 ^
502 502
51} 51}
52 52
53-- parens 53-- parens
54 54
55nno = ( 55nno = (
56 yeah + 2 ) 56 yeah + 2 )
57 57
58nn = ( 58nn = (
59 yeah + 2 59 yeah + 2
60) 60)
61 61
62n = hello( 62n = hello(
63 b 63 b
64) -> 64) ->
65 65
66hello a, 66hello a,
67 ( 67 (
68 yeah + 68 yeah +
69 2 69 2
70 ) - 70 ) -
71 okay 71 okay
72 72
diff --git a/spec/inputs/plus.moon b/spec/inputs/plus.moon
index 7b9ef05..8a91c93 100644
--- a/spec/inputs/plus.moon
+++ b/spec/inputs/plus.moon
@@ -7,3 +7,9 @@ c.repeat.if\then("xyz")\else res
7 7
8print @for,@@function 123 8print @for,@@function 123
9 9
10if fcolor = message\match "<%w*>" then message = message\gsub "<%->", fcolor
11
12message = message\gsub "<%->", fcolor if fcolor = message\match "<%w*>"
13
14func val if val = getvalue!
15
diff --git a/spec/inputs/return.moon b/spec/inputs/return.moon
index 98c3104..f170ffd 100644
--- a/spec/inputs/return.moon
+++ b/spec/inputs/return.moon
@@ -6,48 +6,48 @@ _ = -> [x for x in *things]
6 6
7-- doesn't make sense on purpose 7-- doesn't make sense on purpose
8do 8do
9 return x for x in *things 9 return x for x in *things
10 10
11do 11do
12 return [x for x in *things] 12 return [x for x in *things]
13 13
14do 14do
15 return {x,y for x,y in *things} 15 return {x,y for x,y in *things}
16 16
17_ = -> 17_ = ->
18 if a 18 if a
19 if a 19 if a
20 a 20 a
21 else 21 else
22 b 22 b
23 elseif b 23 elseif b
24 if a 24 if a
25 a 25 a
26 else 26 else
27 b 27 b
28 else 28 else
29 if a 29 if a
30 a 30 a
31 else 31 else
32 b 32 b
33 33
34 34
35do 35do
36 return if a 36 return if a
37 if a 37 if a
38 a 38 a
39 else 39 else
40 b 40 b
41 elseif b 41 elseif b
42 if a 42 if a
43 a 43 a
44 else 44 else
45 b 45 b
46 else 46 else
47 if a 47 if a
48 a 48 a
49 else 49 else
50 b 50 b
51 51
52_ = -> a\b 52_ = -> a\b
53do a\b 53do a\b
diff --git a/spec/inputs/stub.moon b/spec/inputs/stub.moon
index f8f6c3f..b38056a 100644
--- a/spec/inputs/stub.moon
+++ b/spec/inputs/stub.moon
@@ -1,9 +1,9 @@
1 1
2 2
3x = { 3x = {
4 val: 100 4 val: 100
5 hello: => 5 hello: =>
6 print @val 6 print @val
7} 7}
8 8
9fn = x\val 9fn = x\val
diff --git a/spec/inputs/switch.moon b/spec/inputs/switch.moon
index a028f98..ac3dbea 100644
--- a/spec/inputs/switch.moon
+++ b/spec/inputs/switch.moon
@@ -1,64 +1,64 @@
1 1
2switch value 2switch value
3 when "cool" 3 when "cool"
4 print "hello world" 4 print "hello world"
5 5
6 6
7switch value 7switch value
8 when "cool" 8 when "cool"
9 print "hello world" 9 print "hello world"
10 else 10 else
11 print "okay rad" 11 print "okay rad"
12 12
13 13
14switch value 14switch value
15 when "cool" 15 when "cool"
16 print "hello world" 16 print "hello world"
17 when "yeah" 17 when "yeah"
18 _ = [[FFFF]] + [[MMMM]] 18 _ = [[FFFF]] + [[MMMM]]
19 when 2323 + 32434 19 when 2323 + 32434
20 print "okay" 20 print "okay"
21 else 21 else
22 print "okay rad" 22 print "okay rad"
23 23
24out = switch value 24out = switch value
25 when "cool" then print "hello world" 25 when "cool" then print "hello world"
26 else print "okay rad" 26 else print "okay rad"
27 27
28out = switch value 28out = switch value
29 when "cool" then xxxx 29 when "cool" then xxxx
30 when "umm" then 34340 30 when "umm" then 34340
31 else error "this failed big time" 31 else error "this failed big time"
32 32
33with something 33with something
34 switch \value! 34 switch \value!
35 when .okay 35 when .okay
36 _ = "world" 36 _ = "world"
37 else 37 else
38 _ = "yesh" 38 _ = "yesh"
39 39
40fix this 40fix this
41call_func switch something 41call_func switch something
42 when 1 then "yes" 42 when 1 then "yes"
43 else "no" 43 else "no"
44 44
45-- 45--
46 46
47switch hi 47switch hi
48 when hello or world 48 when hello or world
49 _ = greene 49 _ = greene
50 50
51-- 51--
52 52
53switch hi 53switch hi
54 when "one", "two" 54 when "one", "two"
55 print "cool" 55 print "cool"
56 when "dad" 56 when "dad"
57 _ = no 57 _ = no
58 58
59switch hi 59switch hi
60 when 3+1, hello!, (-> 4)! 60 when 3+1, hello!, (-> 4)!
61 yello 61 yello
62 else 62 else
63 print "cool" 63 print "cool"
64 64
diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon
index 351b22c..bf0cf04 100644
--- a/spec/inputs/syntax.moon
+++ b/spec/inputs/syntax.moon
@@ -29,7 +29,7 @@ hairy[hands][are](gross) okay okay[world]
29 29
30_ = (get[something] + 5)[years] 30_ = (get[something] + 5)[years]
31 31
32i,x = 200, 300 32i,x = 200, 300
33 33
34yeah = (1 + 5) * 3 34yeah = (1 + 5) * 3
35yeah = ((1+5)*3)/2 35yeah = ((1+5)*3)/2
@@ -38,16 +38,16 @@ yeah = ((1+5)*3)/2 + i % 100
38whoa = (1+2) * (3+4) * (4+5) 38whoa = (1+2) * (3+4) * (4+5)
39 39
40_ = -> 40_ = ->
41 if something 41 if something
42 return 1,2,4 42 return 1,2,4
43 43
44 print "hello" 44 print "hello"
45 45
46_ = -> 46_ = ->
47 if hello 47 if hello
48 "heloo", "world" 48 "heloo", "world"
49 else 49 else
50 no, way 50 no, way
51 51
52 52
53_ = -> 1,2,34 53_ = -> 1,2,34
@@ -82,23 +82,23 @@ _ = here(we)"go"[12123]
82 82
83-- this runs 83-- this runs
84something = 84something =
85 test: 12323 85 test: 12323
86 what: -> print "hello world" 86 what: -> print "hello world"
87 87
88print something.test 88print something.test
89 89
90frick = hello: "world" 90frick = hello: "world"
91 91
92argon = 92argon =
93 num: 100 93 num: 100
94 world: (self) -> 94 world: (self) ->
95 print self.num 95 print self.num
96 return { 96 return {
97 something: -> print "hi from something" 97 something: -> print "hi from something"
98 } 98 }
99 somethin: (self, str) -> 99 somethin: (self, str) ->
100 print "string is", str 100 print "string is", str
101 return world: (a,b) -> print "sum", a + b 101 return world: (a,b) -> print "sum", a + b
102 102
103something.what() 103something.what()
104argon\world().something() 104argon\world().something()
@@ -127,7 +127,7 @@ print "what" if cool else whack!
127arg = {...} 127arg = {...}
128 128
129x = (...) -> 129x = (...) ->
130 dump {...} 130 dump {...}
131 131
132 132
133x = not true 133x = not true
@@ -167,11 +167,11 @@ _ = (if ntype(v) == "fndef" then x += 1) for v in *values
167 167
168 168
169hello = 169hello =
170 something: world 170 something: world
171 if: "hello" 171 if: "hello"
172 else: 3434 172 else: 3434
173 function: "okay" 173 function: "okay"
174 good: 230203 174 good: 230203
175 175
176 176
177div class: "cool" 177div class: "cool"
@@ -185,29 +185,29 @@ what whack - 5
185x = hello - world - something 185x = hello - world - something
186 186
187((something = with what 187((something = with what
188 \cool 100) -> 188 \cool 100) ->
189 print something)! 189 print something)!
190 190
191if something 191if something
192 _ = 03589 192 _ = 03589
193 193
194-- okay what about this 194-- okay what about this
195 195
196else 196else
197 _ = 3434 197 _ = 3434
198 198
199 199
200if something 200if something
201 _ = yeah 201 _ = yeah
202 202
203 203
204elseif "ymmm" 204elseif "ymmm"
205 205
206 print "cool" 206 print "cool"
207 207
208else 208else
209 209
210 _ = okay 210 _ = okay
211 211
212 212
213-- test names containing keywords 213-- test names containing keywords
@@ -220,15 +220,15 @@ z = x andb
220-- undelimited tables 220-- undelimited tables
221 221
222while 10 > something 222while 10 > something
223 something: "world" 223 something: "world"
224 print "yeah" 224 print "yeah"
225 225
226x = 226x =
227 okay: sure 227 okay: sure
228 228
229yeah 229yeah
230 okay: man 230 okay: man
231 sure: sir 231 sure: sir
232 232
233hello "no comma" 233hello "no comma"
234 yeah: dada 234 yeah: dada
@@ -240,8 +240,8 @@ hello "comma",
240 240
241-- creates two tables 241-- creates two tables
242another hello, one, 242another hello, one,
243 two, three, four, yeah: man 243 two, three, four, yeah: man
244 okay: yeah 244 okay: yeah
245 245
246-- 246--
247a += 3 - 5 247a += 3 - 5
diff --git a/spec/inputs/tables.moon b/spec/inputs/tables.moon
index 10bccde..d7596f5 100644
--- a/spec/inputs/tables.moon
+++ b/spec/inputs/tables.moon
@@ -1,33 +1,33 @@
1 1
2backpack = 2backpack =
3 something: 3 something:
4 yeah: 200 4 yeah: 200
5 they: -> 5 they: ->
6 print "hello" 6 print "hello"
7 yor_feet"small" 7 yor_feet"small"
8 pretty: hair 8 pretty: hair
9 gold: hmm 9 gold: hmm
10 yow: 1000 10 yow: 1000
11 11
12 eat: goo 12 eat: goo
13 yeah: dudd 13 yeah: dudd
14 14
15 15
16start = 16start =
17 something: "cold" 17 something: "cold"
18 18
19bathe = 19bathe =
20 on: "fire" 20 on: "fire"
21 21
22another = 22another =
23 [4]: 232 23 [4]: 232
24 ["good food"]: "is the best" 24 ["good food"]: "is the best"
25 25
26fwip = 26fwip =
27 something: hello"what", number: 2323, 27 something: hello"what", number: 2323,
28 what: yo "momma", "yeah", 28 what: yo "momma", "yeah",
29 fruit: basket 29 fruit: basket
30 nuts: day 30 nuts: day
31 31
32 32
33frick = hello: "world" 33frick = hello: "world"
@@ -38,106 +38,106 @@ ya = { 1,2,3, key: 100, 343, "hello", umm: 232 }
38 38
39 39
40x = { 1,2, 40x = { 1,2,
41 4343, 343 ,343 } 41 4343, 343 ,343 }
42 42
43 43
44g, p = { 44g, p = {
45 1,2, nowy: "yes", 3,4, 45 1,2, nowy: "yes", 3,4,
46 hey: 232, another: "day" 46 hey: 232, another: "day"
47}, 234 47}, 234
48 48
49annother = { 49annother = {
50 1,2,3 50 1,2,3
51 3,4,5 51 3,4,5
52 6,7,8 52 6,7,8
53} 53}
54 54
55yeah = { 55yeah = {
56 [232]: 3434, "helo" 56 [232]: 3434, "helo"
57 ice: "cake" 57 ice: "cake"
58} 58}
59 59
60-- confusing stuff... 60-- confusing stuff...
61whatabout = { 61whatabout = {
62 hello world, another 62 hello world, another
63 what, about, now 63 what, about, now
64 64
65 hello"world", yeah 65 hello"world", yeah
66 hello "world", yeah 66 hello "world", yeah
67} 67}
68 68
69x = 69x =
70 -- yeah 70 -- yeah
71 something: => "hello" 71 something: => "hello"
72 cool: -- umm 72 cool: -- umm
73 --so ething 73 --so ething
74 bed: { 74 bed: {
75 2323,2323 75 2323,2323
76 } 76 }
77 red: 2343 -- here 77 red: 2343 -- here
78 -- what 78 -- what
79 name: (node) => @value node -- here 79 name: (node) => @value node -- here
80 -- comment me 80 -- comment me
81-- okay 81-- okay
82 82
83 83
84x = { :something, something: something } 84x = { :something, something: something }
85 85
86y = { 86y = {
87 :hi, :there, :how, :you 87 :hi, :there, :how, :you
88 :thing 88 :thing
89} 89}
90 90
91call_me "hello", :x, :y, :z 91call_me "hello", :x, :y, :z
92 92
93t = { 93t = {
94 a: 'a' 94 a: 'a'
95 [b]: 'b' 95 [b]: 'b'
96} 96}
97 97
98xam = { 98xam = {
99 hello: 1234 99 hello: 1234
100 "hello": 12354 100 "hello": 12354
101 ["hello"]: 12354 101 ["hello"]: 12354
102} 102}
103 103
104 104
105kam = { 105kam = {
106 hello: 12 106 hello: 12
107 goodcheese: 107 goodcheese:
108 "mmm" 108 "mmm"
109 109
110 yeah: 110 yeah:
111 12 + 232 111 12 + 232
112 112
113 lets: 113 lets:
114 keepit going: true, 114 keepit going: true,
115 okay: "yeah" 115 okay: "yeah"
116 116
117 more: 117 more:
118 { 118 {
119 1, [x for x=1,10] 119 1, [x for x=1,10]
120 } 120 }
121 121
122 [{"one", "two"}]: 122 [{"one", "two"}]:
123 one_thing => 123 one_thing =>
124} 124}
125 125
126-- TODO: both of these have undesirable output 126-- TODO: both of these have undesirable output
127keepit going: true, 127keepit going: true,
128 okay: "yeah", 128 okay: "yeah",
129 workd: "okay" 129 workd: "okay"
130 130
131thing what: 131thing what:
132 "great", no: 132 "great", no:
133 "more" 133 "more"
134 okay: 123 134 okay: 123
135 135
136 136
137-- 137--
138thing what: 138thing what:
139 "great", no: 139 "great", no:
140 "more" 140 "more"
141_ = okay: 123 -- a anon table 141_ = okay: 123 -- a anon table
142 142
143 143
diff --git a/spec/inputs/unless_else.moon b/spec/inputs/unless_else.moon
index fe96c0b..b421d4d 100644
--- a/spec/inputs/unless_else.moon
+++ b/spec/inputs/unless_else.moon
@@ -1,5 +1,5 @@
1if a 1if a
2 unless b 2 unless b
3 print "hi" 3 print "hi"
4 elseif c 4 elseif c
5 print "not hi" 5 print "not hi"
diff --git a/spec/inputs/using.moon b/spec/inputs/using.moon
index cd78ba6..fe0a433 100644
--- a/spec/inputs/using.moon
+++ b/spec/inputs/using.moon
@@ -3,20 +3,20 @@ hello = "hello"
3world = "world" 3world = "world"
4 4
5_ = (using nil) -> 5_ = (using nil) ->
6 hello = 3223 6 hello = 3223
7 7
8_ = (a using nil) -> 8_ = (a using nil) ->
9 hello = 3223 9 hello = 3223
10 a = 323 10 a = 323
11 11
12_ = (a,b,c using a,b,c) -> 12_ = (a,b,c using a,b,c) ->
13 a,b,c = 1,2,3 13 a,b,c = 1,2,3
14 world = 12321 14 world = 12321
15 15
16(a,e,f using a,b,c, hello) -> 16(a,e,f using a,b,c, hello) ->
17 a,b,c = 1,2,3 17 a,b,c = 1,2,3
18 hello = 12321 18 hello = 12321
19 world = "yeah" 19 world = "yeah"
20 20
21 21
22 22
diff --git a/spec/inputs/whitespace.moon b/spec/inputs/whitespace.moon
index e505b1b..36f14ae 100644
--- a/spec/inputs/whitespace.moon
+++ b/spec/inputs/whitespace.moon
@@ -1,6 +1,6 @@
1 1
2_ = { 2_ = {
3 1, 2 3 1, 2
4} 4}
5 5
6_ = { 1, 2 6_ = { 1, 2
@@ -16,22 +16,22 @@ _ = {
16} 16}
17 17
18_ = { something 1,2, 18_ = { something 1,2,
19 4,5,6, 19 4,5,6,
20 3,4,5 20 3,4,5
21} 21}
22 22
23_ = { 23_ = {
24 a 1,2,3, 24 a 1,2,3,
25 4,5,6 25 4,5,6
26 1,2,3 26 1,2,3
27} 27}
28 28
29 29
30_ = { 30_ = {
31 b 1,2,3, 31 b 1,2,3,
32 4,5,6 32 4,5,6
33 1,2,3, 33 1,2,3,
34 1,2,3 34 1,2,3
35} 35}
36 36
37_ = { 1,2,3 } 37_ = { 1,2,3 }
@@ -41,61 +41,61 @@ _ = { c 1,2,3,
41 41
42 42
43hello 1,2,3,4, 43hello 1,2,3,4,
44 1,2,3,4,4,5 44 1,2,3,4,4,5
45 45
46x 1, 46x 1,
47 2, 3, 47 2, 3,
48 4, 5, 6 48 4, 5, 6
49 49
50 50
51hello 1,2,3, 51hello 1,2,3,
52 world 4,5,6, 52 world 4,5,6,
53 5,6,7,8 53 5,6,7,8
54 54
55hello 1,2,3, 55hello 1,2,3,
56 world 4,5,6, 56 world 4,5,6,
57 5,6,7,8, 57 5,6,7,8,
58 9,9 58 9,9
59 59
60 60
61_ = { 61_ = {
62 hello 1,2, 62 hello 1,2,
63 3,4, 63 3,4,
64 5, 6 64 5, 6
65} 65}
66 66
67x = { 67x = {
68 hello 1,2,3,4, 68 hello 1,2,3,4,
69 5,6,7 69 5,6,7
70 1,2,3,4 70 1,2,3,4
71} 71}
72 72
73if hello 1,2,3, 73if hello 1,2,3,
74 world, 74 world,
75 world 75 world
76 print "hello" 76 print "hello"
77 77
78if hello 1,2,3, 78if hello 1,2,3,
79 world, 79 world,
80 world 80 world
81 print "hello" 81 print "hello"
82 82
83 83
84-- 84--
85 85
86a( 86a(
87 one, two, three 87 one, two, three
88) 88)
89 89
90b( 90b(
91 one, 91 one,
92 two, 92 two,
93 three 93 three
94) 94)
95 95
96 96
97c(one, two, 97c(one, two,
98 three, four) 98 three, four)
99 99
100-- 100--
101 101
diff --git a/spec/inputs/with.moon b/spec/inputs/with.moon
index f543356..704c494 100644
--- a/spec/inputs/with.moon
+++ b/spec/inputs/with.moon
@@ -1,118 +1,118 @@
1 1
2do 2do
3 a = -> 3 a = ->
4 with something 4 with something
5 print .hello 5 print .hello
6 print hi 6 print hi
7 print "world" 7 print "world"
8 8
9do 9do
10 with leaf 10 with leaf
11 .world! 11 .world!
12 .world 1,2,3 12 .world 1,2,3
13 13
14 g = .what.is.this 14 g = .what.is.this
15 15
16 .hi 1,2,3 16 .hi 1,2,3
17 17
18 \hi(1,2).world 2323 18 \hi(1,2).world 2323
19 19
20 \hi "yeah", "man" 20 \hi "yeah", "man"
21 .world = 200 21 .world = 200
22 22
23do 23do
24 zyzyzy = with something 24 zyzyzy = with something
25 .set_state "hello world" 25 .set_state "hello world"
26 26
27do 27do
28 x = 5 + with Something! 28 x = 5 + with Something!
29 \write "hello world" 29 \write "hello world"
30 30
31 31
32do 32do
33 x = { 33 x = {
34 hello: with yeah 34 hello: with yeah
35 \okay! 35 \okay!
36 } 36 }
37 37
38do 38do
39 with foo 39 with foo
40 _ = \prop"something".hello 40 _ = \prop"something".hello
41 .prop\send(one) 41 .prop\send(one)
42 .prop\send one 42 .prop\send one
43 43
44 44
45-- 45--
46 46
47do 47do
48 with a, b -- b is lost 48 with a, b -- b is lost
49 print .world 49 print .world
50 50
51 mod = with _M = {} 51 mod = with _M = {}
52 .Thing = "hi" 52 .Thing = "hi"
53 53
54 -- operate on a only 54 -- operate on a only
55 with a, b = something, pooh 55 with a, b = something, pooh
56 print .world 56 print .world
57 57
58 x = with a, b = 1, 2 58 x = with a, b = 1, 2
59 print a + b 59 print a + b
60 60
61 print with a, b = 1, 2 61 print with a, b = 1, 2
62 print a + b 62 print a + b
63 63
64 -- assignment lhs must be evaluated in the order they appear 64 -- assignment lhs must be evaluated in the order they appear
65 p = with hello!.x, world!.y = 1, 2 65 p = with hello!.x, world!.y = 1, 2
66 print a + b 66 print a + b
67 67
68-- 68--
69 69
70do 70do
71 x = "hello" 71 x = "hello"
72 with x 72 with x
73 x\upper! 73 x\upper!
74 74
75do 75do
76 with k = "jo" 76 with k = "jo"
77 print \upper! 77 print \upper!
78 78
79do 79do
80 with a,b,c = "", "", "" 80 with a,b,c = "", "", ""
81 print \upper! 81 print \upper!
82 82
83do 83do
84 a = "bunk" 84 a = "bunk"
85 with a,b,c = "", "", "" 85 with a,b,c = "", "", ""
86 print \upper! 86 print \upper!
87 87
88do 88do
89 with j 89 with j
90 print \upper! 90 print \upper!
91 91
92do 92do
93 with k.j = "jo" 93 with k.j = "jo"
94 print \upper! 94 print \upper!
95 95
96do 96do
97 with a 97 with a
98 print .b 98 print .b
99 -- nested `with`s should change the scope correctly 99 -- nested `with`s should change the scope correctly
100 with .c 100 with .c
101 print .d 101 print .d
102 102
103do 103do
104 with a 104 with a
105 -- nested `with`s with assignments should change the scope correctly 105 -- nested `with`s with assignments should change the scope correctly
106 with .b = 2 106 with .b = 2
107 print .c 107 print .c
108 108
109do 109do
110 _ = -> 110 _ = ->
111 with hi 111 with hi
112 return .a, .b 112 return .a, .b
113 113
114 114
115do 115do
116 with dad 116 with dad
117 .if "yes" 117 .if "yes"
118 y = .end.of.function 118 y = .end.of.function
diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h
index f8d2099..e71afe9 100644
--- a/src/MoonP/moon_ast.h
+++ b/src/MoonP/moon_ast.h
@@ -565,8 +565,9 @@ AST_END(ExpListAssign)
565 565
566AST_NODE(if_else_line, "if_else_line"_id) 566AST_NODE(if_else_line, "if_else_line"_id)
567 ast_ptr<true, Exp_t> condition; 567 ast_ptr<true, Exp_t> condition;
568 ast_ptr<false, Assign_t> assign;
568 ast_sel<false, Exp_t, default_value_t> elseExpr; 569 ast_sel<false, Exp_t, default_value_t> elseExpr;
569 AST_MEMBER(if_else_line, &condition, &elseExpr) 570 AST_MEMBER(if_else_line, &condition, &assign, &elseExpr)
570AST_END(if_else_line) 571AST_END(if_else_line)
571 572
572AST_NODE(unless_line, "unless_line"_id) 573AST_NODE(unless_line, "unless_line"_id)
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index b1770fb..4723af4 100644
--- a/src/MoonP/moon_compiler.cpp
+++ b/src/MoonP/moon_compiler.cpp
@@ -601,6 +601,7 @@ private:
601 601
602 auto ifCond = x->new_ptr<IfCond_t>(); 602 auto ifCond = x->new_ptr<IfCond_t>();
603 ifCond->condition.set(if_else_line->condition); 603 ifCond->condition.set(if_else_line->condition);
604 ifCond->assign.set(if_else_line->assign);
604 ifNode->nodes.push_back(ifCond); 605 ifNode->nodes.push_back(ifCond);
605 606
606 auto stmt = x->new_ptr<Statement_t>(); 607 auto stmt = x->new_ptr<Statement_t>();
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp
index d3c0ed2..6d1b86c 100644
--- a/src/MoonP/moon_parser.cpp
+++ b/src/MoonP/moon_parser.cpp
@@ -198,7 +198,7 @@ rule IfCond = Exp >> -Assign;
198rule IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> key("elseif") >> IfCond >> -key("then") >> Body; 198rule IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> key("elseif") >> IfCond >> -key("then") >> Body;
199rule IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> Body; 199rule IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> Body;
200rule If = key("if") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; 200rule If = key("if") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse;
201rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; 201rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse;
202 202
203rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; 203rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body;
204 204
@@ -510,7 +510,7 @@ rule SimpleValue =
510 510
511rule ExpListAssign = ExpList >> -(Update | Assign); 511rule ExpListAssign = ExpList >> -(Update | Assign);
512 512
513rule if_else_line = key("if") >> Exp >> (key("else") >> Exp | default_value); 513rule if_else_line = key("if") >> Exp >> -Assign >> (key("else") >> Exp | default_value);
514rule unless_line = key("unless") >> Exp; 514rule unless_line = key("unless") >> Exp;
515 515
516rule statement_appendix = (if_else_line | unless_line | CompInner) >> Space; 516rule statement_appendix = (if_else_line | unless_line | CompInner) >> Space;