diff options
author | Li Jin <dragon-fly@qq.com> | 2020-01-25 17:48:03 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-01-25 17:48:03 +0800 |
commit | ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8 (patch) | |
tree | 427e365939da39f31dbfa755675fb60bb141583d | |
parent | 4827d200604a086e2ad94edb4257c3abc7a3c4fc (diff) | |
download | yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.gz yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.bz2 yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.zip |
fix Moonscript issue 375.
28 files changed, 867 insertions, 783 deletions
@@ -1,7 +1,7 @@ | |||
1 | # MoonPlus | 1 | # MoonPlus |
2 | 2 | ||
3 |  | 3 |  |
4 | MoonPlus is a compiler adopting features from Moonscript language 0.5.0 and could be 2~4 times faster than the original Moonscript compiler. | 4 | MoonPlus 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 |
17 | c.repeat.if\then("xyz")\else res | 17 | func?! |
18 | |||
19 | x = tab?.value | ||
20 | |||
21 | print abc?["hello world"]?.xyz | ||
22 | |||
23 | if print and x? | ||
24 | print x | ||
18 | ``` | 25 | ``` |
19 |   to: | 26 |   to: |
27 | ```Lua | ||
28 | if func ~= nil then | ||
29 | func() | ||
30 | end | ||
31 | local x | ||
32 | if tab ~= nil then | ||
33 | x = tab.value | ||
34 | end | ||
35 | print((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 | ||
44 | end)()) | ||
45 | if print and (x ~= nil) then | ||
46 | print(x) | ||
47 | end | ||
48 | ``` | ||
49 | |||
50 | * Can do slash call with Lua keywords. Generate codes from: | ||
20 | ```Moonscript | 51 | ```Moonscript |
52 | c.repeat.if\then("xyz")\else res | ||
53 | ``` | ||
54 |   to: | ||
55 | ```Lua | ||
21 | local _call_3 = c["repeat"]["if"] | 56 | local _call_3 = c["repeat"]["if"] |
22 | local _call_4 = _call_3["then"](_call_3, "xyz") | 57 | local _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 | ||
63 | import 'module' | ||
64 | import "module.part" | ||
65 | import "d-a-s-h-e-s" | ||
66 | import "player" as Player | ||
67 | import "lpeg" as {:C, :Ct, :Cmt} | ||
68 | ``` | ||
69 |   to: | ||
70 | ```Lua | ||
71 | local module = require('module') | ||
72 | local part = require("module.part") | ||
73 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
74 | local Player = require("player") | ||
75 | local C, Ct, Cmt | ||
76 | do | ||
77 | local _obj_0 = require("lpeg") | ||
78 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
79 | end | ||
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 |
28 | with leaf | 84 | with leaf |
@@ -36,7 +92,7 @@ for x in *something | |||
36 | print x | 92 | print x |
37 | ``` | 93 | ``` |
38 |   to: | 94 |   to: |
39 | ```lua | 95 | ```Lua |
40 | leaf.world(1, 2, 3) | 96 | leaf.world(1, 2, 3) |
41 | do | 97 | do |
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 | ||
15 | joop = 2345 | 15 | joop = 2345 |
16 | 16 | ||
17 | a, b = if hello | 17 | a, b = if hello |
18 | "hello" | 18 | "hello" |
19 | else | 19 | else |
20 | "nothing", "yeah" | 20 | "nothing", "yeah" |
21 | 21 | ||
22 | 22 | ||
23 | a, b = if hello | 23 | a, b = if hello |
24 | if yeah then "one", "two" else "mmhh" | 24 | if yeah then "one", "two" else "mmhh" |
25 | else | 25 | else |
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 @@ | |||
3 | f = (...) -> #{...} | 3 | f = (...) -> #{...} |
4 | 4 | ||
5 | dont_bubble = -> | 5 | dont_bubble = -> |
6 | [x for x in ((...)-> print ...)("hello")] | 6 | [x for x in ((...)-> print ...)("hello")] |
7 | 7 | ||
8 | k = [x for x in ((...)-> print ...)("hello")] | 8 | k = [x for x in ((...)-> print ...)("hello")] |
9 | 9 | ||
10 | j = for i=1,10 | 10 | j = for i=1,10 |
11 | (...) -> print ... | 11 | (...) -> print ... |
12 | 12 | ||
13 | -- bubble me | 13 | -- bubble me |
14 | 14 | ||
15 | m = (...) -> | 15 | m = (...) -> |
16 | [x for x in *{...} when f(...) > 4] | 16 | [x for x in *{...} when f(...) > 4] |
17 | 17 | ||
18 | x = for i in *{...} do i | 18 | x = for i in *{...} do i |
19 | y = [x for x in *{...}] | 19 | y = [x for x in *{...}] |
@@ -23,6 +23,6 @@ z = [x for x in hallo when f(...) > 4] | |||
23 | a = for i=1,10 do ... | 23 | a = for i=1,10 do ... |
24 | 24 | ||
25 | b = for i=1,10 | 25 | b = 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 | ||
2 | class Hello | 2 | class 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 | ||
9 | x = Hello 1,2 | 9 | x = Hello 1,2 |
10 | x\hello() | 10 | x\hello() |
@@ -12,26 +12,26 @@ x\hello() | |||
12 | print x | 12 | print x |
13 | 13 | ||
14 | class Simple | 14 | class Simple |
15 | cool: => print "cool" | 15 | cool: => print "cool" |
16 | 16 | ||
17 | class Yikes extends Simple | 17 | class Yikes extends Simple |
18 | new: => print "created hello" | 18 | new: => print "created hello" |
19 | 19 | ||
20 | x = Yikes() | 20 | x = Yikes() |
21 | x\cool() | 21 | x\cool() |
22 | 22 | ||
23 | 23 | ||
24 | class Hi | 24 | class 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 | ||
32 | class Simple extends Hi | 32 | class Simple extends Hi |
33 | new: => super "man" | 33 | new: => super "man" |
34 | cool: => super 120302 | 34 | cool: => super 120302 |
35 | 35 | ||
36 | x = Simple() | 36 | x = Simple() |
37 | x\cool() | 37 | x\cool() |
@@ -40,45 +40,45 @@ print x.__class == Simple | |||
40 | 40 | ||
41 | 41 | ||
42 | class Okay | 42 | class 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 | ||
48 | class Biggie extends Okay | 48 | class 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 | ||
55 | class Yeah | 55 | class Yeah |
56 | okay: => | 56 | okay: => |
57 | super\something 1,2,3,4 | 57 | super\something 1,2,3,4 |
58 | 58 | ||
59 | 59 | ||
60 | class What | 60 | class What |
61 | something: => print "val:", @val | 61 | something: => print "val:", @val |
62 | 62 | ||
63 | class Hello extends What | 63 | class Hello extends What |
64 | val: 2323 | 64 | val: 2323 |
65 | something: => super\something | 65 | something: => super\something |
66 | 66 | ||
67 | with Hello! | 67 | with Hello! |
68 | x = \something! | 68 | x = \something! |
69 | print x | 69 | print x |
70 | x! | 70 | x! |
71 | 71 | ||
72 | class CoolSuper | 72 | class 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 |
97 | class ClassMan | 97 | class 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 | ||
105 | x = @ | 105 | x = @ |
@@ -118,34 +118,34 @@ _ = hello[@].world | |||
118 | 118 | ||
119 | 119 | ||
120 | class Whacko | 120 | class 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 | ||
131 | print "hello" | 131 | print "hello" |
132 | 132 | ||
133 | yyy = -> | 133 | yyy = -> |
134 | class Cool | 134 | class Cool |
135 | _ = nil | 135 | _ = nil |
136 | 136 | ||
137 | 137 | ||
138 | -- | 138 | -- |
139 | 139 | ||
140 | class a.b.c.D | 140 | class a.b.c.D |
141 | _ = nil | 141 | _ = nil |
142 | 142 | ||
143 | 143 | ||
144 | class a.b["hello"] | 144 | class a.b["hello"] |
145 | _ = nil | 145 | _ = nil |
146 | 146 | ||
147 | class (-> require "moon")!.Something extends Hello.World | 147 | class (-> 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 | ||
161 | export ^ | 161 | export ^ |
162 | class Something | 162 | class Something |
163 | _ = nil | 163 | _ = nil |
164 | 164 | ||
165 | 165 | ||
166 | -- | 166 | -- |
167 | 167 | ||
168 | -- hoisting | 168 | -- hoisting |
169 | class Something | 169 | class 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 | ||
176 | class X | 176 | class X |
177 | new: hi | 177 | new: hi |
178 | 178 | ||
179 | 179 | ||
180 | -- | 180 | -- |
181 | 181 | ||
182 | class Cool extends Thing | 182 | class 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 | ||
191 | class Whack extends Thing | 191 | class Whack extends Thing |
192 | dang: do_something => | 192 | dang: do_something => |
193 | super! | 193 | super! |
194 | 194 | ||
195 | --- | 195 | --- |
196 | 196 | ||
197 | class Wowha extends Thing | 197 | class 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 | ||
213 | nil | 213 | nil |
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 @@ | |||
2 | you_cool = false | 2 | you_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 |
12 | else | 12 | else |
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 | ||
18 | if cool then wow cool else | 18 | if cool then wow cool else |
19 | noso cool | 19 | noso cool |
20 | 20 | ||
21 | if working | 21 | if 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 | ||
25 | if yeah then no day elseif cool me then okay ya else u way | 25 | if 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 | |||
29 | if (->)() then what ever | 29 | if (->)() then what ever |
30 | 30 | ||
31 | if nil then flip me else | 31 | if nil then flip me else |
32 | it be,rad | 32 | it be,rad |
33 | 33 | ||
34 | 34 | ||
35 | if things great then no way elseif okay sure | 35 | if things great then no way elseif okay sure |
36 | what here | 36 | what here |
37 | 37 | ||
38 | 38 | ||
39 | if things then no chance | 39 | if things then no chance |
40 | elseif okay | 40 | elseif okay |
41 | what now | 41 | what now |
42 | 42 | ||
43 | 43 | ||
44 | if things | 44 | if things |
45 | yes man | 45 | yes man |
46 | elseif okay person then hi there else hmm sure | 46 | elseif okay person then hi there else hmm sure |
47 | 47 | ||
48 | if lets go | 48 | if lets go |
49 | print "greetings" | 49 | print "greetings" |
50 | elseif "just us" | 50 | elseif "just us" |
51 | print "will smith" else show 5555555 | 51 | print "will smith" else show 5555555 |
52 | 52 | ||
53 | -- | 53 | -- |
54 | 54 | ||
55 | if something = 10 | 55 | if something = 10 |
56 | print something | 56 | print something |
57 | else | 57 | else |
58 | print "else" | 58 | print "else" |
59 | 59 | ||
60 | hello = if something = 10 | 60 | hello = if something = 10 |
61 | print something | 61 | print something |
62 | else | 62 | else |
63 | print "else" | 63 | print "else" |
64 | 64 | ||
65 | 65 | ||
66 | hello = 5 + if something = 10 | 66 | hello = 5 + if something = 10 |
67 | print something | 67 | print something |
68 | 68 | ||
69 | --- | 69 | --- |
70 | 70 | ||
71 | z = false | 71 | z = false |
72 | 72 | ||
73 | _ = if false | 73 | _ = if false |
74 | one | 74 | one |
75 | elseif x = true | 75 | elseif x = true |
76 | two | 76 | two |
77 | elseif z = true | 77 | elseif z = true |
78 | three | 78 | three |
79 | else | 79 | else |
80 | four | 80 | four |
81 | 81 | ||
82 | 82 | ||
83 | out = if false | 83 | out = if false |
84 | one | 84 | one |
85 | elseif x = true | 85 | elseif x = true |
86 | two | 86 | two |
87 | elseif z = true | 87 | elseif z = true |
88 | three | 88 | three |
89 | else | 89 | else |
90 | four | 90 | four |
91 | 91 | ||
92 | kzy = -> | 92 | kzy = -> |
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 | ||
100 | unless true | 100 | unless true |
101 | print "cool!" | 101 | print "cool!" |
102 | 102 | ||
103 | unless true and false | 103 | unless true and false |
104 | print "cool!" | 104 | print "cool!" |
105 | 105 | ||
106 | unless false then print "cool!" | 106 | unless false then print "cool!" |
107 | unless false then print "cool!" else print "no way!" | 107 | unless false then print "cool!" else print "no way!" |
108 | 108 | ||
109 | unless nil | 109 | unless nil |
110 | print "hello" | 110 | print "hello" |
111 | else | 111 | else |
112 | print "world" | 112 | print "world" |
113 | 113 | ||
114 | -- | 114 | -- |
115 | 115 | ||
116 | x = unless true | 116 | x = unless true |
117 | print "cool!" | 117 | print "cool!" |
118 | 118 | ||
119 | x = unless true and false | 119 | x = unless true and false |
120 | print "cool!" | 120 | print "cool!" |
121 | 121 | ||
122 | y = unless false then print "cool!" | 122 | y = unless false then print "cool!" |
123 | y = unless false then print "cool!" else print "no way!" | 123 | y = unless false then print "cool!" else print "no way!" |
124 | 124 | ||
125 | z = unless nil | 125 | z = unless nil |
126 | print "hello" | 126 | print "hello" |
127 | else | 127 | else |
128 | print "world" | 128 | print "world" |
129 | 129 | ||
130 | print unless true | 130 | print unless true |
131 | print "cool!" | 131 | print "cool!" |
132 | 132 | ||
133 | print unless true and false | 133 | print unless true and false |
134 | print "cool!" | 134 | print "cool!" |
135 | 135 | ||
136 | print unless false then print "cool!" | 136 | print unless false then print "cool!" |
137 | print unless false then print "cool!" else print "no way!" | 137 | print unless false then print "cool!" else print "no way!" |
138 | 138 | ||
139 | print unless nil | 139 | print unless nil |
140 | print "hello" | 140 | print "hello" |
141 | else | 141 | else |
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 | ||
153 | do | 153 | do |
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 | ||
167 | j = if 1 | 167 | j = if 1 |
168 | if 2 | 168 | if 2 |
169 | 3 | 169 | 3 |
170 | else 6 | 170 | else 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 | ||
183 | else 6 | 183 | else 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 | ||
2 | do | 2 | do |
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 | ||
9 | do | 9 | do |
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 | ||
27 | do | 27 | do |
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 | ||
42 | do | 42 | do |
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 | ||
50 | do | 50 | do |
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 | ||
59 | do | 59 | do |
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 | ||
66 | do | 66 | do |
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 | ||
86 | do | 86 | do |
87 | z = "yeah" | 87 | z = "yeah" |
88 | {a,b,c} = z | 88 | {a,b,c} = z |
89 | 89 | ||
90 | do | 90 | do |
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 | ||
96 | do | 96 | do |
97 | z = "oo" | 97 | z = "oo" |
98 | _ = (k) -> | 98 | _ = (k) -> |
99 | {a,b,c} = z | 99 | {a,b,c} = z |
100 | 100 | ||
101 | do | 101 | do |
102 | {function:{end:endVar}} = thing | 102 | {function:{end:endVar}} = thing |
103 | 103 | ||
104 | do | 104 | do |
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 | ||
2 | do | 2 | do |
3 | print "hello" | 3 | print "hello" |
4 | print "world" | 4 | print "world" |
5 | 5 | ||
6 | x = do | 6 | x = do |
7 | print "hello" | 7 | print "hello" |
8 | print "world" | 8 | print "world" |
9 | 9 | ||
10 | y = do | 10 | y = 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 | ||
16 | t = { | 16 | t = { |
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 | ||
2 | f?! | 2 | f1?! |
3 | |||
4 | f2? "arg0",123 | ||
3 | 5 | ||
4 | x = tab?.value | 6 | x = tab?.value |
5 | 7 | ||
@@ -19,3 +21,21 @@ if {:x} = a?.if?\then?(123)? @?\function 998 | |||
19 | 21 | ||
20 | res = b.function\do!\while?("OK")\if("def",998)\f? | 22 | res = b.function\do!\while?("OK")\if("def",998)\f? |
21 | print res | 23 | print res |
24 | |||
25 | solipsism = true if mind? and not world? | ||
26 | |||
27 | speed = 0 | ||
28 | speed or= 15 | ||
29 | |||
30 | footprints = yeti or "bear" | ||
31 | |||
32 | major = 'Computer Science' | ||
33 | |||
34 | unless major? | ||
35 | signUpForClass 'Introduction to Wines' | ||
36 | |||
37 | if window? | ||
38 | environment = 'browser (probably)' | ||
39 | |||
40 | zip = 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 | ||
2 | do | 2 | do |
3 | export a,b,c = 223, 343 | 3 | export a,b,c = 223, 343 |
4 | export cool = "dad" | 4 | export cool = "dad" |
5 | 5 | ||
6 | do | 6 | do |
7 | export class Something | 7 | export class Something |
8 | umm: "cool" | 8 | umm: "cool" |
9 | 9 | ||
10 | do | 10 | do |
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 | ||
15 | do | 15 | do |
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 | ||
34 | do | 34 | do |
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 | ||
51 | do | 51 | do |
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 | ||
57 | do | 57 | do |
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 | ||
63 | do | 63 | do |
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 | |||
11 | open -> the -> door | 11 | open -> the -> door |
12 | 12 | ||
13 | open -> | 13 | open -> |
14 | the door | 14 | the door |
15 | hello = -> | 15 | hello = -> |
16 | my func | 16 | my func |
17 | 17 | ||
18 | h = -> hi | 18 | h = -> 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 | ||
46 | something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") -> | 46 | something = (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 | ||
64 | d( | 64 | d( |
65 | -> | 65 | -> |
66 | print "hello world" | 66 | print "hello world" |
67 | 10 | 67 | 10 |
68 | ) | 68 | ) |
69 | 69 | ||
70 | 70 | ||
71 | 71 | ||
72 | d( | 72 | d( |
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 | ||
86 | f( | 86 | f( |
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 | ||
98 | x = (a, | 98 | x = (a, |
99 | b) -> | 99 | b) -> |
100 | print "what" | 100 | print "what" |
101 | 101 | ||
102 | 102 | ||
103 | y = (a="hi", | 103 | y = (a="hi", |
104 | b=23) -> | 104 | b=23) -> |
105 | print "what" | 105 | print "what" |
106 | 106 | ||
107 | z = ( | 107 | z = ( |
108 | a="hi", | 108 | a="hi", |
109 | b=23) -> | 109 | b=23) -> |
110 | print "what" | 110 | print "what" |
111 | 111 | ||
112 | 112 | ||
113 | j = (f,g,m, | 113 | j = (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 | ||
120 | y = (a="hi", | 120 | y = (a="hi", |
121 | b=23, | 121 | b=23, |
122 | ...) -> | 122 | ...) -> |
123 | print "what" | 123 | print "what" |
124 | 124 | ||
125 | 125 | ||
126 | y = (a="hi", | 126 | y = (a="hi", |
127 | b=23, | 127 | b=23, |
128 | ... | 128 | ... |
129 | ) -> | 129 | ) -> |
130 | print "what" | 130 | print "what" |
131 | 131 | ||
132 | -- | 132 | -- |
133 | 133 | ||
134 | args = (a | 134 | args = (a |
135 | b) -> | 135 | b) -> |
136 | print "what" | 136 | print "what" |
137 | 137 | ||
138 | 138 | ||
139 | args = (a="hi" | 139 | args = (a="hi" |
140 | b=23) -> | 140 | b=23) -> |
141 | print "what" | 141 | print "what" |
142 | 142 | ||
143 | args = ( | 143 | args = ( |
144 | a="hi" | 144 | a="hi" |
145 | b=23) -> | 145 | b=23) -> |
146 | print "what" | 146 | print "what" |
147 | 147 | ||
148 | 148 | ||
149 | args = (f,g,m | 149 | args = (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 | ||
160 | nil | 160 | nil |
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 | ||
20 | if indent | 20 | if indent |
21 | import okay, \well from tables[100] | 21 | import okay, \well from tables[100] |
22 | 22 | ||
23 | do | 23 | do |
24 | import a, b, c from z | 24 | import a, b, c from z |
25 | 25 | ||
26 | do | 26 | do |
27 | import a, | 27 | import a, |
28 | b, c from z | 28 | b, c from z |
29 | 29 | ||
30 | do | 30 | do |
31 | import a | 31 | import a |
32 | b | 32 | b |
33 | c from z | 33 | c from z |
34 | 34 | ||
35 | do | 35 | do |
36 | import | 36 | import |
37 | a | 37 | a |
38 | b | 38 | b |
39 | c from z | 39 | c from z |
40 | 40 | ||
41 | 41 | ||
42 | do | 42 | do |
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 | ||
50 | do | 50 | do |
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 | ||
56 | do | 56 | do |
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 | ||
60 | do | 60 | do |
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 | ||
66 | do | 66 | do |
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 | ||
8 | rad = [{a} for a in ipairs { | 8 | rad = [{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" | |||
17 | dump = (x) -> print util.dump x | 17 | dump = (x) -> print util.dump x |
18 | 18 | ||
19 | range = (count) -> | 19 | range = (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 | ||
26 | dump [x for x in range 10] | 26 | dump [x for x in range 10] |
27 | dump [{x, y} for x in range 5 when x > 2 for y in range 5] | 27 | dump [{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 | ||
63 | normal = (hello) -> | 63 | normal = (hello) -> |
64 | [x for x in yeah] | 64 | [x for x in yeah] |
65 | 65 | ||
66 | 66 | ||
67 | test = x 1,2,3,4,5 | 67 | test = 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 | ||
2 | do | 2 | do |
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 | ||
9 | do | 9 | do |
10 | x = 1212 | 10 | x = 1212 |
11 | something = -> | 11 | something = -> |
12 | local x | 12 | local x |
13 | x = 1212 | 13 | x = 1212 |
14 | 14 | ||
15 | do | 15 | do |
16 | local * | 16 | local * |
17 | y = 2323 | 17 | y = 2323 |
18 | z = 2323 | 18 | z = 2323 |
19 | 19 | ||
20 | do | 20 | do |
21 | local * | 21 | local * |
22 | print "Nothing Here!" | 22 | print "Nothing Here!" |
23 | 23 | ||
24 | do | 24 | do |
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 | ||
31 | do | 31 | do |
32 | local ^ | 32 | local ^ |
33 | x,y = "a", "b" | 33 | x,y = "a", "b" |
34 | 34 | ||
35 | do | 35 | do |
36 | local * | 36 | local * |
37 | x,y = "a", "b" | 37 | x,y = "a", "b" |
38 | 38 | ||
39 | 39 | ||
40 | do | 40 | do |
41 | local * | 41 | local * |
42 | if something | 42 | if something |
43 | x = 2323 | 43 | x = 2323 |
44 | 44 | ||
45 | do | 45 | do |
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 | ||
55 | do | 55 | do |
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 | ||
64 | do | 64 | do |
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 | ||
78 | do | 78 | do |
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 | ||
89 | do | 89 | do |
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 | ||
94 | g = 2323 -- test if anything leaked | 94 | g = 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 | ||
2 | for x=1,10 | 2 | for x=1,10 |
3 | print "yeah" | 3 | print "yeah" |
4 | 4 | ||
5 | for x=1,#something | 5 | for x=1,#something |
6 | print "yeah" | 6 | print "yeah" |
7 | 7 | ||
8 | for y=100,60,-3 | 8 | for y=100,60,-3 |
9 | print "count down", y | 9 | print "count down", y |
10 | 10 | ||
11 | for a=1,10 do print "okay" | 11 | for a=1,10 do print "okay" |
12 | 12 | ||
13 | for a=1,10 | 13 | for a=1,10 |
14 | for b = 2,43 | 14 | for b = 2,43 |
15 | print a,b | 15 | print a,b |
16 | 16 | ||
17 | for i in iter | 17 | for 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 | ||
22 | for x in *something | 22 | for x in *something |
23 | print x | 23 | print x |
24 | 24 | ||
25 | for k,v in pairs hello do print k,v | 25 | for k,v in pairs hello do print k,v |
26 | 26 | ||
27 | for x in y, z | 27 | for x in y, z |
28 | print x | 28 | print x |
29 | 29 | ||
30 | for x in y, z, k | 30 | for x in y, z, k |
31 | print x | 31 | print x |
32 | 32 | ||
33 | 33 | ||
34 | x = -> | 34 | x = -> |
35 | for x in y | 35 | for x in y |
36 | _ = y | 36 | _ = y |
37 | 37 | ||
38 | hello = {1,2,3,4,5} | 38 | hello = {1,2,3,4,5} |
39 | 39 | ||
40 | x = for y in *hello | 40 | x = for y in *hello |
41 | if y % 2 == 0 | 41 | if y % 2 == 0 |
42 | y | 42 | y |
43 | 43 | ||
44 | x = -> | 44 | x = -> |
45 | for x in *hello | 45 | for x in *hello |
46 | _ = y | 46 | _ = y |
47 | 47 | ||
48 | t = for i=10,20 do i * 2 | 48 | t = for i=10,20 do i * 2 |
49 | 49 | ||
50 | hmm = 0 | 50 | hmm = 0 |
51 | y = for j = 3,30, 8 | 51 | y = 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 | ||
63 | while true do print "name" | 63 | while true do print "name" |
64 | 64 | ||
65 | while 5 + 5 | 65 | while 5 + 5 |
66 | print "okay world" | 66 | print "okay world" |
67 | working man | 67 | working man |
68 | 68 | ||
69 | while also do | 69 | while also do |
70 | i work too | 70 | i work too |
71 | _ = "okay" | 71 | _ = "okay" |
72 | 72 | ||
73 | i = 0 | 73 | i = 0 |
74 | x = while i < 10 | 74 | x = 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 | ||
79 | x = for thing in *3 | 79 | x = for thing in *3 |
80 | y = "hello" | 80 | y = "hello" |
81 | 81 | ||
82 | x = for x=1,2 | 82 | x = for x=1,2 |
83 | y = "hello" | 83 | y = "hello" |
84 | 84 | ||
85 | 85 | ||
86 | -- continue | 86 | -- continue |
87 | 87 | ||
88 | while true | 88 | while 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 | ||
95 | for x=1,10 | 95 | for 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 | ||
100 | list = for x=1,10 | 100 | list = 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 | ||
105 | for a in *{1,2,3,4,5,6} | 105 | for 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 | ||
112 | for x=1,10 | 112 | for 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 | ||
118 | while true | 118 | while true |
119 | continue if false | 119 | continue if false |
120 | break | 120 | break |
121 | 121 | ||
122 | while true | 122 | while true |
123 | continue if false | 123 | continue if false |
124 | return 22 | 124 | return 22 |
125 | 125 | ||
126 | -- | 126 | -- |
127 | 127 | ||
128 | do | 128 | do |
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 @@ | |||
3 | x = 1 + 3 | 3 | x = 1 + 3 |
4 | 4 | ||
5 | y = 1 + | 5 | y = 1 + |
6 | 3 | 6 | 3 |
7 | 7 | ||
8 | z = 1 + | 8 | z = 1 + |
9 | 3 + | 9 | 3 + |
10 | 4 | 10 | 4 |
11 | 11 | ||
12 | -- | 12 | -- |
13 | 13 | ||
14 | k = b and c and | 14 | k = b and c and |
15 | g | 15 | g |
16 | 16 | ||
17 | 17 | ||
18 | h = thing and | 18 | h = 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 |
24 | i = thing or | 24 | i = thing or |
25 | -> | 25 | -> |
26 | print "hello world" | 26 | print "hello world" |
27 | 27 | ||
28 | p = thing and | 28 | p = thing and |
29 | -> | 29 | -> |
30 | print "hello world" | 30 | print "hello world" |
31 | 31 | ||
32 | s = thing or | 32 | s = thing or |
33 | -> and 234 | 33 | -> and 234 |
34 | 34 | ||
35 | 35 | ||
36 | -- | 36 | -- |
37 | u = { | 37 | u = { |
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 | ||
44 | v = { | 44 | v = { |
45 | color: 1 and | 45 | color: 1 and |
46 | -> | 46 | -> |
47 | "yeah" | 47 | "yeah" |
48 | "great" | 48 | "great" |
49 | oksy: 3 ^ | 49 | oksy: 3 ^ |
50 | 2 | 50 | 2 |
51 | } | 51 | } |
52 | 52 | ||
53 | -- parens | 53 | -- parens |
54 | 54 | ||
55 | nno = ( | 55 | nno = ( |
56 | yeah + 2 ) | 56 | yeah + 2 ) |
57 | 57 | ||
58 | nn = ( | 58 | nn = ( |
59 | yeah + 2 | 59 | yeah + 2 |
60 | ) | 60 | ) |
61 | 61 | ||
62 | n = hello( | 62 | n = hello( |
63 | b | 63 | b |
64 | ) -> | 64 | ) -> |
65 | 65 | ||
66 | hello a, | 66 | hello 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 | ||
8 | print @for,@@function 123 | 8 | print @for,@@function 123 |
9 | 9 | ||
10 | if fcolor = message\match "<%w*>" then message = message\gsub "<%->", fcolor | ||
11 | |||
12 | message = message\gsub "<%->", fcolor if fcolor = message\match "<%w*>" | ||
13 | |||
14 | func 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 |
8 | do | 8 | do |
9 | return x for x in *things | 9 | return x for x in *things |
10 | 10 | ||
11 | do | 11 | do |
12 | return [x for x in *things] | 12 | return [x for x in *things] |
13 | 13 | ||
14 | do | 14 | do |
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 | ||
35 | do | 35 | do |
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 |
53 | do a\b | 53 | do 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 | ||
3 | x = { | 3 | x = { |
4 | val: 100 | 4 | val: 100 |
5 | hello: => | 5 | hello: => |
6 | print @val | 6 | print @val |
7 | } | 7 | } |
8 | 8 | ||
9 | fn = x\val | 9 | fn = 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 | ||
2 | switch value | 2 | switch value |
3 | when "cool" | 3 | when "cool" |
4 | print "hello world" | 4 | print "hello world" |
5 | 5 | ||
6 | 6 | ||
7 | switch value | 7 | switch 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 | ||
14 | switch value | 14 | switch 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 | ||
24 | out = switch value | 24 | out = 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 | ||
28 | out = switch value | 28 | out = 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 | ||
33 | with something | 33 | with 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 | ||
40 | fix this | 40 | fix this |
41 | call_func switch something | 41 | call_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 | ||
47 | switch hi | 47 | switch hi |
48 | when hello or world | 48 | when hello or world |
49 | _ = greene | 49 | _ = greene |
50 | 50 | ||
51 | -- | 51 | -- |
52 | 52 | ||
53 | switch hi | 53 | switch 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 | ||
59 | switch hi | 59 | switch 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 | ||
32 | i,x = 200, 300 | 32 | i,x = 200, 300 |
33 | 33 | ||
34 | yeah = (1 + 5) * 3 | 34 | yeah = (1 + 5) * 3 |
35 | yeah = ((1+5)*3)/2 | 35 | yeah = ((1+5)*3)/2 |
@@ -38,16 +38,16 @@ yeah = ((1+5)*3)/2 + i % 100 | |||
38 | whoa = (1+2) * (3+4) * (4+5) | 38 | whoa = (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 |
84 | something = | 84 | something = |
85 | test: 12323 | 85 | test: 12323 |
86 | what: -> print "hello world" | 86 | what: -> print "hello world" |
87 | 87 | ||
88 | print something.test | 88 | print something.test |
89 | 89 | ||
90 | frick = hello: "world" | 90 | frick = hello: "world" |
91 | 91 | ||
92 | argon = | 92 | argon = |
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 | ||
103 | something.what() | 103 | something.what() |
104 | argon\world().something() | 104 | argon\world().something() |
@@ -127,7 +127,7 @@ print "what" if cool else whack! | |||
127 | arg = {...} | 127 | arg = {...} |
128 | 128 | ||
129 | x = (...) -> | 129 | x = (...) -> |
130 | dump {...} | 130 | dump {...} |
131 | 131 | ||
132 | 132 | ||
133 | x = not true | 133 | x = not true |
@@ -167,11 +167,11 @@ _ = (if ntype(v) == "fndef" then x += 1) for v in *values | |||
167 | 167 | ||
168 | 168 | ||
169 | hello = | 169 | hello = |
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 | ||
177 | div class: "cool" | 177 | div class: "cool" |
@@ -185,29 +185,29 @@ what whack - 5 | |||
185 | x = hello - world - something | 185 | x = 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 | ||
191 | if something | 191 | if something |
192 | _ = 03589 | 192 | _ = 03589 |
193 | 193 | ||
194 | -- okay what about this | 194 | -- okay what about this |
195 | 195 | ||
196 | else | 196 | else |
197 | _ = 3434 | 197 | _ = 3434 |
198 | 198 | ||
199 | 199 | ||
200 | if something | 200 | if something |
201 | _ = yeah | 201 | _ = yeah |
202 | 202 | ||
203 | 203 | ||
204 | elseif "ymmm" | 204 | elseif "ymmm" |
205 | 205 | ||
206 | print "cool" | 206 | print "cool" |
207 | 207 | ||
208 | else | 208 | else |
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 | ||
222 | while 10 > something | 222 | while 10 > something |
223 | something: "world" | 223 | something: "world" |
224 | print "yeah" | 224 | print "yeah" |
225 | 225 | ||
226 | x = | 226 | x = |
227 | okay: sure | 227 | okay: sure |
228 | 228 | ||
229 | yeah | 229 | yeah |
230 | okay: man | 230 | okay: man |
231 | sure: sir | 231 | sure: sir |
232 | 232 | ||
233 | hello "no comma" | 233 | hello "no comma" |
234 | yeah: dada | 234 | yeah: dada |
@@ -240,8 +240,8 @@ hello "comma", | |||
240 | 240 | ||
241 | -- creates two tables | 241 | -- creates two tables |
242 | another hello, one, | 242 | another hello, one, |
243 | two, three, four, yeah: man | 243 | two, three, four, yeah: man |
244 | okay: yeah | 244 | okay: yeah |
245 | 245 | ||
246 | -- | 246 | -- |
247 | a += 3 - 5 | 247 | a += 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 | ||
2 | backpack = | 2 | backpack = |
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 | ||
16 | start = | 16 | start = |
17 | something: "cold" | 17 | something: "cold" |
18 | 18 | ||
19 | bathe = | 19 | bathe = |
20 | on: "fire" | 20 | on: "fire" |
21 | 21 | ||
22 | another = | 22 | another = |
23 | [4]: 232 | 23 | [4]: 232 |
24 | ["good food"]: "is the best" | 24 | ["good food"]: "is the best" |
25 | 25 | ||
26 | fwip = | 26 | fwip = |
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 | ||
33 | frick = hello: "world" | 33 | frick = hello: "world" |
@@ -38,106 +38,106 @@ ya = { 1,2,3, key: 100, 343, "hello", umm: 232 } | |||
38 | 38 | ||
39 | 39 | ||
40 | x = { 1,2, | 40 | x = { 1,2, |
41 | 4343, 343 ,343 } | 41 | 4343, 343 ,343 } |
42 | 42 | ||
43 | 43 | ||
44 | g, p = { | 44 | g, 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 | ||
49 | annother = { | 49 | annother = { |
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 | ||
55 | yeah = { | 55 | yeah = { |
56 | [232]: 3434, "helo" | 56 | [232]: 3434, "helo" |
57 | ice: "cake" | 57 | ice: "cake" |
58 | } | 58 | } |
59 | 59 | ||
60 | -- confusing stuff... | 60 | -- confusing stuff... |
61 | whatabout = { | 61 | whatabout = { |
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 | ||
69 | x = | 69 | x = |
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 | ||
84 | x = { :something, something: something } | 84 | x = { :something, something: something } |
85 | 85 | ||
86 | y = { | 86 | y = { |
87 | :hi, :there, :how, :you | 87 | :hi, :there, :how, :you |
88 | :thing | 88 | :thing |
89 | } | 89 | } |
90 | 90 | ||
91 | call_me "hello", :x, :y, :z | 91 | call_me "hello", :x, :y, :z |
92 | 92 | ||
93 | t = { | 93 | t = { |
94 | a: 'a' | 94 | a: 'a' |
95 | [b]: 'b' | 95 | [b]: 'b' |
96 | } | 96 | } |
97 | 97 | ||
98 | xam = { | 98 | xam = { |
99 | hello: 1234 | 99 | hello: 1234 |
100 | "hello": 12354 | 100 | "hello": 12354 |
101 | ["hello"]: 12354 | 101 | ["hello"]: 12354 |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | kam = { | 105 | kam = { |
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 |
127 | keepit going: true, | 127 | keepit going: true, |
128 | okay: "yeah", | 128 | okay: "yeah", |
129 | workd: "okay" | 129 | workd: "okay" |
130 | 130 | ||
131 | thing what: | 131 | thing what: |
132 | "great", no: | 132 | "great", no: |
133 | "more" | 133 | "more" |
134 | okay: 123 | 134 | okay: 123 |
135 | 135 | ||
136 | 136 | ||
137 | -- | 137 | -- |
138 | thing what: | 138 | thing 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 @@ | |||
1 | if a | 1 | if 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" | |||
3 | world = "world" | 3 | world = "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 | ||
43 | hello 1,2,3,4, | 43 | hello 1,2,3,4, |
44 | 1,2,3,4,4,5 | 44 | 1,2,3,4,4,5 |
45 | 45 | ||
46 | x 1, | 46 | x 1, |
47 | 2, 3, | 47 | 2, 3, |
48 | 4, 5, 6 | 48 | 4, 5, 6 |
49 | 49 | ||
50 | 50 | ||
51 | hello 1,2,3, | 51 | hello 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 | ||
55 | hello 1,2,3, | 55 | hello 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 | ||
67 | x = { | 67 | x = { |
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 | ||
73 | if hello 1,2,3, | 73 | if hello 1,2,3, |
74 | world, | 74 | world, |
75 | world | 75 | world |
76 | print "hello" | 76 | print "hello" |
77 | 77 | ||
78 | if hello 1,2,3, | 78 | if 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 | ||
86 | a( | 86 | a( |
87 | one, two, three | 87 | one, two, three |
88 | ) | 88 | ) |
89 | 89 | ||
90 | b( | 90 | b( |
91 | one, | 91 | one, |
92 | two, | 92 | two, |
93 | three | 93 | three |
94 | ) | 94 | ) |
95 | 95 | ||
96 | 96 | ||
97 | c(one, two, | 97 | c(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 | ||
2 | do | 2 | do |
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 | ||
9 | do | 9 | do |
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 | ||
23 | do | 23 | do |
24 | zyzyzy = with something | 24 | zyzyzy = with something |
25 | .set_state "hello world" | 25 | .set_state "hello world" |
26 | 26 | ||
27 | do | 27 | do |
28 | x = 5 + with Something! | 28 | x = 5 + with Something! |
29 | \write "hello world" | 29 | \write "hello world" |
30 | 30 | ||
31 | 31 | ||
32 | do | 32 | do |
33 | x = { | 33 | x = { |
34 | hello: with yeah | 34 | hello: with yeah |
35 | \okay! | 35 | \okay! |
36 | } | 36 | } |
37 | 37 | ||
38 | do | 38 | do |
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 | ||
47 | do | 47 | do |
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 | ||
70 | do | 70 | do |
71 | x = "hello" | 71 | x = "hello" |
72 | with x | 72 | with x |
73 | x\upper! | 73 | x\upper! |
74 | 74 | ||
75 | do | 75 | do |
76 | with k = "jo" | 76 | with k = "jo" |
77 | print \upper! | 77 | print \upper! |
78 | 78 | ||
79 | do | 79 | do |
80 | with a,b,c = "", "", "" | 80 | with a,b,c = "", "", "" |
81 | print \upper! | 81 | print \upper! |
82 | 82 | ||
83 | do | 83 | do |
84 | a = "bunk" | 84 | a = "bunk" |
85 | with a,b,c = "", "", "" | 85 | with a,b,c = "", "", "" |
86 | print \upper! | 86 | print \upper! |
87 | 87 | ||
88 | do | 88 | do |
89 | with j | 89 | with j |
90 | print \upper! | 90 | print \upper! |
91 | 91 | ||
92 | do | 92 | do |
93 | with k.j = "jo" | 93 | with k.j = "jo" |
94 | print \upper! | 94 | print \upper! |
95 | 95 | ||
96 | do | 96 | do |
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 | ||
103 | do | 103 | do |
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 | ||
109 | do | 109 | do |
110 | _ = -> | 110 | _ = -> |
111 | with hi | 111 | with hi |
112 | return .a, .b | 112 | return .a, .b |
113 | 113 | ||
114 | 114 | ||
115 | do | 115 | do |
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 | ||
566 | AST_NODE(if_else_line, "if_else_line"_id) | 566 | AST_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) |
570 | AST_END(if_else_line) | 571 | AST_END(if_else_line) |
571 | 572 | ||
572 | AST_NODE(unless_line, "unless_line"_id) | 573 | AST_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; | |||
198 | rule IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> key("elseif") >> IfCond >> -key("then") >> Body; | 198 | rule IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> key("elseif") >> IfCond >> -key("then") >> Body; |
199 | rule IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> Body; | 199 | rule IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> Body; |
200 | rule If = key("if") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; | 200 | rule If = key("if") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; |
201 | rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; | 201 | rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; |
202 | 202 | ||
203 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; | 203 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; |
204 | 204 | ||
@@ -510,7 +510,7 @@ rule SimpleValue = | |||
510 | 510 | ||
511 | rule ExpListAssign = ExpList >> -(Update | Assign); | 511 | rule ExpListAssign = ExpList >> -(Update | Assign); |
512 | 512 | ||
513 | rule if_else_line = key("if") >> Exp >> (key("else") >> Exp | default_value); | 513 | rule if_else_line = key("if") >> Exp >> -Assign >> (key("else") >> Exp | default_value); |
514 | rule unless_line = key("unless") >> Exp; | 514 | rule unless_line = key("unless") >> Exp; |
515 | 515 | ||
516 | rule statement_appendix = (if_else_line | unless_line | CompInner) >> Space; | 516 | rule statement_appendix = (if_else_line | unless_line | CompInner) >> Space; |