aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--spec/inputs/assign.yue18
-rw-r--r--spec/inputs/backcall.yue4
-rw-r--r--spec/inputs/destructure.yue40
-rw-r--r--spec/inputs/funcs.yue31
-rw-r--r--spec/inputs/global.yue13
-rw-r--r--spec/inputs/import.yue10
-rw-r--r--spec/inputs/lists.yue47
-rw-r--r--spec/inputs/literals.yue9
-rw-r--r--spec/inputs/loops.yue52
-rw-r--r--spec/inputs/macro.yue54
-rw-r--r--spec/inputs/macro_export.yue31
-rw-r--r--spec/inputs/macro_teal.yue13
-rw-r--r--spec/inputs/macro_todo.yue7
-rw-r--r--spec/inputs/props.yue61
-rw-r--r--spec/inputs/string.yue73
-rw-r--r--spec/inputs/switch.yue125
-rw-r--r--spec/inputs/tables.yue18
-rw-r--r--spec/inputs/try_catch.yue122
-rw-r--r--spec/inputs/unicode/destructure.yue2
-rw-r--r--spec/inputs/unicode/macro_export.yue4
-rw-r--r--spec/inputs/unicode/with.yue24
-rw-r--r--spec/inputs/with.yue42
-rw-r--r--spec/outputs/5.1/attrib.lua210
-rw-r--r--spec/outputs/5.1/loops.lua132
-rw-r--r--spec/outputs/5.1/try_catch.lua271
-rw-r--r--spec/outputs/assign.lua37
-rw-r--r--spec/outputs/attrib.lua18
-rw-r--r--spec/outputs/class.lua44
-rw-r--r--spec/outputs/codes_from_doc.lua962
-rw-r--r--spec/outputs/codes_from_doc_zh.lua962
-rw-r--r--spec/outputs/comprehension.lua10
-rw-r--r--spec/outputs/cond.lua14
-rw-r--r--spec/outputs/destructure.lua90
-rw-r--r--spec/outputs/do.lua6
-rw-r--r--spec/outputs/funcs.lua153
-rw-r--r--spec/outputs/global.lua31
-rw-r--r--spec/outputs/import.lua10
-rw-r--r--spec/outputs/lists.lua215
-rw-r--r--spec/outputs/literals.lua8
-rw-r--r--spec/outputs/loops.lua132
-rw-r--r--spec/outputs/macro.lua39
-rw-r--r--spec/outputs/plus.lua3
-rw-r--r--spec/outputs/props.lua240
-rw-r--r--spec/outputs/string.lua41
-rw-r--r--spec/outputs/switch.lua362
-rw-r--r--spec/outputs/syntax.lua8
-rw-r--r--spec/outputs/tables.lua22
-rw-r--r--spec/outputs/try_catch.lua272
-rw-r--r--spec/outputs/unicode/assign.lua12
-rw-r--r--spec/outputs/unicode/attrib.lua18
-rw-r--r--spec/outputs/unicode/comprehension.lua10
-rw-r--r--spec/outputs/unicode/cond.lua16
-rw-r--r--spec/outputs/unicode/do.lua6
-rw-r--r--spec/outputs/unicode/lists.lua23
-rw-r--r--spec/outputs/unicode/loops.lua4
-rw-r--r--spec/outputs/unicode/macro.lua101
-rw-r--r--spec/outputs/unicode/multiline_chain.lua6
-rw-r--r--spec/outputs/unicode/plus.lua3
-rw-r--r--spec/outputs/unicode/syntax.lua14
-rw-r--r--spec/outputs/unicode/try_catch.lua10
-rw-r--r--spec/outputs/unicode/vararg.lua28
-rw-r--r--spec/outputs/unicode/with.lua20
-rw-r--r--spec/outputs/upvalue_func.lua48
-rw-r--r--spec/outputs/vararg.lua28
-rw-r--r--spec/outputs/with.lua82
65 files changed, 5057 insertions, 464 deletions
diff --git a/spec/inputs/assign.yue b/spec/inputs/assign.yue
index 514aeed..ad1eda3 100644
--- a/spec/inputs/assign.yue
+++ b/spec/inputs/assign.yue
@@ -109,4 +109,22 @@ do
109 val = 123 109 val = 123
110 a = b = c = val 110 a = b = c = val
111 111
112do
113 -- update
114 a ..= "abc"
115 a //= 2
116 a or= def
117 a and= false
118 a >>= 10
119 a <<= 10
120 a.b.c ??= 123
121 a.b.c += 1
122 a.b.c -= 2
123 a.b.c *= 3
124 a.b.c /= 4
125 a.b.c %= 5
126 a &= 6
127 a |= 7
128 a ^= 8
129
112nil 130nil
diff --git a/spec/inputs/backcall.yue b/spec/inputs/backcall.yue
index 8aadc71..e6b8c21 100644
--- a/spec/inputs/backcall.yue
+++ b/spec/inputs/backcall.yue
@@ -13,9 +13,9 @@ do
13 x > 2 13 x > 2
14 14
15do 15do
16 (data) <- http?.get "ajaxtest" 16 data <- http?.get "ajaxtest"
17 body[".result"]\html data 17 body[".result"]\html data
18 (processed) <- http.post "ajaxprocess", data 18 processed <- http.post "ajaxprocess", data
19 body[".result"]\append processed 19 body[".result"]\append processed
20 <- setTimeout 1000 20 <- setTimeout 1000
21 print "done" 21 print "done"
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue
index 674dfe4..b6250d0 100644
--- a/spec/inputs/destructure.yue
+++ b/spec/inputs/destructure.yue
@@ -94,7 +94,7 @@ do
94-- 94--
95 95
96do 96do
97 with {a,b} = thing 97 with {a,b} := thing
98 print a, b 98 print a, b
99 99
100 100
@@ -240,5 +240,43 @@ do
240 switch tb 240 switch tb
241 when {c: {<"abc">: meta_field = "def"}, <[[any string]]>: {d: abc = 123}, <'str'>: {e: def = {}}} 241 when {c: {<"abc">: meta_field = "def"}, <[[any string]]>: {d: abc = 123}, <'str'>: {e: def = {}}}
242 print meta_field, abc, def 242 print meta_field, abc, def
243
244do
245 clients = ["VIP_Alice", "User_Bob", "User_Clara", "VIP_Eva"]
246 [vipStart, ...regulars, vipEnd] = clients
247 print vipStart -- "VIP_Alice"
248 print regulars -- {"User_Bob", "User_Clara"}
249 print vipEnd -- "VIP_Eva"
250
251do
252 setupMeeting = (participants) ->
253 [chair, ..._, secretary] = participants
254 print chair, secretary
255
256 setupMeeting ["Alice", "Bob", "Charlie", "David"]
257 -- Output: Alice David
258
259do
260 getTransactions = ->
261 {
262 {id: "T1", amount: 100}
263 {id: "T2", amount: 200}
264 {id: "T3", amount: 300}
265 }
266
267 :id, :amount = getTransactions![#]
268 assert id == "T3"
269 assert amount == 300
270
271do
272 [
273 _
274 ...middle
275 _
276 ] = tb
277
278do
279 {a, :abc, b, :def, ...sub, d, e} = tb
280
243nil 281nil
244 282
diff --git a/spec/inputs/funcs.yue b/spec/inputs/funcs.yue
index e647edc..6b1669b 100644
--- a/spec/inputs/funcs.yue
+++ b/spec/inputs/funcs.yue
@@ -193,4 +193,35 @@ do
193 func = (): -> check 123 193 func = (): -> check 123
194 print func! -- get nil 194 print func! -- get nil
195 195
196do
197 f = ({:a, :b, :c}) -> print a, b, c
198 f = (:a, :b, :c) -> print a, b, c
199 g = (x, :y) -> print x, y
200 i = ({a: ax = 0, b: by = 0}) -> print ax, by
201 j = (name, {id: uid = "n/a", :role = "guest"}) -> print name, uid, role
202 m = ({user: {:name, :age}, meta: {:ver = 1}}) -> print name, age, ver
203 m1 = ({user: {:name, :age}, :meta = {}}) -> print name, age, meta and meta.ver or "nil"
204 new = ({:name = "anon", :age = 0}) =>
205 @name = name
206 @age = age
207 set = ({:name = @name, :age = @age}) =>
208 @name = name
209 @age = age
210 logKV = ({:k, :v}, ...) ->
211 print "kv:", k, v
212 print "rest count:", select "#", ...
213 macro gen = (fname) -> |
214 #{fname} = ({:a, :b = 0}) -> print a, b
215 $gen foo
216 t1 = (:a, x) -> print a, x
217 t2 = (:a) -> print a
218 w = (
219 id
220 {:x = 0, :y = 0}
221 :flag
222 ) ->
223 print id, x, y, flag
224 g1 = ({:a, a: ax}) -> print a, ax
225 g4 = ({:a, :b, ...rest}) -> print a, b
226
196nil 227nil
diff --git a/spec/inputs/global.yue b/spec/inputs/global.yue
index 59cf764..4e3b8aa 100644
--- a/spec/inputs/global.yue
+++ b/spec/inputs/global.yue
@@ -75,3 +75,16 @@ do
75 75
76 h = 100 76 h = 100
77 77
78do
79 global x = y
80 global ^
81 foobar = "all lowercase"
82 FooBar = "pascal case"
83 FOOBAR = "all uppercase"
84
85do
86 global const class A
87 global const Flag = 1
88 global const const, x, y = "const", 1, 2
89 global const math, table
90
diff --git a/spec/inputs/import.yue b/spec/inputs/import.yue
index b8ffc24..8982e6c 100644
--- a/spec/inputs/import.yue
+++ b/spec/inputs/import.yue
@@ -139,3 +139,13 @@ do
139 import "m" as {c: d} 139 import "m" as {c: d}
140 import "m" as {g, {<close>: i}} 140 import "m" as {g, {<close>: i}}
141 141
142do
143 import require
144 import string as stringlib
145 import string.format
146 import io.read as io_read
147
148 type = ->
149 import type as tp
150 import 月 as yue
151
diff --git a/spec/inputs/lists.yue b/spec/inputs/lists.yue
index 921cae0..c493b68 100644
--- a/spec/inputs/lists.yue
+++ b/spec/inputs/lists.yue
@@ -87,4 +87,51 @@ do
87 [a, b] = hello 87 [a, b] = hello
88 [name = "nameless", job = "jobless"] = person 88 [name = "nameless", job = "jobless"] = person
89 89
90do
91 transactions = ["T001", "T002", "T003", "T004", "T005"]
92 middleTransactions = transactions[2, -2]
93 print middleTransactions -- => {"T002", "T003", "T004"}
94
95do
96 logs =
97 - start: 0, end: 100
98 - start: 100, end: 200
99 - start: 200, end: 123
100 print logs[#].end -- => 123
101
102do
103 pendingOrders = ["O001", "O002", "O003", "O004"]
104 print pendingOrders[# - 1] -- => "O003"
105
106do
107 getOrders = ->
108 {
109 { id: "O1001", status: "pending" }
110 { id: "O1002", status: "processing" }
111 { id: "O1003", status: "done" }
112 }
113
114 lastStatus = getOrders()[#].status
115 assert lastStatus == "done"
116
117do
118 cloneList1 = (list) -> list[,]
119 cloneList2 = (list) -> [...list,]
120 cloneTable = (tb) -> {...tb}
121
122do
123 print(
124 globalTB[#]
125 a.b.c[# - 2]
126 x?\y?!.z?[# - 3]
127 )
128
129do
130 f = ->
131 print(
132 globalTB[#]\end 123
133 a.b.c[5,-5][# - 2]
134 x?\y?!.z?[# - 3]?[, -3]
135 )
136
90nil 137nil
diff --git a/spec/inputs/literals.yue b/spec/inputs/literals.yue
index 6b666f0..32cf7e7 100644
--- a/spec/inputs/literals.yue
+++ b/spec/inputs/literals.yue
@@ -10,10 +10,19 @@ _ = {
10 0xfF2323 10 0xfF2323
11 0xabcdef 11 0xabcdef
12 0xABCDEF 12 0xABCDEF
13 0XFB_C4_00
13 0x123p-123 14 0x123p-123
14 0xABCP+321 15 0xABCP+321
15 0x.1p-111 16 0x.1p-111
16 0xA_B_CP-3_2_1 17 0xA_B_CP-3_2_1
18 0x0.1E
19 0xA23p-4
20 0X1.921FB54442D18P+1
21
22 0b01
23 0b00_00_10_00
24 0B1111
25 0B00_11_00_10_01
17 26
18 .2323 27 .2323
19 .2323e-1 28 .2323e-1
diff --git a/spec/inputs/loops.yue b/spec/inputs/loops.yue
index c5b28b3..5df10ca 100644
--- a/spec/inputs/loops.yue
+++ b/spec/inputs/loops.yue
@@ -213,3 +213,55 @@ do
213do 213do
214 until x := func 'a', b do 214 until x := func 'a', b do
215 print "false expected" 215 print "false expected"
216
217do
218 index = for i = 1, #tb
219 break i if tb[i]
220
221 f for i = 1, #tb
222 break i if tb[i]
223
224 f for i = 1, #tb
225 i if tb[i]
226
227 i = 1
228 ids = while tb[i]
229 i += 1
230 i - 1
231
232 i = 1
233 idx = while tb[i]
234 i += 1
235 break i - 1
236
237 f1 = ->
238 i = 1
239 f while tb[i]
240 i += 1
241 i - 1
242
243 i = 1
244 f while tb[i]
245 i += 1
246 break i - 1
247
248 list = for item in *items
249 switch item
250 when type: "A", :value
251 if value > 5
252 item
253
254do
255 repeat print 1 until true
256
257 x = repeat
258 a = func!
259 break a.x
260 until a.v
261
262 items = repeat
263 item = getItem!
264 break unless item
265 item if item.value > 0
266 until false
267
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue
index 5d5f1a9..191f09f 100644
--- a/spec/inputs/macro.yue
+++ b/spec/inputs/macro.yue
@@ -60,6 +60,11 @@ macro NumAndStr = (num, str) ->
60 60
61print $NumAndStr 123, 'xyz' 61print $NumAndStr 123, 'xyz'
62 62
63macro NumAndStr2 = (num`Num, str`SingleString) -> |
64 [#{num}, #{str}]
65
66print $NumAndStr2 456, 'abc'
67
63$asserts item == nil 68$asserts item == nil
64 69
65$myconfig false 70$myconfig false
@@ -100,13 +105,14 @@ macro filter = (items, action)->
100 $showMacro "filter", "[_ for _ in *#{items} when #{action}]" 105 $showMacro "filter", "[_ for _ in *#{items} when #{action}]"
101 106
102macro reduce = (items, def, action)-> 107macro reduce = (items, def, action)->
103 $showMacro "reduce", "if ##{items} == 0 108 $showMacro "reduce", |
104 #{def} 109 if ##{items} == 0
105else 110 #{def}
106 _1 = #{def} 111 else
107 for _2 in *#{items} 112 _1 = #{def}
108 _1 = #{action} 113 for _2 in *#{items}
109 _1" 114 _1 = #{action}
115 _1
110 116
111macro foreach = (items, action)-> 117macro foreach = (items, action)->
112 $showMacro "foreach", "for _ in *#{items} 118 $showMacro "foreach", "for _ in *#{items}
@@ -154,13 +160,15 @@ macro curry = (...)->
154f = $curry x,y,z,do 160f = $curry x,y,z,do
155 print x,y,z 161 print x,y,z
156 162
157macro get_inner = (var)-> "do 163macro get_inner = (var)-> |
158 a = 1 164 do
159 a + 1" 165 a = 1
166 a + 1
160 167
161macro get_inner_hygienic = (var)-> "(-> 168macro get_inner_hygienic = (var)-> |
162 local a = 1 169 (->
163 a + 1)!" 170 local a = 1
171 a + 1)!
164 172
165do 173do
166 a = 8 174 a = 8
@@ -196,6 +204,18 @@ end
196 204
197print x 205print x
198 206
207import "yue"
208macro lua = (code`YAMLMultiline) -> {
209 code: yue.loadstring(code)!
210 type: "lua"
211}
212
213$lua |
214 local function f2(a)
215 return a + 1
216 end
217 x = x + f2(3)
218
199macro def = (fname, ...)-> 219macro def = (fname, ...)->
200 args = {...} 220 args = {...}
201 last = table.remove args 221 last = table.remove args
@@ -317,7 +337,13 @@ $chainC(
317 Destroy! 337 Destroy!
318) 338)
319 339
320macro tb = -> "{'abc', a:123, <call>:=> 998}" 340macro tb = -> |
341 {
342 'abc'
343 a: 123
344 <call>: => 998
345 }
346
321print $tb[1], $tb.a, ($tb)!, $tb! 347print $tb[1], $tb.a, ($tb)!, $tb!
322 348
323print "current line: #{ $LINE }" 349print "current line: #{ $LINE }"
diff --git a/spec/inputs/macro_export.yue b/spec/inputs/macro_export.yue
index cc7d459..22905b5 100644
--- a/spec/inputs/macro_export.yue
+++ b/spec/inputs/macro_export.yue
@@ -8,13 +8,12 @@ export macro config = (debugging = true)->
8 "" 8 ""
9 9
10export macro showMacro = (name, res)-> 10export macro showMacro = (name, res)->
11 if debugMacro then " 11 if debugMacro then |
12do 12 do
13 txt = #{res} 13 txt = #{res}
14 print '[macro ' .. #{name} .. ']' 14 print '[macro #{name}]'
15 print txt 15 print txt
16 txt 16 txt
17"
18 else 17 else
19 res 18 res
20 19
@@ -35,14 +34,16 @@ export macro copy = (src, dst, ...)->
35 src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_" 34 src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_"
36 "copy targets can not be _src_ or _dst_" 35 "copy targets can not be _src_ or _dst_"
37 ) 36 )
38 " 37 copyFields = table.concat(
39do 38 ["_dst_.#{field} = _src_.#{field}" for field in *{...}]
40 local _src_, _dst_ 39 "\n\t\t\t"
41 with _dst_ = #{dst} 40 )
42 with _src_ = #{src} 41 |
43#{table.concat for field in *{...} do " 42 do
44 _dst_.#{field} = _src_.#{field} 43 local _src_, _dst_
45"}" 44 with _dst_ := #{dst}
45 with _src_ := #{src}
46 #{copyFields}
46 47
47export macro enum = (...) -> 48export macro enum = (...) ->
48 items = {...} 49 items = {...}
diff --git a/spec/inputs/macro_teal.yue b/spec/inputs/macro_teal.yue
index 0cfd862..e51bcd7 100644
--- a/spec/inputs/macro_teal.yue
+++ b/spec/inputs/macro_teal.yue
@@ -4,11 +4,16 @@ $ ->
4 options.target_extension = "tl" 4 options.target_extension = "tl"
5 package.path ..= ";./spec/lib/?.lua" 5 package.path ..= ";./spec/lib/?.lua"
6 6
7macro to_lua = (code)-> 7macro to_lua = (code)-> |
8 "require('yue').to_lua(#{code}, reserve_line_number:false, same_module:true)" 8 require('yue').to_lua #{code},
9 reserve_line_number: false
10 same_module: true
9 11
10macro trim = (name)-> 12macro trim = (name)-> |
11 "if result := #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" 13 if result := #{name}\match '[\'"](.*)[\'"]'
14 result
15 else
16 #{name}
12 17
13export macro local = (decl, value = nil)-> 18export macro local = (decl, value = nil)->
14 import "yue" as {options:{:tl_enabled}} 19 import "yue" as {options:{:tl_enabled}}
diff --git a/spec/inputs/macro_todo.yue b/spec/inputs/macro_todo.yue
index 752c9cb..c9c8f77 100644
--- a/spec/inputs/macro_todo.yue
+++ b/spec/inputs/macro_todo.yue
@@ -5,9 +5,6 @@ export macro todoInner = (module, line, msg)->
5 type: "lua" 5 type: "lua"
6 } 6 }
7 7
8export macro todo = (msg)-> 8export macro todo = (msg)-> |
9 if msg 9 $todoInner $FILE, $LINE#{msg and ", #{msg}" or ""}
10 "$todoInner $FILE, $LINE, #{msg}"
11 else
12 "$todoInner $FILE, $LINE"
13 10
diff --git a/spec/inputs/props.yue b/spec/inputs/props.yue
new file mode 100644
index 0000000..bbb7aae
--- /dev/null
+++ b/spec/inputs/props.yue
@@ -0,0 +1,61 @@
1class Props
2 __index: (name): nil =>
3 cls = @.<>
4 if item := cls.__getter?[name] -- access properties
5 return item @
6 elseif item := rawget cls, name -- access member functions
7 return item
8 else
9 c = cls
10 while c := c.<> -- recursive to access base classes
11 if item := c.__getter?[name]
12 cls.__getter ??= {}
13 cls.__getter[name] = item -- cache base properties to class
14 return item @
15 elseif item := rawget c, name
16 rawset cls, name, item -- cache base member to class
17 return item
18
19 __newindex: (name, value) =>
20 cls = @.<>
21 if item := cls.__setter?[name] -- access properties
22 item @, value
23 else
24 c = cls
25 while c := c.<> -- recursive to access base classes
26 if item := c.__setter?[name]
27 cls.__setter ??= {}
28 cls.__setter[name] = item -- cache base property to class
29 item @, value
30 return
31 rawset @, name, value -- assign field to self
32
33 assignReadOnly = -> error "assigning a readonly property"
34
35 prop: (name, props) =>
36 {
37 :get
38 :set = assignReadOnly
39 } = props
40 if getter := rawget @__base, "__getter"
41 getter[name] = get
42 else
43 rawset @__base, "__getter", [name]: get
44 if setter := rawget @__base, "__setter"
45 setter[name] = set
46 else
47 rawset @__base, "__setter", [name]: set
48
49class A extends Props
50 @prop 'x'
51 get: => @_x + 1000
52 set: (v) => @_x = v
53 new: =>
54 @_x = 0
55
56class B extends A
57 @prop 'abc', get: => "hello"
58
59b = B!
60b.x = 999
61print b.x, b.abc
diff --git a/spec/inputs/string.yue b/spec/inputs/string.yue
index f91383e..1f0fba8 100644
--- a/spec/inputs/string.yue
+++ b/spec/inputs/string.yue
@@ -74,3 +74,76 @@ _ = "hello"
74something"hello"\world! 74something"hello"\world!
75something "hello"\world! 75something "hello"\world!
76 76
77do
78 str = |
79 key: value
80 str = |
81 config:
82 enabled: true
83 level: 5
84 str = |
85 header: start
86
87 footer: end
88 str = |
89 name: #{username}
90 str = |
91 count: #{total} items
92 str = |
93 user: #{name}
94 id: #{id}
95 str = |
96 path: "C:\\Program Files\\App"
97 desc: 'single "quote" test'
98 str = |
99 key: value
100 next: 123
101 str = |
102 list:
103 - "one"
104 - "two"
105 str = |
106 -- comment
107 content text
108 -- comment
109 str = |
110 #{1 + 2}
111 #{2 + 3}
112 #{"a" .. "b"}
113 obj =
114 settings: |
115 mode: #{mode}
116 flags:
117 - #{flag1}
118 - default
119 fn = -> |
120 Hello
121 name: #{userName}
122 str = |
123 result:
124 status: #{if ok then "pass" else "fail"}
125 code: #{code}
126 summary = |
127 date: #{os.date()}
128 values:
129 -
130 a: #{aVal}
131 b: #{bVal or defaultB}
132 msg = send |
133 Hello, #{user}!
134 Today is #{os.date("%A")}.
135 desc = do
136 prefix = "Result"
137 |
138 #{prefix}:
139 value: #{compute!}
140 (|
141 1
142 2
143 3
144 ) |> print
145
146export yaml = |
147 version: #{ver}
148 ok: true
149
diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue
index 49d47f3..2b0669c 100644
--- a/spec/inputs/switch.yue
+++ b/spec/inputs/switch.yue
@@ -165,5 +165,128 @@ do
165 print item 165 print item
166 when [a = 1, b = "abc"] 166 when [a = 1, b = "abc"]
167 print a, b 167 print a, b
168nil
169 168
169do
170 switch tb
171 when [1, 2, 3]
172 print "1, 2, 3"
173 when [1, b, 3]
174 print "1, #{b}, 3"
175 when [1, 2, b = 3]
176 print "1, 2, #{b}"
177
178do
179 switch tb
180 when success: true, :result
181 print "success", result
182 when success: false
183 print "failed", result
184 else
185 print "invalid"
186
187do
188 switch tb
189 when {type: "success", :content}
190 print "success", content
191 when {type: "error", :content}
192 print "failed", content
193 else
194 print "invalid"
195
196do
197 switch tb
198 when [
199 {a: 1, b: 2}
200 {a: 3, b: 4}
201 {a: 5, b: 6}
202 fourth
203 ]
204 print "matched", fourth
205
206 switch tb
207 when [
208 {c: 1, d: 2}
209 {c: 3, d: 4}
210 {c: 5, d: 6}
211 ]
212 print "OK"
213 when [
214 _
215 _
216 {a: 1, b: 2}
217 {a: 3, b: 4}
218 {a: 5, b: 6}
219 sixth
220 ]
221 print "matched", sixth
222
223do
224 switch v := "hello"
225 when "hello"
226 print "matched hello"
227 else
228 print "not matched"
229 -- output: matched hello
230
231do
232 f = -> "ok"
233 switch val := f!
234 when "ok"
235 print "it's ok"
236 -- output: it's ok
237
238
239do
240 g = -> 42
241 switch result := g!
242 when 1, 2
243 print "small"
244 when 42
245 print "life universe everything"
246 else
247 print "other #{result}"
248 -- output: life universe everything
249
250do
251 check = ->
252 if true
253 "yes"
254 else
255 "no"
256
257 switch x := check!
258 when "yes"
259 print "affirmative"
260 else
261 print "negative"
262 -- output: affirmative
263
264do
265 t = (): tb ->
266 tb = {a: 1}
267 tb.a = 2
268
269 switch data := t!
270 when {a: 2}
271 print "matched"
272 else
273 print "not matched"
274
275do
276 clientData = ["Meta", "CUST_1001", "CHK123"]
277 switch clientData
278 when [...metadata, customerId, checksum]
279 print metadata -- {"Meta"}
280 print customerId -- "CUST_1001"
281 print checksum -- "CHK123"
282
283do
284 handlePath = (segments) ->
285 switch segments
286 when [..._, resource, action]
287 print "Resource:", resource
288 print "Action:", action
289
290 handlePath ["admin", "logs", "view"]
291
292nil
diff --git a/spec/inputs/tables.yue b/spec/inputs/tables.yue
index 0de8a8c..702e04a 100644
--- a/spec/inputs/tables.yue
+++ b/spec/inputs/tables.yue
@@ -245,6 +245,24 @@ menus =
245 click: -> 245 click: ->
246 } 246 }
247 247
248_ =
249 boolean:
250 - true
251 - false
252 float:
253 - 3.14
254 - -6.8523015e+5
255 int:
256 - 123
257 - -0b1010_0111_0100_1010_1110
258 null:
259 nodeName: 'node'
260 parent: nil
261 string:
262 - 'Hello world'
263 - "newline
264newline2"
265
248tb = {...other} 266tb = {...other}
249 267
250tbMix = { 268tbMix = {
diff --git a/spec/inputs/try_catch.yue b/spec/inputs/try_catch.yue
index 4e05bc6..6c29a52 100644
--- a/spec/inputs/try_catch.yue
+++ b/spec/inputs/try_catch.yue
@@ -62,6 +62,126 @@ f = ->
62 do 62 do
63 <- x 63 <- x
64 local tb, a, b, c 64 local tb, a, b, c
65 f = -> try tb.f a, b, c 65 f1 = -> try tb.f a, b, c
66
67 do
68 f1 = -> do
69 ok, ... = try func!
70 ...
71
72 do
73 local func
74 a, b, c = try? func!
75
76 do
77 a, b, c = try? func!
78
79 do
80 a = (try? func!) ?? "default"
81
82 do
83 f try? func!
84
85 do
86 f try?
87 print 123
88 func!
89 catch e
90 print e
91 e
66 92
67 nil 93 nil
94
95do
96 try
97 func 1, 2, 3
98 catch err
99 print err
100
101 try func 1, 2, 3
102 catch err
103 print err
104
105 try
106 print "trying"
107 func 1, 2, 3
108
109 do
110 success, result = try
111 func 1, 2, 3
112 catch err
113 print err
114
115 success, result = try func 1, 2, 3
116
117 tb = {}
118
119 try tb.func
120 try tb.func!
121 try tb.func()
122 try (tb.func!)
123 try (tb\func(1, 2, 3))
124
125 try tb.func 1
126 try tb.func(1)
127
128 if (try func 1
129 catch err
130 print err)
131 print "OK"
132
133 if try (func 1)
134 catch err
135 print err
136 print "OK"
137
138 do
139 if success, result := try func "abc", 123
140 print result
141
142 success, result = try func "abc", 123
143 catch err
144 print err
145
146 print result if success, result := try func "abc", 123
147 catch err
148 print err
149
150 do
151 try
152 func 1, 2, 3
153
154 try func 1, 2, 3
155
156 do
157 <- x
158 local tb, a, b, c
159 f1 = -> try tb.f a, b, c
160
161 do
162 f1 = -> do
163 ok, ... = try func!
164 ...
165
166 do
167 local func
168 a, b, c = try? func!
169
170 do
171 a, b, c = try? func!
172
173 do
174 a = (try? func!) ?? "default"
175
176 do
177 f try? func!
178
179 do
180 f try?
181 print 123
182 func!
183 catch e
184 print e
185 e
186
187nil
diff --git a/spec/inputs/unicode/destructure.yue b/spec/inputs/unicode/destructure.yue
index 3c3a369..a5ffd5d 100644
--- a/spec/inputs/unicode/destructure.yue
+++ b/spec/inputs/unicode/destructure.yue
@@ -84,7 +84,7 @@ do
84-- 84--
85 85
86do 86do
87 with {元素a,元素b} = 东西 87 with {元素a,元素b} := 东西
88 打印 元素a, 元素b 88 打印 元素a, 元素b
89 89
90 90
diff --git a/spec/inputs/unicode/macro_export.yue b/spec/inputs/unicode/macro_export.yue
index 3c9a942..56571cd 100644
--- a/spec/inputs/unicode/macro_export.yue
+++ b/spec/inputs/unicode/macro_export.yue
@@ -37,8 +37,8 @@ export macro 复制 = (源, 目标, ...)->
37 " 37 "
38do 38do
39 local _源_, _目标_ 39 local _源_, _目标_
40 with _目标_ = #{目标} 40 with _目标_ := #{目标}
41 with _源_ = #{源} 41 with _源_ := #{源}
42#{table.concat for 字段 in *{...} do " 42#{table.concat for 字段 in *{...} do "
43 _目标_.#{字段} = _源_.#{字段} 43 _目标_.#{字段} = _源_.#{字段}
44"}" 44"}"
diff --git a/spec/inputs/unicode/with.yue b/spec/inputs/unicode/with.yue
index ecbfdab..3c15add 100644
--- a/spec/inputs/unicode/with.yue
+++ b/spec/inputs/unicode/with.yue
@@ -45,19 +45,19 @@ do
45 with 变量a 45 with 变量a
46 打印 .世界 46 打印 .世界
47 47
48 模块 = with _模块 = {} 48 模块 = with _模块 := {}
49 .事物 = "你好" 49 .事物 = "你好"
50 50
51 with 变量a, 变量b = 东西, 布 51 with 变量a, 变量b := 东西, 布
52 打印 .世界 52 打印 .世界
53 53
54 变量x = with 变量a, 变量b = 1, 2 54 变量x = with 变量a, 变量b := 1, 2
55 打印 变量a + 变量b 55 打印 变量a + 变量b
56 56
57 打印 with 变量a, 变量b = 1, 2 57 打印 with 变量a, 变量b := 1, 2
58 打印 变量a + 变量b 58 打印 变量a + 变量b
59 59
60 p = with 你好!.字段x, 世界!.字段y = 1, 2 60 p = with 你好!.字段x, 世界!.字段y := 1, 2
61 打印 变量a + 变量b 61 打印 变量a + 变量b
62 62
63-- 63--
@@ -68,16 +68,16 @@ do
68 变量x\大写! 68 变量x\大写!
69 69
70do 70do
71 with 变量k = "乔" 71 with 变量k := "乔"
72 打印 \大写! 72 打印 \大写!
73 73
74do 74do
75 with 变量a,变量b,变量c = "", "", "" 75 with 变量a,变量b,变量c := "", "", ""
76 打印 \大写! 76 打印 \大写!
77 77
78do 78do
79 变量a = "床铺" 79 变量a = "床铺"
80 with 变量a,变量b,变量c = "", "", "" 80 with 变量a,变量b,变量c := "", "", ""
81 打印 \大写! 81 打印 \大写!
82 82
83do 83do
@@ -85,7 +85,7 @@ do
85 打印 \大写! 85 打印 \大写!
86 86
87do 87do
88 with 变量k.变量j = "乔" 88 with 变量k.变量j := "乔"
89 打印 \大写! 89 打印 \大写!
90 90
91do 91do
@@ -96,7 +96,7 @@ do
96 96
97do 97do
98 with 变量a 98 with 变量a
99 with .b = 2 99 with .b := 2
100 打印 .c 100 打印 .c
101 101
102do 102do
@@ -131,12 +131,12 @@ do
131 131
132do 132do
133 global 掩码 133 global 掩码
134 with? 掩码 = 实心矩形 宽: w, 高: h, 颜色: 0x66000000 134 with? 掩码 := 实心矩形 宽: w, 高: h, 颜色: 0x66000000
135 .触摸启用 = true 135 .触摸启用 = true
136 .吞噬触摸 = true 136 .吞噬触摸 = true
137 137
138do 138do
139 with? 掩码 = 实心矩形 宽: w, 高: h, 颜色: 0x66000000 139 with? 掩码 := 实心矩形 宽: w, 高: h, 颜色: 0x66000000
140 .触摸启用 = true 140 .触摸启用 = true
141 .吞噬触摸 = true 141 .吞噬触摸 = true
142 142
diff --git a/spec/inputs/with.yue b/spec/inputs/with.yue
index 19b7be1..2256833 100644
--- a/spec/inputs/with.yue
+++ b/spec/inputs/with.yue
@@ -48,21 +48,21 @@ do
48 with a -- only one value allowed 48 with a -- only one value allowed
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--
@@ -73,16 +73,16 @@ do
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
@@ -90,7 +90,7 @@ do
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
@@ -103,7 +103,7 @@ do
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
@@ -138,12 +138,12 @@ do
138 138
139do 139do
140 global mask 140 global mask
141 with? mask = SolidRect width: w, height: h, color: 0x66000000 141 with? mask := SolidRect width: w, height: h, color: 0x66000000
142 .touchEnabled = true 142 .touchEnabled = true
143 .swallowTouches = true 143 .swallowTouches = true
144 144
145do 145do
146 with? mask = SolidRect width: w, height: h, color: 0x66000000 146 with? mask := SolidRect width: w, height: h, color: 0x66000000
147 .touchEnabled = true 147 .touchEnabled = true
148 .swallowTouches = true 148 .swallowTouches = true
149 149
@@ -152,4 +152,22 @@ do
152 return with {} 152 return with {}
153 return [123] 153 return [123]
154 154
155do
156 f with item
157 if .id > 0
158 break .content
159
160 a = with tb
161 if .v
162 break .a
163
164 a = while true
165 break with? tb
166 break 1
167
168do
169 a = for i = 1, 100
170 with? x := tb[i]
171 break x if .id := 1
172
155nil 173nil
diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua
index dc1285c..bda24bc 100644
--- a/spec/outputs/5.1/attrib.lua
+++ b/spec/outputs/5.1/attrib.lua
@@ -5,12 +5,36 @@ do
5 return print("closed") 5 return print("closed")
6 end 6 end
7 }) 7 })
8 local _close_0 = assert(getmetatable(a).__close) 8 local _close_0
9 local _close_1 = assert(getmetatable(b).__close); 9 if (function()
10 local _val_0 = type(a)
11 return 'table' == _val_0 or 'userdata' == _val_0
12 end)() then
13 _close_0 = assert(getmetatable(a) and getmetatable(a).__close, "variable 'a' got a non-closable value")
14 elseif a == nil then
15 _close_0 = nil
16 else
17 _close_0 = error("variable 'a' got a non-closable value")
18 end
19 local _close_1
20 if (function()
21 local _val_0 = type(b)
22 return 'table' == _val_0 or 'userdata' == _val_0
23 end)() then
24 _close_1 = assert(getmetatable(b) and getmetatable(b).__close, "variable 'b' got a non-closable value")
25 elseif b == nil then
26 _close_1 = nil
27 else
28 _close_1 = error("variable 'b' got a non-closable value")
29 end
10 (function(_arg_0, ...) 30 (function(_arg_0, ...)
11 local _ok_0 = _arg_0 31 local _ok_0 = _arg_0
12 _close_1(b) 32 if _close_1 ~= nil then
13 _close_0(a) 33 _close_1(b)
34 end
35 if _close_0 ~= nil then
36 _close_0(a)
37 end
14 if _ok_0 then 38 if _ok_0 then
15 return ... 39 return ...
16 else 40 else
@@ -53,10 +77,22 @@ do
53 __close = function(self) end 77 __close = function(self) end
54 }) 78 })
55 end 79 end
56 local _close_0 = assert(getmetatable(v).__close); 80 local _close_0
81 if (function()
82 local _val_0 = type(v)
83 return 'table' == _val_0 or 'userdata' == _val_0
84 end)() then
85 _close_0 = assert(getmetatable(v) and getmetatable(v).__close, "variable 'v' got a non-closable value")
86 elseif v == nil then
87 _close_0 = nil
88 else
89 _close_0 = error("variable 'v' got a non-closable value")
90 end
57 (function(_arg_0, ...) 91 (function(_arg_0, ...)
58 local _ok_0 = _arg_0 92 local _ok_0 = _arg_0
59 _close_0(v) 93 if _close_0 ~= nil then
94 _close_0(v)
95 end
60 if _ok_0 then 96 if _ok_0 then
61 return ... 97 return ...
62 else 98 else
@@ -69,10 +105,22 @@ do
69 _with_0:write("Hello") 105 _with_0:write("Hello")
70 f = _with_0 106 f = _with_0
71 end 107 end
72 local _close_1 = assert(getmetatable(f).__close) 108 local _close_1
109 if (function()
110 local _val_0 = type(f)
111 return 'table' == _val_0 or 'userdata' == _val_0
112 end)() then
113 _close_1 = assert(getmetatable(f) and getmetatable(f).__close, "variable 'f' got a non-closable value")
114 elseif f == nil then
115 _close_1 = nil
116 else
117 _close_1 = error("variable 'f' got a non-closable value")
118 end
73 return (function(_arg_0, ...) 119 return (function(_arg_0, ...)
74 local _ok_0 = _arg_0 120 local _ok_0 = _arg_0
75 _close_1(f) 121 if _close_1 ~= nil then
122 _close_1(f)
123 end
76 if _ok_0 then 124 if _ok_0 then
77 return ... 125 return ...
78 else 126 else
@@ -88,14 +136,28 @@ do
88 end 136 end
89 local b 137 local b
90 if not false then 138 if not false then
91 if x then 139 b = ((function()
92 b = 1 140 if x then
93 end 141 return 1
142 end
143 end)())
144 end
145 local _close_0
146 if (function()
147 local _val_0 = type(b)
148 return 'table' == _val_0 or 'userdata' == _val_0
149 end)() then
150 _close_0 = assert(getmetatable(b) and getmetatable(b).__close, "variable 'b' got a non-closable value")
151 elseif b == nil then
152 _close_0 = nil
153 else
154 _close_0 = error("variable 'b' got a non-closable value")
94 end 155 end
95 local _close_0 = assert(getmetatable(b).__close);
96 (function(_arg_0, ...) 156 (function(_arg_0, ...)
97 local _ok_0 = _arg_0 157 local _ok_0 = _arg_0
98 _close_0(b) 158 if _close_0 ~= nil then
159 _close_0(b)
160 end
99 if _ok_0 then 161 if _ok_0 then
100 return ... 162 return ...
101 else 163 else
@@ -104,10 +166,12 @@ do
104 end)(pcall(function() 166 end)(pcall(function()
105 local c 167 local c
106 if true then 168 if true then
107 local _exp_0 = x 169 c = ((function()
108 if "abc" == _exp_0 then 170 local _exp_0 = x
109 c = 998 171 if "abc" == _exp_0 then
110 end 172 return 998
173 end
174 end)())
111 end 175 end
112 local d 176 local d
113 if (function() 177 if (function()
@@ -121,10 +185,22 @@ do
121 value = value 185 value = value
122 } 186 }
123 end 187 end
124 local _close_1 = assert(getmetatable(d).__close) 188 local _close_1
189 if (function()
190 local _val_0 = type(d)
191 return 'table' == _val_0 or 'userdata' == _val_0
192 end)() then
193 _close_1 = assert(getmetatable(d) and getmetatable(d).__close, "variable 'd' got a non-closable value")
194 elseif d == nil then
195 _close_1 = nil
196 else
197 _close_1 = error("variable 'd' got a non-closable value")
198 end
125 return (function(_arg_0, ...) 199 return (function(_arg_0, ...)
126 local _ok_0 = _arg_0 200 local _ok_0 = _arg_0
127 _close_1(d) 201 if _close_1 ~= nil then
202 _close_1(d)
203 end
128 if _ok_0 then 204 if _ok_0 then
129 return ... 205 return ...
130 else 206 else
@@ -140,10 +216,22 @@ do
140 _with_0:write("Hello") 216 _with_0:write("Hello")
141 _ = _with_0 217 _ = _with_0
142 end 218 end
143 local _close_0 = assert(getmetatable(_).__close); 219 local _close_0
220 if (function()
221 local _val_0 = type(_)
222 return 'table' == _val_0 or 'userdata' == _val_0
223 end)() then
224 _close_0 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value")
225 elseif _ == nil then
226 _close_0 = nil
227 else
228 _close_0 = error("variable '_' got a non-closable value")
229 end
144 (function(_arg_0, ...) 230 (function(_arg_0, ...)
145 local _ok_0 = _arg_0 231 local _ok_0 = _arg_0
146 _close_0(_) 232 if _close_0 ~= nil then
233 _close_0(_)
234 end
147 if _ok_0 then 235 if _ok_0 then
148 return ... 236 return ...
149 else 237 else
@@ -155,10 +243,22 @@ do
155 return print("second") 243 return print("second")
156 end 244 end
157 }) 245 })
158 local _close_1 = assert(getmetatable(_).__close) 246 local _close_1
247 if (function()
248 local _val_0 = type(_)
249 return 'table' == _val_0 or 'userdata' == _val_0
250 end)() then
251 _close_1 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value")
252 elseif _ == nil then
253 _close_1 = nil
254 else
255 _close_1 = error("variable '_' got a non-closable value")
256 end
159 return (function(_arg_0, ...) 257 return (function(_arg_0, ...)
160 local _ok_0 = _arg_0 258 local _ok_0 = _arg_0
161 _close_1(_) 259 if _close_1 ~= nil then
260 _close_1(_)
261 end
162 if _ok_0 then 262 if _ok_0 then
163 return ... 263 return ...
164 else 264 else
@@ -170,10 +270,22 @@ do
170 return print("first") 270 return print("first")
171 end 271 end
172 }) 272 })
173 local _close_2 = assert(getmetatable(_).__close) 273 local _close_2
274 if (function()
275 local _val_0 = type(_)
276 return 'table' == _val_0 or 'userdata' == _val_0
277 end)() then
278 _close_2 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value")
279 elseif _ == nil then
280 _close_2 = nil
281 else
282 _close_2 = error("variable '_' got a non-closable value")
283 end
174 return (function(_arg_0, ...) 284 return (function(_arg_0, ...)
175 local _ok_0 = _arg_0 285 local _ok_0 = _arg_0
176 _close_2(_) 286 if _close_2 ~= nil then
287 _close_2(_)
288 end
177 if _ok_0 then 289 if _ok_0 then
178 return ... 290 return ...
179 else 291 else
@@ -200,10 +312,22 @@ do
200 local _ = def(function() 312 local _ = def(function()
201 return print(3) 313 return print(3)
202 end) 314 end)
203 local _close_0 = assert(getmetatable(_).__close) 315 local _close_0
316 if (function()
317 local _val_0 = type(_)
318 return 'table' == _val_0 or 'userdata' == _val_0
319 end)() then
320 _close_0 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value")
321 elseif _ == nil then
322 _close_0 = nil
323 else
324 _close_0 = error("variable '_' got a non-closable value")
325 end
204 return (function(_arg_0, ...) 326 return (function(_arg_0, ...)
205 local _ok_0 = _arg_0 327 local _ok_0 = _arg_0
206 _close_0(_) 328 if _close_0 ~= nil then
329 _close_0(_)
330 end
207 if _ok_0 then 331 if _ok_0 then
208 return ... 332 return ...
209 else 333 else
@@ -213,10 +337,22 @@ do
213 local _ = def(function() 337 local _ = def(function()
214 return print(2) 338 return print(2)
215 end) 339 end)
216 local _close_1 = assert(getmetatable(_).__close) 340 local _close_1
341 if (function()
342 local _val_0 = type(_)
343 return 'table' == _val_0 or 'userdata' == _val_0
344 end)() then
345 _close_1 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value")
346 elseif _ == nil then
347 _close_1 = nil
348 else
349 _close_1 = error("variable '_' got a non-closable value")
350 end
217 return (function(_arg_0, ...) 351 return (function(_arg_0, ...)
218 local _ok_0 = _arg_0 352 local _ok_0 = _arg_0
219 _close_1(_) 353 if _close_1 ~= nil then
354 _close_1(_)
355 end
220 if _ok_0 then 356 if _ok_0 then
221 return ... 357 return ...
222 else 358 else
@@ -226,10 +362,22 @@ do
226 local _ = def(function() 362 local _ = def(function()
227 return print(1) 363 return print(1)
228 end) 364 end)
229 local _close_2 = assert(getmetatable(_).__close) 365 local _close_2
366 if (function()
367 local _val_0 = type(_)
368 return 'table' == _val_0 or 'userdata' == _val_0
369 end)() then
370 _close_2 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value")
371 elseif _ == nil then
372 _close_2 = nil
373 else
374 _close_2 = error("variable '_' got a non-closable value")
375 end
230 return (function(_arg_0, ...) 376 return (function(_arg_0, ...)
231 local _ok_0 = _arg_0 377 local _ok_0 = _arg_0
232 _close_2(_) 378 if _close_2 ~= nil then
379 _close_2(_)
380 end
233 if _ok_0 then 381 if _ok_0 then
234 return ... 382 return ...
235 else 383 else
diff --git a/spec/outputs/5.1/loops.lua b/spec/outputs/5.1/loops.lua
index 57b19be..e4f2871 100644
--- a/spec/outputs/5.1/loops.lua
+++ b/spec/outputs/5.1/loops.lua
@@ -60,8 +60,8 @@ do
60 local y = hello[_index_0] 60 local y = hello[_index_0]
61 if y % 2 == 0 then 61 if y % 2 == 0 then
62 _accum_0[_len_0] = y 62 _accum_0[_len_0] = y
63 _len_0 = _len_0 + 1
63 end 64 end
64 _len_0 = _len_0 + 1
65 end 65 end
66 x = _accum_0 66 x = _accum_0
67end 67end
@@ -132,13 +132,11 @@ do
132end 132end
133do 133do
134 local _accum_0 = { } 134 local _accum_0 = { }
135 local _len_0 = 1
136 local _list_2 = 3 135 local _list_2 = 3
137 for _index_0 = 1, #_list_2 do 136 for _index_0 = 1, #_list_2 do
138 local thing = _list_2[_index_0] 137 local thing = _list_2[_index_0]
139 y = "hello" 138 y = "hello"
140 break 139 break
141 _len_0 = _len_0 + 1
142 end 140 end
143 x = _accum_0 141 x = _accum_0
144end 142end
@@ -489,3 +487,131 @@ do
489 end 487 end
490 until false 488 until false
491end 489end
490local _anon_func_0 = function(i, tb)
491 local _accum_0 = { }
492 local _len_0 = 1
493 while tb[i] do
494 i = i + 1
495 _accum_0[_len_0] = i - 1
496 _len_0 = _len_0 + 1
497 end
498 return _accum_0
499end
500do
501 local index
502 do
503 local _accum_0
504 for i = 1, #tb do
505 if tb[i] then
506 _accum_0 = i
507 break
508 end
509 end
510 index = _accum_0
511 end
512 f((function()
513 local _accum_0
514 for i = 1, #tb do
515 if tb[i] then
516 _accum_0 = i
517 break
518 end
519 end
520 return _accum_0
521 end)())
522 f((function()
523 local _accum_0 = { }
524 local _len_0 = 1
525 for i = 1, #tb do
526 if tb[i] then
527 _accum_0[_len_0] = i
528 _len_0 = _len_0 + 1
529 end
530 end
531 return _accum_0
532 end)())
533 i = 1
534 local ids
535 do
536 local _accum_0 = { }
537 local _len_0 = 1
538 while tb[i] do
539 i = i + 1
540 _accum_0[_len_0] = i - 1
541 _len_0 = _len_0 + 1
542 end
543 ids = _accum_0
544 end
545 i = 1
546 local idx
547 do
548 local _accum_0
549 while tb[i] do
550 i = i + 1
551 _accum_0 = i - 1
552 break
553 end
554 idx = _accum_0
555 end
556 local f1
557 f1 = function()
558 i = 1
559 return f(_anon_func_0(i, tb))
560 end
561 i = 1
562 f((function()
563 local _accum_0
564 while tb[i] do
565 i = i + 1
566 _accum_0 = i - 1
567 break
568 end
569 return _accum_0
570 end)())
571 local _accum_0 = { }
572 local _len_0 = 1
573 local _list_3 = items
574 for _index_0 = 1, #_list_3 do
575 local item = _list_3[_index_0]
576 local _type_0 = type(item)
577 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
578 if _tab_0 then
579 local value = item.value
580 if "A" == item.type and value ~= nil then
581 if value > 5 then
582 _accum_0[_len_0] = item
583 _len_0 = _len_0 + 1
584 end
585 end
586 end
587 end
588 list = _accum_0
589end
590do
591 repeat
592 print(1)
593 until true
594 do
595 local _accum_0
596 repeat
597 a = func()
598 _accum_0 = a.x
599 break
600 until a.v
601 x = _accum_0
602 end
603 local items
604 local _accum_0 = { }
605 local _len_0 = 1
606 repeat
607 local item = getItem()
608 if not item then
609 break
610 end
611 if item.value > 0 then
612 _accum_0[_len_0] = item
613 _len_0 = _len_0 + 1
614 end
615 until false
616 items = _accum_0
617end
diff --git a/spec/outputs/5.1/try_catch.lua b/spec/outputs/5.1/try_catch.lua
index d4c80c1..d2b58bc 100644
--- a/spec/outputs/5.1/try_catch.lua
+++ b/spec/outputs/5.1/try_catch.lua
@@ -8,10 +8,10 @@ local _anon_func_2 = function(tb)
8 return tb.func() 8 return tb.func()
9end 9end
10local _anon_func_3 = function(tb) 10local _anon_func_3 = function(tb)
11 return tb.func() 11 return (tb.func())
12end 12end
13local _anon_func_4 = function(tb) 13local _anon_func_4 = function(tb)
14 return tb:func(1, 2, 3) 14 return (tb:func(1, 2, 3))
15end 15end
16local _anon_func_5 = function(tb) 16local _anon_func_5 = function(tb)
17 return tb.func(1) 17 return tb.func(1)
@@ -22,6 +22,43 @@ end
22local _anon_func_7 = function(a, b, c, tb) 22local _anon_func_7 = function(a, b, c, tb)
23 return tb.f(a, b, c) 23 return tb.f(a, b, c)
24end 24end
25local _anon_func_8 = function(_arg_0, ...)
26 local ok = _arg_0
27 return ...
28end
29local _anon_func_10 = function(_arg_0, ...)
30 local _ok_0 = _arg_0
31 if _ok_0 then
32 return ...
33 end
34end
35local _anon_func_9 = function(func, pcall)
36 return _anon_func_10(pcall(func))
37end
38local _anon_func_12 = function(_arg_0, ...)
39 local _ok_0 = _arg_0
40 if _ok_0 then
41 return ...
42 end
43end
44local _anon_func_11 = function(func, pcall)
45 return _anon_func_12(pcall(func))
46end
47local _anon_func_14 = function(_arg_0, ...)
48 local _ok_0 = _arg_0
49 if _ok_0 then
50 return ...
51 end
52end
53local _anon_func_13 = function(func, print, xpcall)
54 return _anon_func_14(xpcall(function()
55 print(123)
56 return func()
57 end, function(e)
58 print(e)
59 return e
60 end))
61end
25local f 62local f
26f = function() 63f = function()
27 xpcall(function() 64 xpcall(function()
@@ -64,7 +101,7 @@ f = function()
64 print("OK") 101 print("OK")
65 end 102 end
66 if xpcall(function() 103 if xpcall(function()
67 return func(1) 104 return (func(1))
68 end, function(err) 105 end, function(err)
69 return print(err) 106 return print(err)
70 end) then 107 end) then
@@ -104,10 +141,236 @@ f = function()
104 do 141 do
105 x(function() 142 x(function()
106 local tb, a, b, c 143 local tb, a, b, c
107 f = function() 144 local f1
145 f1 = function()
108 return pcall(_anon_func_7, a, b, c, tb) 146 return pcall(_anon_func_7, a, b, c, tb)
109 end 147 end
110 end) 148 end)
111 end 149 end
150 do
151 local f1
152 f1 = function()
153 do
154 return _anon_func_8(pcall(function()
155 return func()
156 end))
157 end
158 end
159 end
160 do
161 local func
162 local a, b, c
163 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
164 if _ok_0 then
165 a, b, c = _ret_0, _ret_1, _ret_2
166 end
167 end
168 do
169 local a, b, c
170 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
171 return func()
172 end)
173 if _ok_0 then
174 a, b, c = _ret_0, _ret_1, _ret_2
175 end
176 end
177 do
178 local a
179 local _exp_0 = (_anon_func_9(func, pcall))
180 if _exp_0 ~= nil then
181 a = _exp_0
182 else
183 a = "default"
184 end
185 end
186 do
187 f(_anon_func_11(func, pcall))
188 end
189 do
190 f(_anon_func_13(func, print, xpcall))
191 end
112 return nil 192 return nil
113end 193end
194local _anon_func_15 = function(a, b, c, tb)
195 return tb.f(a, b, c)
196end
197local _anon_func_16 = function(_arg_0, ...)
198 local ok = _arg_0
199 return ...
200end
201do
202 xpcall(function()
203 return func(1, 2, 3)
204 end, function(err)
205 return print(err)
206 end)
207 xpcall(function()
208 return func(1, 2, 3)
209 end, function(err)
210 return print(err)
211 end)
212 pcall(function()
213 print("trying")
214 return func(1, 2, 3)
215 end)
216 do
217 local success, result = xpcall(function()
218 return func(1, 2, 3)
219 end, function(err)
220 return print(err)
221 end)
222 success, result = pcall(function()
223 return func(1, 2, 3)
224 end)
225 end
226 local tb = { }
227 pcall(function()
228 return tb.func
229 end)
230 pcall(function()
231 return tb.func()
232 end)
233 pcall(function()
234 return tb.func()
235 end)
236 pcall(function()
237 return (tb.func())
238 end)
239 pcall(function()
240 return (tb:func(1, 2, 3))
241 end)
242 pcall(function()
243 return tb.func(1)
244 end)
245 pcall(function()
246 return tb.func(1)
247 end)
248 if (xpcall(function()
249 return func(1)
250 end, function(err)
251 return print(err)
252 end)) then
253 print("OK")
254 end
255 if xpcall(function()
256 return (func(1))
257 end, function(err)
258 return print(err)
259 end) then
260 print("OK")
261 end
262 do
263 do
264 local success, result = pcall(function()
265 return func("abc", 123)
266 end)
267 if success then
268 print(result)
269 end
270 end
271 local success, result = xpcall(function()
272 return func("abc", 123)
273 end, function(err)
274 return print(err)
275 end)
276 success, result = xpcall(function()
277 return func("abc", 123)
278 end, function(err)
279 return print(err)
280 end)
281 if success then
282 print(result)
283 end
284 end
285 do
286 pcall(function()
287 return func(1, 2, 3)
288 end)
289 pcall(function()
290 return func(1, 2, 3)
291 end)
292 end
293 do
294 x(function()
295 local tb, a, b, c
296 local f1
297 f1 = function()
298 return pcall(_anon_func_15, a, b, c, tb)
299 end
300 end)
301 end
302 do
303 local f1
304 f1 = function()
305 do
306 return _anon_func_16(pcall(function()
307 return func()
308 end))
309 end
310 end
311 end
312 do
313 local func
314 local a, b, c
315 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
316 if _ok_0 then
317 a, b, c = _ret_0, _ret_1, _ret_2
318 end
319 end
320 do
321 local a, b, c
322 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
323 return func()
324 end)
325 if _ok_0 then
326 a, b, c = _ret_0, _ret_1, _ret_2
327 end
328 end
329 do
330 local a
331 local _exp_0 = ((function()
332 return (function(_arg_0, ...)
333 local _ok_0 = _arg_0
334 if _ok_0 then
335 return ...
336 end
337 end)(pcall(function()
338 return func()
339 end))
340 end)())
341 if _exp_0 ~= nil then
342 a = _exp_0
343 else
344 a = "default"
345 end
346 end
347 do
348 f((function()
349 return (function(_arg_0, ...)
350 local _ok_0 = _arg_0
351 if _ok_0 then
352 return ...
353 end
354 end)(pcall(function()
355 return func()
356 end))
357 end)())
358 end
359 do
360 f((function()
361 return (function(_arg_0, ...)
362 local _ok_0 = _arg_0
363 if _ok_0 then
364 return ...
365 end
366 end)(xpcall(function()
367 print(123)
368 return func()
369 end, function(e)
370 print(e)
371 return e
372 end))
373 end)())
374 end
375end
376return nil
diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua
index 162a563..89c5f8a 100644
--- a/spec/outputs/assign.lua
+++ b/spec/outputs/assign.lua
@@ -36,17 +36,15 @@ local x
36do 36do
37 local f = getHandler() 37 local f = getHandler()
38 if f then 38 if f then
39 do 39 x = ((function()
40 f() 40 f()
41 x = 123 41 return 123
42 end 42 end)())
43 end 43 end
44end 44end
45local _anon_func_0 = function(print) 45local _anon_func_0 = function(print)
46 do 46 print(123)
47 print(123) 47 return { }
48 return { }
49 end
50end 48end
51return _(function() 49return _(function()
52 setmetatable(a, _anon_func_0(print)) 50 setmetatable(a, _anon_func_0(print))
@@ -181,5 +179,30 @@ return _(function()
181 local b = val 179 local b = val
182 local c = val 180 local c = val
183 end 181 end
182 do
183 local a = a .. "abc"
184 a = a // 2
185 a = a or def
186 a = a and false
187 a = a >> 10
188 a = a << 10
189 local _obj_0 = a.b
190 if _obj_0.c == nil then
191 _obj_0.c = 123
192 end
193 local _obj_1 = a.b
194 _obj_1.c = _obj_1.c + 1
195 local _obj_2 = a.b
196 _obj_2.c = _obj_2.c - 2
197 local _obj_3 = a.b
198 _obj_3.c = _obj_3.c * 3
199 local _obj_4 = a.b
200 _obj_4.c = _obj_4.c / 4
201 local _obj_5 = a.b
202 _obj_5.c = _obj_5.c % 5
203 a = a & 6
204 a = a | 7
205 a = a ^ 8
206 end
184 return nil 207 return nil
185end) 208end)
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua
index e48963c..bb9916c 100644
--- a/spec/outputs/attrib.lua
+++ b/spec/outputs/attrib.lua
@@ -56,17 +56,21 @@ do
56 end 56 end
57 local b 57 local b
58 if not false then 58 if not false then
59 if x then 59 b = ((function()
60 b = 1 60 if x then
61 end 61 return 1
62 end
63 end)())
62 end 64 end
63 local _close_0 <close> = b 65 local _close_0 <close> = b
64 local c 66 local c
65 if true then 67 if true then
66 local _exp_0 = x 68 c = ((function()
67 if "abc" == _exp_0 then 69 local _exp_0 = x
68 c = 998 70 if "abc" == _exp_0 then
69 end 71 return 998
72 end
73 end)())
70 end 74 end
71 local d 75 local d
72 if (function() 76 if (function()
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua
index aaea33c..07efde4 100644
--- a/spec/outputs/class.lua
+++ b/spec/outputs/class.lua
@@ -1231,30 +1231,28 @@ do
1231end 1231end
1232do 1232do
1233 local CX 1233 local CX
1234 do 1234 local _class_0
1235 local _class_0 1235 local _base_0 = { }
1236 local _base_0 = { } 1236 if _base_0.__index == nil then
1237 if _base_0.__index == nil then 1237 _base_0.__index = _base_0
1238 _base_0.__index = _base_0
1239 end
1240 _class_0 = setmetatable({
1241 __init = function(self) end,
1242 __base = _base_0,
1243 __name = "CX"
1244 }, {
1245 __index = _base_0,
1246 __call = function(cls, ...)
1247 local _self_0 = setmetatable({ }, _base_0)
1248 cls.__init(_self_0, ...)
1249 return _self_0
1250 end
1251 })
1252 _base_0.__class = _class_0
1253 local self = _class_0;
1254 xa = 1
1255 xb = 1
1256 CX = _class_0
1257 end 1238 end
1239 _class_0 = setmetatable({
1240 __init = function(self) end,
1241 __base = _base_0,
1242 __name = "CX"
1243 }, {
1244 __index = _base_0,
1245 __call = function(cls, ...)
1246 local _self_0 = setmetatable({ }, _base_0)
1247 cls.__init(_self_0, ...)
1248 return _self_0
1249 end
1250 })
1251 _base_0.__class = _class_0
1252 local self = _class_0;
1253 xa = 1
1254 xb = 1
1255 CX = _class_0
1258end 1256end
1259do 1257do
1260 local CY 1258 local CY
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 74db469..055e79b 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.lua
@@ -20,6 +20,38 @@ local inventory = {
20 } 20 }
21 } 21 }
22} 22}
23local map
24map = function(arr, action)
25 local _accum_0 = { }
26 local _len_0 = 1
27 for _index_0 = 1, #arr do
28 local item = arr[_index_0]
29 _accum_0[_len_0] = action(item)
30 _len_0 = _len_0 + 1
31 end
32 return _accum_0
33end
34local filter
35filter = function(arr, cond)
36 local _accum_0 = { }
37 local _len_0 = 1
38 for _index_0 = 1, #arr do
39 local item = arr[_index_0]
40 if cond(item) then
41 _accum_0[_len_0] = item
42 _len_0 = _len_0 + 1
43 end
44 end
45 return _accum_0
46end
47local reduce
48reduce = function(arr, init, action)
49 for _index_0 = 1, #arr do
50 local item = arr[_index_0]
51 init = action(init, item)
52 end
53 return init
54end
23print(reduce(filter(map({ 55print(reduce(filter(map({
24 1, 56 1,
25 2, 57 2,
@@ -77,6 +109,12 @@ end
77print("yuescript") 109print("yuescript")
78print(3) 110print(3)
79print("Valid enum type:", "Static") 111print("Valid enum type:", "Static")
112do
113 print(123, "hello")
114end
115do
116 print(123, "hello")
117end
80if tb ~= nil then 118if tb ~= nil then
81 tb:func() 119 tb:func()
82end 120end
@@ -177,6 +215,16 @@ for _key_0, _value_0 in pairs(b) do
177 end 215 end
178end 216end
179merge = _tab_0 217merge = _tab_0
218local last
219do
220 local _item_0 = data.items
221 last = _item_0[#_item_0]
222end
223local second_last
224do
225 local _item_0 = data.items
226 second_last = _item_0[#_item_0 - 1]
227end
180local mt = { } 228local mt = { }
181local add 229local add
182add = function(self, right) 230add = function(self, right)
@@ -307,6 +355,14 @@ func({
307 2, 355 2,
308 3 356 3
309}) 357})
358local f
359f = function()
360 return {
361 1,
362 2,
363 3
364 }
365end
310local tb = { 366local tb = {
311 name = "abc", 367 name = "abc",
312 values = { 368 values = {
@@ -467,8 +523,7 @@ local x = f()
467local y = x 523local y = x
468local z = x 524local z = x
469do 525do
470 local a 526 local a = 1
471 a = 1
472 local x, y, z 527 local x, y, z
473 print("forward declare all variables as locals") 528 print("forward declare all variables as locals")
474 x = function() 529 x = function()
@@ -478,8 +533,7 @@ do
478 instance = Item:new() 533 instance = Item:new()
479end 534end
480do 535do
481 local X 536 local X = 1
482 X = 1
483 local B 537 local B
484 print("only forward declare upper case variables") 538 print("only forward declare upper case variables")
485 local a = 1 539 local a = 1
@@ -488,19 +542,17 @@ end
488do 542do
489 a = 1 543 a = 1
490 print("declare all variables as globals") 544 print("declare all variables as globals")
491 local x
492 x = function() 545 x = function()
493 return 1 + y + z 546 return 1 + y + z
494 end 547 end
495 local y, z = 2, 3 548 y, z = 2, 3
496end 549end
497do 550do
498 X = 1 551 X = 1
499 print("only declare upper case variables as globals") 552 print("only declare upper case variables as globals")
500 local a = 1 553 local a = 1
501 local B = 2 554 B = 2
502 local Temp 555 local Temp = "a local value"
503 Temp = "a local value"
504end 556end
505local thing = { 557local thing = {
506 1, 558 1,
@@ -551,6 +603,59 @@ end
551local two, four 603local two, four
552local _obj_0 = items 604local _obj_0 = items
553two, four = _obj_0[2], _obj_0[4] 605two, four = _obj_0[2], _obj_0[4]
606local orders = {
607 "first",
608 "second",
609 "third",
610 "fourth",
611 "last"
612}
613local first, bulk, last = orders[1], (function()
614 local _accum_0 = { }
615 local _len_0 = 1
616 local _max_0 = #orders + -2 + 1
617 for _index_0 = 2, _max_0 do
618 local _item_0 = orders[_index_0]
619 _accum_0[_len_0] = _item_0
620 _len_0 = _len_0 + 1
621 end
622 return _accum_0
623end)(), orders[#orders]
624print(first)
625print(bulk)
626print(last)
627local first, rest
628do
629 local _obj_0 = orders
630 first, rest = _obj_0[1], (function()
631 local _accum_0 = { }
632 local _len_0 = 1
633 local _max_0 = #_obj_0
634 for _index_0 = 2, _max_0 do
635 local _item_0 = _obj_0[_index_0]
636 _accum_0[_len_0] = _item_0
637 _len_0 = _len_0 + 1
638 end
639 return _accum_0
640 end)()
641end
642local start, last
643do
644 local _obj_0 = orders
645 start, last = (function()
646 local _accum_0 = { }
647 local _len_0 = 1
648 local _max_0 = #_obj_0 + -2 + 1
649 for _index_0 = 1, _max_0 do
650 local _item_0 = _obj_0[_index_0]
651 _accum_0[_len_0] = _item_0
652 _len_0 = _len_0 + 1
653 end
654 return _accum_0
655 end)(), _obj_0[#_obj_0]
656end
657local _obj_0 = orders
658first, last = _obj_0[1], _obj_0[#_obj_0]
554local tuples = { 659local tuples = {
555 { 660 {
556 "hello", 661 "hello",
@@ -652,6 +757,56 @@ end)
652if success then 757if success then
653 print(result) 758 print(result)
654end 759end
760local a, b, c
761do
762 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
763 return func()
764 end)
765 if _ok_0 then
766 a, b, c = _ret_0, _ret_1, _ret_2
767 end
768end
769do
770 local _exp_0 = ((function()
771 return (function(_arg_0, ...)
772 local _ok_0 = _arg_0
773 if _ok_0 then
774 return ...
775 end
776 end)(pcall(function()
777 return func()
778 end))
779 end)())
780 if _exp_0 ~= nil then
781 a = _exp_0
782 else
783 a = "default"
784 end
785end
786f((function()
787 return (function(_arg_0, ...)
788 local _ok_0 = _arg_0
789 if _ok_0 then
790 return ...
791 end
792 end)(pcall(function()
793 return func()
794 end))
795end)())
796f((function()
797 return (function(_arg_0, ...)
798 local _ok_0 = _arg_0
799 if _ok_0 then
800 return ...
801 end
802 end)(xpcall(function()
803 print(123)
804 return func()
805 end, function(e)
806 print(e)
807 return e
808 end))
809end)())
655local a <const> = 123 810local a <const> = 123
656local _ <close> = setmetatable({ }, { 811local _ <close> = setmetatable({ }, {
657 __close = function() 812 __close = function()
@@ -661,10 +816,19 @@ local _ <close> = setmetatable({ }, {
661local a, b, c, d 816local a, b, c, d
662local _obj_0 = tb 817local _obj_0 = tb
663a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 818a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
819Constant = 123
664local some_string = "Here is a string\n that has a line break in it." 820local some_string = "Here is a string\n that has a line break in it."
665print("I am " .. tostring(math.random() * 100) .. "% sure.") 821print("I am " .. tostring(math.random() * 100) .. "% sure.")
666local integer = 1000000 822local integer = 1000000
667local hex = 0xEFBBBF 823local hex = 0xEFBBBF
824local binary = 19
825local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
826local fn
827fn = function()
828 local str = "foo:\n bar: baz"
829 return str
830end
831local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
668local my_function 832local my_function
669my_function = function() end 833my_function = function() end
670my_function() 834my_function()
@@ -759,6 +923,36 @@ if func(1, 2, 3, "hello", "world") then
759 print("hello") 923 print("hello")
760 print("I am inside if") 924 print("I am inside if")
761end 925end
926local f1
927f1 = function(_arg_0)
928 local a, b, c
929 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
930 return print(a, b, c)
931end
932f1({
933 a = 1,
934 b = "2",
935 c = { }
936})
937local f2
938f2 = function(_arg_0, c)
939 local a1, b
940 a1, b = _arg_0.a, _arg_0.b
941 if a1 == nil then
942 a1 = 123
943 end
944 if b == nil then
945 b = 'abc'
946 end
947 if c == nil then
948 c = { }
949 end
950 return print(a1, b, c)
951end
952local arg1 = {
953 a = 0
954}
955f2(arg1, arg2)
762f(function() 956f(function()
763 return print("hello") 957 return print("hello")
764end) 958end)
@@ -864,11 +1058,10 @@ for i, item in ipairs(items) do
864 _len_0 = _len_0 + 1 1058 _len_0 = _len_0 + 1
865end 1059end
866doubled = _accum_0 1060doubled = _accum_0
867local iter = ipairs(items)
868local slice 1061local slice
869local _accum_0 = { } 1062local _accum_0 = { }
870local _len_0 = 1 1063local _len_0 = 1
871for i, item in iter do 1064for i, item in ipairs(items) do
872 if i > 1 and i < 3 then 1065 if i > 1 and i < 3 then
873 _accum_0[_len_0] = item 1066 _accum_0[_len_0] = item
874 _len_0 = _len_0 + 1 1067 _len_0 = _len_0 + 1
@@ -975,8 +1168,7 @@ local slice
975local _accum_0 = { } 1168local _accum_0 = { }
976local _len_0 = 1 1169local _len_0 = 1
977local _list_0 = items 1170local _list_0 = items
978local _max_0 = 5 1171for _index_0 = 1, 5 do
979for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
980 local item = _list_0[_index_0] 1172 local item = _list_0[_index_0]
981 _accum_0[_len_0] = item 1173 _accum_0[_len_0] = item
982 _len_0 = _len_0 + 1 1174 _len_0 = _len_0 + 1
@@ -986,7 +1178,8 @@ local slice
986local _accum_0 = { } 1178local _accum_0 = { }
987local _len_0 = 1 1179local _len_0 = 1
988local _list_0 = items 1180local _list_0 = items
989for _index_0 = 2, #_list_0 do 1181local _max_0 = #_list_0
1182for _index_0 = 2, _max_0 do
990 local item = _list_0[_index_0] 1183 local item = _list_0[_index_0]
991 _accum_0[_len_0] = item 1184 _accum_0[_len_0] = item
992 _len_0 = _len_0 + 1 1185 _len_0 = _len_0 + 1
@@ -996,12 +1189,46 @@ local slice
996local _accum_0 = { } 1189local _accum_0 = { }
997local _len_0 = 1 1190local _len_0 = 1
998local _list_0 = items 1191local _list_0 = items
999for _index_0 = 1, #_list_0, 2 do 1192local _max_0 = #_list_0
1193for _index_0 = 1, _max_0, 2 do
1000 local item = _list_0[_index_0] 1194 local item = _list_0[_index_0]
1001 _accum_0[_len_0] = item 1195 _accum_0[_len_0] = item
1002 _len_0 = _len_0 + 1 1196 _len_0 = _len_0 + 1
1003end 1197end
1004slice = _accum_0 1198slice = _accum_0
1199local slice
1200local _accum_0 = { }
1201local _len_0 = 1
1202local _list_0 = items
1203local _min_0 = #_list_0 + -4 + 1
1204local _max_0 = #_list_0 + -1 + 1
1205for _index_0 = _min_0, _max_0 do
1206 local item = _list_0[_index_0]
1207 _accum_0[_len_0] = item
1208 _len_0 = _len_0 + 1
1209end
1210slice = _accum_0
1211local reverse_slice
1212local _accum_0 = { }
1213local _len_0 = 1
1214local _list_0 = items
1215local _min_0 = #_list_0 + -1 + 1
1216for _index_0 = _min_0, 1, -1 do
1217 local item = _list_0[_index_0]
1218 _accum_0[_len_0] = item
1219 _len_0 = _len_0 + 1
1220end
1221reverse_slice = _accum_0
1222local sub_list
1223local _accum_0 = { }
1224local _len_0 = 1
1225local _list_0 = items
1226for _index_0 = 2, 4 do
1227 local _item_0 = _list_0[_index_0]
1228 _accum_0[_len_0] = _item_0
1229 _len_0 = _len_0 + 1
1230end
1231sub_list = _accum_0
1005for i = 10, 20 do 1232for i = 10, 20 do
1006 print(i) 1233 print(i)
1007end 1234end
@@ -1012,8 +1239,7 @@ for key, value in pairs(object) do
1012 print(key, value) 1239 print(key, value)
1013end 1240end
1014local _list_0 = items 1241local _list_0 = items
1015local _max_0 = 4 1242for _index_0 = 2, 4 do
1016for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1017 local item = _list_0[_index_0] 1243 local item = _list_0[_index_0]
1018 print(item) 1244 print(item)
1019end 1245end
@@ -1031,12 +1257,24 @@ local _len_0 = 1
1031for i = 1, 20 do 1257for i = 1, 20 do
1032 if i % 2 == 0 then 1258 if i % 2 == 0 then
1033 _accum_0[_len_0] = i * 2 1259 _accum_0[_len_0] = i * 2
1260 _len_0 = _len_0 + 1
1034 else 1261 else
1035 _accum_0[_len_0] = i 1262 _accum_0[_len_0] = i
1263 _len_0 = _len_0 + 1
1036 end 1264 end
1037 _len_0 = _len_0 + 1
1038end 1265end
1039doubled_evens = _accum_0 1266doubled_evens = _accum_0
1267local first_large
1268local _accum_0
1269local _list_0 = numbers
1270for _index_0 = 1, #_list_0 do
1271 local n = _list_0[_index_0]
1272 if n > 10 then
1273 _accum_0 = n
1274 break
1275 end
1276end
1277first_large = _accum_0
1040local func_a 1278local func_a
1041func_a = function() 1279func_a = function()
1042 for i = 1, 10 do 1280 for i = 1, 10 do
@@ -1185,7 +1423,7 @@ if "Robert" == name then
1185elseif "Dan" == name or "Daniel" == name then 1423elseif "Dan" == name or "Daniel" == name then
1186 print("Your name, it's Dan") 1424 print("Your name, it's Dan")
1187else 1425else
1188 print("I don't know about your name") 1426 print("I don't know about you with name " .. tostring(name))
1189end 1427end
1190local b = 1 1428local b = 1
1191local next_number 1429local next_number
@@ -1285,6 +1523,192 @@ if _tab_0 then
1285 end 1523 end
1286 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1524 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1287end 1525end
1526local _exp_0 = tb
1527local _type_0 = type(_exp_0)
1528local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1529local _match_0 = false
1530if _tab_0 then
1531 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1532 _match_0 = true
1533 print("1, 2, 3")
1534 end
1535end
1536if not _match_0 then
1537 local _match_1 = false
1538 if _tab_0 then
1539 local b = _exp_0[2]
1540 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1541 _match_1 = true
1542 print("1, " .. tostring(b) .. ", 3")
1543 end
1544 end
1545 if not _match_1 then
1546 if _tab_0 then
1547 local b = _exp_0[3]
1548 if b == nil then
1549 b = 3
1550 end
1551 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1552 print("1, 2, " .. tostring(b))
1553 end
1554 end
1555 end
1556end
1557local _exp_0 = tb
1558local _type_0 = type(_exp_0)
1559local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1560local _match_0 = false
1561if _tab_0 then
1562 local result = _exp_0.result
1563 if true == _exp_0.success and result ~= nil then
1564 _match_0 = true
1565 print("success", result)
1566 end
1567end
1568if not _match_0 then
1569 local _match_1 = false
1570 if _tab_0 then
1571 if false == _exp_0.success then
1572 _match_1 = true
1573 print("failed", result)
1574 end
1575 end
1576 if not _match_1 then
1577 print("invalid")
1578 end
1579end
1580local _exp_0 = tb
1581local _type_0 = type(_exp_0)
1582local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1583local _match_0 = false
1584if _tab_0 then
1585 local content
1586 do
1587 local _obj_0 = _exp_0.data
1588 local _type_1 = type(_obj_0)
1589 if "table" == _type_1 or "userdata" == _type_1 then
1590 content = _obj_0.content
1591 end
1592 end
1593 local _val_0
1594 do
1595 local _obj_0 = _exp_0.data
1596 if _obj_0 ~= nil then
1597 _val_0 = _obj_0.type
1598 end
1599 end
1600 if "success" == _val_0 and content ~= nil then
1601 _match_0 = true
1602 print("success", content)
1603 end
1604end
1605if not _match_0 then
1606 local _match_1 = false
1607 if _tab_0 then
1608 local content
1609 do
1610 local _obj_0 = _exp_0.data
1611 local _type_1 = type(_obj_0)
1612 if "table" == _type_1 or "userdata" == _type_1 then
1613 content = _obj_0.content
1614 end
1615 end
1616 local _val_0
1617 do
1618 local _obj_0 = _exp_0.data
1619 if _obj_0 ~= nil then
1620 _val_0 = _obj_0.type
1621 end
1622 end
1623 if "error" == _val_0 and content ~= nil then
1624 _match_1 = true
1625 print("failed", content)
1626 end
1627 end
1628 if not _match_1 then
1629 print("invalid")
1630 end
1631end
1632local _exp_0 = tb
1633local _type_0 = type(_exp_0)
1634local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1635if _tab_0 then
1636 local fourth = _exp_0[4]
1637 local _val_0
1638 do
1639 local _obj_0 = _exp_0[1]
1640 if _obj_0 ~= nil then
1641 _val_0 = _obj_0.a
1642 end
1643 end
1644 local _val_1
1645 do
1646 local _obj_0 = _exp_0[1]
1647 if _obj_0 ~= nil then
1648 _val_1 = _obj_0.b
1649 end
1650 end
1651 local _val_2
1652 do
1653 local _obj_0 = _exp_0[2]
1654 if _obj_0 ~= nil then
1655 _val_2 = _obj_0.a
1656 end
1657 end
1658 local _val_3
1659 do
1660 local _obj_0 = _exp_0[2]
1661 if _obj_0 ~= nil then
1662 _val_3 = _obj_0.b
1663 end
1664 end
1665 local _val_4
1666 do
1667 local _obj_0 = _exp_0[3]
1668 if _obj_0 ~= nil then
1669 _val_4 = _obj_0.a
1670 end
1671 end
1672 local _val_5
1673 do
1674 local _obj_0 = _exp_0[3]
1675 if _obj_0 ~= nil then
1676 _val_5 = _obj_0.b
1677 end
1678 end
1679 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
1680 print("matched", fourth)
1681 end
1682end
1683local segments = {
1684 "admin",
1685 "users",
1686 "logs",
1687 "view"
1688}
1689local _type_0 = type(segments)
1690local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1691if _tab_0 then
1692 local groups
1693 do
1694 local _accum_0 = { }
1695 local _len_0 = 1
1696 local _max_0 = #segments + -3 + 1
1697 for _index_0 = 1, _max_0 do
1698 local _item_0 = segments[_index_0]
1699 _accum_0[_len_0] = _item_0
1700 _len_0 = _len_0 + 1
1701 end
1702 groups = _accum_0
1703 end
1704 local resource = segments[#segments - 1]
1705 local action = segments[#segments]
1706 if resource ~= nil and action ~= nil then
1707 print("Group:", groups)
1708 print("Resource:", resource)
1709 print("Action:", action)
1710 end
1711end
1288local Inventory 1712local Inventory
1289local _class_0 1713local _class_0
1290local _base_0 = { 1714local _base_0 = {
@@ -1941,6 +2365,10 @@ do
1941 _with_1["key-name"] = value 2365 _with_1["key-name"] = value
1942end 2366end
1943_with_0[#_with_0 + 1] = "abc" 2367_with_0[#_with_0 + 1] = "abc"
2368local _with_0 = obj
2369if _with_0 ~= nil then
2370 print(obj.name)
2371end
1944do 2372do
1945 local var = "hello" 2373 local var = "hello"
1946 print(var) 2374 print(var)
@@ -2031,6 +2459,38 @@ local inventory = {
2031 } 2459 }
2032 } 2460 }
2033} 2461}
2462local map
2463map = function(arr, action)
2464 local _accum_0 = { }
2465 local _len_0 = 1
2466 for _index_0 = 1, #arr do
2467 local item = arr[_index_0]
2468 _accum_0[_len_0] = action(item)
2469 _len_0 = _len_0 + 1
2470 end
2471 return _accum_0
2472end
2473local filter
2474filter = function(arr, cond)
2475 local _accum_0 = { }
2476 local _len_0 = 1
2477 for _index_0 = 1, #arr do
2478 local item = arr[_index_0]
2479 if cond(item) then
2480 _accum_0[_len_0] = item
2481 _len_0 = _len_0 + 1
2482 end
2483 end
2484 return _accum_0
2485end
2486local reduce
2487reduce = function(arr, init, action)
2488 for _index_0 = 1, #arr do
2489 local item = arr[_index_0]
2490 init = action(init, item)
2491 end
2492 return init
2493end
2034print(reduce(filter(map({ 2494print(reduce(filter(map({
2035 1, 2495 1,
2036 2, 2496 2,
@@ -2088,6 +2548,12 @@ end
2088print("yuescript") 2548print("yuescript")
2089print(3) 2549print(3)
2090print("Valid enum type:", "Static") 2550print("Valid enum type:", "Static")
2551do
2552 print(123, "hello")
2553end
2554do
2555 print(123, "hello")
2556end
2091if tb ~= nil then 2557if tb ~= nil then
2092 tb:func() 2558 tb:func()
2093end 2559end
@@ -2188,6 +2654,16 @@ for _key_0, _value_0 in pairs(b) do
2188 end 2654 end
2189end 2655end
2190merge = _tab_0 2656merge = _tab_0
2657local last
2658do
2659 local _item_0 = data.items
2660 last = _item_0[#_item_0]
2661end
2662local second_last
2663do
2664 local _item_0 = data.items
2665 second_last = _item_0[#_item_0 - 1]
2666end
2191local mt = { } 2667local mt = { }
2192local add 2668local add
2193add = function(self, right) 2669add = function(self, right)
@@ -2318,6 +2794,14 @@ func({
2318 2, 2794 2,
2319 3 2795 3
2320}) 2796})
2797local f
2798f = function()
2799 return {
2800 1,
2801 2,
2802 3
2803 }
2804end
2321local tb = { 2805local tb = {
2322 name = "abc", 2806 name = "abc",
2323 values = { 2807 values = {
@@ -2478,8 +2962,7 @@ local x = f()
2478local y = x 2962local y = x
2479local z = x 2963local z = x
2480do 2964do
2481 local a 2965 local a = 1
2482 a = 1
2483 local x, y, z 2966 local x, y, z
2484 print("forward declare all variables as locals") 2967 print("forward declare all variables as locals")
2485 x = function() 2968 x = function()
@@ -2489,8 +2972,7 @@ do
2489 instance = Item:new() 2972 instance = Item:new()
2490end 2973end
2491do 2974do
2492 local X 2975 local X = 1
2493 X = 1
2494 local B 2976 local B
2495 print("only forward declare upper case variables") 2977 print("only forward declare upper case variables")
2496 local a = 1 2978 local a = 1
@@ -2499,19 +2981,17 @@ end
2499do 2981do
2500 a = 1 2982 a = 1
2501 print("declare all variables as globals") 2983 print("declare all variables as globals")
2502 local x
2503 x = function() 2984 x = function()
2504 return 1 + y + z 2985 return 1 + y + z
2505 end 2986 end
2506 local y, z = 2, 3 2987 y, z = 2, 3
2507end 2988end
2508do 2989do
2509 X = 1 2990 X = 1
2510 print("only declare upper case variables as globals") 2991 print("only declare upper case variables as globals")
2511 local a = 1 2992 local a = 1
2512 local B = 2 2993 B = 2
2513 local Temp 2994 local Temp = "a local value"
2514 Temp = "a local value"
2515end 2995end
2516local thing = { 2996local thing = {
2517 1, 2997 1,
@@ -2562,6 +3042,59 @@ end
2562local two, four 3042local two, four
2563local _obj_0 = items 3043local _obj_0 = items
2564two, four = _obj_0[2], _obj_0[4] 3044two, four = _obj_0[2], _obj_0[4]
3045local orders = {
3046 "first",
3047 "second",
3048 "third",
3049 "fourth",
3050 "last"
3051}
3052local first, bulk, last = orders[1], (function()
3053 local _accum_0 = { }
3054 local _len_0 = 1
3055 local _max_0 = #orders + -2 + 1
3056 for _index_0 = 2, _max_0 do
3057 local _item_0 = orders[_index_0]
3058 _accum_0[_len_0] = _item_0
3059 _len_0 = _len_0 + 1
3060 end
3061 return _accum_0
3062end)(), orders[#orders]
3063print(first)
3064print(bulk)
3065print(last)
3066local first, rest
3067do
3068 local _obj_0 = orders
3069 first, rest = _obj_0[1], (function()
3070 local _accum_0 = { }
3071 local _len_0 = 1
3072 local _max_0 = #_obj_0
3073 for _index_0 = 2, _max_0 do
3074 local _item_0 = _obj_0[_index_0]
3075 _accum_0[_len_0] = _item_0
3076 _len_0 = _len_0 + 1
3077 end
3078 return _accum_0
3079 end)()
3080end
3081local start, last
3082do
3083 local _obj_0 = orders
3084 start, last = (function()
3085 local _accum_0 = { }
3086 local _len_0 = 1
3087 local _max_0 = #_obj_0 + -2 + 1
3088 for _index_0 = 1, _max_0 do
3089 local _item_0 = _obj_0[_index_0]
3090 _accum_0[_len_0] = _item_0
3091 _len_0 = _len_0 + 1
3092 end
3093 return _accum_0
3094 end)(), _obj_0[#_obj_0]
3095end
3096local _obj_0 = orders
3097first, last = _obj_0[1], _obj_0[#_obj_0]
2565local tuples = { 3098local tuples = {
2566 { 3099 {
2567 "hello", 3100 "hello",
@@ -2663,6 +3196,56 @@ end)
2663if success then 3196if success then
2664 print(result) 3197 print(result)
2665end 3198end
3199local a, b, c
3200do
3201 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3202 return func()
3203 end)
3204 if _ok_0 then
3205 a, b, c = _ret_0, _ret_1, _ret_2
3206 end
3207end
3208do
3209 local _exp_0 = ((function()
3210 return (function(_arg_0, ...)
3211 local _ok_0 = _arg_0
3212 if _ok_0 then
3213 return ...
3214 end
3215 end)(pcall(function()
3216 return func()
3217 end))
3218 end)())
3219 if _exp_0 ~= nil then
3220 a = _exp_0
3221 else
3222 a = "default"
3223 end
3224end
3225f((function()
3226 return (function(_arg_0, ...)
3227 local _ok_0 = _arg_0
3228 if _ok_0 then
3229 return ...
3230 end
3231 end)(pcall(function()
3232 return func()
3233 end))
3234end)())
3235f((function()
3236 return (function(_arg_0, ...)
3237 local _ok_0 = _arg_0
3238 if _ok_0 then
3239 return ...
3240 end
3241 end)(xpcall(function()
3242 print(123)
3243 return func()
3244 end, function(e)
3245 print(e)
3246 return e
3247 end))
3248end)())
2666local a <const> = 123 3249local a <const> = 123
2667local _ <close> = setmetatable({ }, { 3250local _ <close> = setmetatable({ }, {
2668 __close = function() 3251 __close = function()
@@ -2672,10 +3255,19 @@ local _ <close> = setmetatable({ }, {
2672local a, b, c, d 3255local a, b, c, d
2673local _obj_0 = tb 3256local _obj_0 = tb
2674a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3257a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3258Constant = 123
2675local some_string = "Here is a string\n that has a line break in it." 3259local some_string = "Here is a string\n that has a line break in it."
2676print("I am " .. tostring(math.random() * 100) .. "% sure.") 3260print("I am " .. tostring(math.random() * 100) .. "% sure.")
2677local integer = 1000000 3261local integer = 1000000
2678local hex = 0xEFBBBF 3262local hex = 0xEFBBBF
3263local binary = 19
3264local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3265local fn
3266fn = function()
3267 local str = "foo:\n bar: baz"
3268 return str
3269end
3270local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2679local my_function 3271local my_function
2680my_function = function() end 3272my_function = function() end
2681my_function() 3273my_function()
@@ -2770,6 +3362,66 @@ if func(1, 2, 3, "hello", "world") then
2770 print("hello") 3362 print("hello")
2771 print("I am inside if") 3363 print("I am inside if")
2772end 3364end
3365local f1
3366f1 = function(_arg_0)
3367 local a, b, c
3368 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
3369 return print(a, b, c)
3370end
3371f1({
3372 a = 1,
3373 b = "2",
3374 c = { }
3375})
3376local f2
3377f2 = function(_arg_0, c)
3378 local a1, b
3379 a1, b = _arg_0.a, _arg_0.b
3380 if a1 == nil then
3381 a1 = 123
3382 end
3383 if b == nil then
3384 b = 'abc'
3385 end
3386 if c == nil then
3387 c = { }
3388 end
3389end
3390print(a1, b, c)
3391local arg1 = {
3392 a = 0
3393}
3394f2(arg1, arg2)
3395local findFirstEven
3396findFirstEven = function(list)
3397 for _index_0 = 1, #list do
3398 local item = list[_index_0]
3399 if type(item) == "table" then
3400 for _index_1 = 1, #item do
3401 local sub = item[_index_1]
3402 if sub % 2 == 0 then
3403 return sub
3404 end
3405 end
3406 end
3407 end
3408 return nil
3409end
3410local findFirstEven
3411findFirstEven = function(list)
3412 for _index_0 = 1, #list do
3413 local item = list[_index_0]
3414 if type(item) == "table" then
3415 for _index_1 = 1, #item do
3416 local sub = item[_index_1]
3417 if sub % 2 == 0 then
3418 return sub
3419 end
3420 end
3421 end
3422 end
3423 return nil
3424end
2773f(function() 3425f(function()
2774 return print("hello") 3426 return print("hello")
2775end) 3427end)
@@ -2875,11 +3527,10 @@ for i, item in ipairs(items) do
2875 _len_0 = _len_0 + 1 3527 _len_0 = _len_0 + 1
2876end 3528end
2877doubled = _accum_0 3529doubled = _accum_0
2878local iter = ipairs(items)
2879local slice 3530local slice
2880local _accum_0 = { } 3531local _accum_0 = { }
2881local _len_0 = 1 3532local _len_0 = 1
2882for i, item in iter do 3533for i, item in ipairs(items) do
2883 if i > 1 and i < 3 then 3534 if i > 1 and i < 3 then
2884 _accum_0[_len_0] = item 3535 _accum_0[_len_0] = item
2885 _len_0 = _len_0 + 1 3536 _len_0 = _len_0 + 1
@@ -2986,8 +3637,18 @@ local slice
2986local _accum_0 = { } 3637local _accum_0 = { }
2987local _len_0 = 1 3638local _len_0 = 1
2988local _list_0 = items 3639local _list_0 = items
2989local _max_0 = 5 3640for _index_0 = 1, 5 do
2990for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 3641 local item = _list_0[_index_0]
3642 _accum_0[_len_0] = item
3643 _len_0 = _len_0 + 1
3644end
3645slice = _accum_0
3646local slice
3647local _accum_0 = { }
3648local _len_0 = 1
3649local _list_0 = items
3650local _max_0 = #_list_0
3651for _index_0 = 2, _max_0 do
2991 local item = _list_0[_index_0] 3652 local item = _list_0[_index_0]
2992 _accum_0[_len_0] = item 3653 _accum_0[_len_0] = item
2993 _len_0 = _len_0 + 1 3654 _len_0 = _len_0 + 1
@@ -2997,7 +3658,8 @@ local slice
2997local _accum_0 = { } 3658local _accum_0 = { }
2998local _len_0 = 1 3659local _len_0 = 1
2999local _list_0 = items 3660local _list_0 = items
3000for _index_0 = 2, #_list_0 do 3661local _max_0 = #_list_0
3662for _index_0 = 1, _max_0, 2 do
3001 local item = _list_0[_index_0] 3663 local item = _list_0[_index_0]
3002 _accum_0[_len_0] = item 3664 _accum_0[_len_0] = item
3003 _len_0 = _len_0 + 1 3665 _len_0 = _len_0 + 1
@@ -3007,12 +3669,35 @@ local slice
3007local _accum_0 = { } 3669local _accum_0 = { }
3008local _len_0 = 1 3670local _len_0 = 1
3009local _list_0 = items 3671local _list_0 = items
3010for _index_0 = 1, #_list_0, 2 do 3672local _min_0 = #_list_0 + -4 + 1
3673local _max_0 = #_list_0 + -1 + 1
3674for _index_0 = _min_0, _max_0 do
3011 local item = _list_0[_index_0] 3675 local item = _list_0[_index_0]
3012 _accum_0[_len_0] = item 3676 _accum_0[_len_0] = item
3013 _len_0 = _len_0 + 1 3677 _len_0 = _len_0 + 1
3014end 3678end
3015slice = _accum_0 3679slice = _accum_0
3680local reverse_slice
3681local _accum_0 = { }
3682local _len_0 = 1
3683local _list_0 = items
3684local _min_0 = #_list_0 + -1 + 1
3685for _index_0 = _min_0, 1, -1 do
3686 local item = _list_0[_index_0]
3687 _accum_0[_len_0] = item
3688 _len_0 = _len_0 + 1
3689end
3690reverse_slice = _accum_0
3691local sub_list
3692local _accum_0 = { }
3693local _len_0 = 1
3694local _list_0 = items
3695for _index_0 = 2, 4 do
3696 local _item_0 = _list_0[_index_0]
3697 _accum_0[_len_0] = _item_0
3698 _len_0 = _len_0 + 1
3699end
3700sub_list = _accum_0
3016for i = 10, 20 do 3701for i = 10, 20 do
3017 print(i) 3702 print(i)
3018end 3703end
@@ -3023,8 +3708,7 @@ for key, value in pairs(object) do
3023 print(key, value) 3708 print(key, value)
3024end 3709end
3025local _list_0 = items 3710local _list_0 = items
3026local _max_0 = 4 3711for _index_0 = 2, 4 do
3027for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3028 local item = _list_0[_index_0] 3712 local item = _list_0[_index_0]
3029 print(item) 3713 print(item)
3030end 3714end
@@ -3042,12 +3726,24 @@ local _len_0 = 1
3042for i = 1, 20 do 3726for i = 1, 20 do
3043 if i % 2 == 0 then 3727 if i % 2 == 0 then
3044 _accum_0[_len_0] = i * 2 3728 _accum_0[_len_0] = i * 2
3729 _len_0 = _len_0 + 1
3045 else 3730 else
3046 _accum_0[_len_0] = i 3731 _accum_0[_len_0] = i
3732 _len_0 = _len_0 + 1
3047 end 3733 end
3048 _len_0 = _len_0 + 1
3049end 3734end
3050doubled_evens = _accum_0 3735doubled_evens = _accum_0
3736local first_large
3737local _accum_0
3738local _list_0 = numbers
3739for _index_0 = 1, #_list_0 do
3740 local n = _list_0[_index_0]
3741 if n > 10 then
3742 _accum_0 = n
3743 break
3744 end
3745end
3746first_large = _accum_0
3051local func_a 3747local func_a
3052func_a = function() 3748func_a = function()
3053 for i = 1, 10 do 3749 for i = 1, 10 do
@@ -3196,7 +3892,7 @@ if "Robert" == name then
3196elseif "Dan" == name or "Daniel" == name then 3892elseif "Dan" == name or "Daniel" == name then
3197 print("Your name, it's Dan") 3893 print("Your name, it's Dan")
3198else 3894else
3199 print("I don't know about your name") 3895 print("I don't know about you with name " .. tostring(name))
3200end 3896end
3201local b = 1 3897local b = 1
3202local next_number 3898local next_number
@@ -3296,6 +3992,192 @@ if _tab_0 then
3296 end 3992 end
3297 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3993 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3298end 3994end
3995local _exp_0 = tb
3996local _type_0 = type(_exp_0)
3997local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3998local _match_0 = false
3999if _tab_0 then
4000 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
4001 _match_0 = true
4002 print("1, 2, 3")
4003 end
4004end
4005if not _match_0 then
4006 local _match_1 = false
4007 if _tab_0 then
4008 local b = _exp_0[2]
4009 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
4010 _match_1 = true
4011 print("1, " .. tostring(b) .. ", 3")
4012 end
4013 end
4014 if not _match_1 then
4015 if _tab_0 then
4016 local b = _exp_0[3]
4017 if b == nil then
4018 b = 3
4019 end
4020 if 1 == _exp_0[1] and 2 == _exp_0[2] then
4021 print("1, 2, " .. tostring(b))
4022 end
4023 end
4024 end
4025end
4026local _exp_0 = tb
4027local _type_0 = type(_exp_0)
4028local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4029local _match_0 = false
4030if _tab_0 then
4031 local result = _exp_0.result
4032 if true == _exp_0.success and result ~= nil then
4033 _match_0 = true
4034 print("success", result)
4035 end
4036end
4037if not _match_0 then
4038 local _match_1 = false
4039 if _tab_0 then
4040 if false == _exp_0.success then
4041 _match_1 = true
4042 print("failed", result)
4043 end
4044 end
4045 if not _match_1 then
4046 print("invalid")
4047 end
4048end
4049local _exp_0 = tb
4050local _type_0 = type(_exp_0)
4051local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4052local _match_0 = false
4053if _tab_0 then
4054 local content
4055 do
4056 local _obj_0 = _exp_0.data
4057 local _type_1 = type(_obj_0)
4058 if "table" == _type_1 or "userdata" == _type_1 then
4059 content = _obj_0.content
4060 end
4061 end
4062 local _val_0
4063 do
4064 local _obj_0 = _exp_0.data
4065 if _obj_0 ~= nil then
4066 _val_0 = _obj_0.type
4067 end
4068 end
4069 if "success" == _val_0 and content ~= nil then
4070 _match_0 = true
4071 print("success", content)
4072 end
4073end
4074if not _match_0 then
4075 local _match_1 = false
4076 if _tab_0 then
4077 local content
4078 do
4079 local _obj_0 = _exp_0.data
4080 local _type_1 = type(_obj_0)
4081 if "table" == _type_1 or "userdata" == _type_1 then
4082 content = _obj_0.content
4083 end
4084 end
4085 local _val_0
4086 do
4087 local _obj_0 = _exp_0.data
4088 if _obj_0 ~= nil then
4089 _val_0 = _obj_0.type
4090 end
4091 end
4092 if "error" == _val_0 and content ~= nil then
4093 _match_1 = true
4094 print("failed", content)
4095 end
4096 end
4097 if not _match_1 then
4098 print("invalid")
4099 end
4100end
4101local _exp_0 = tb
4102local _type_0 = type(_exp_0)
4103local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4104if _tab_0 then
4105 local fourth = _exp_0[4]
4106 local _val_0
4107 do
4108 local _obj_0 = _exp_0[1]
4109 if _obj_0 ~= nil then
4110 _val_0 = _obj_0.a
4111 end
4112 end
4113 local _val_1
4114 do
4115 local _obj_0 = _exp_0[1]
4116 if _obj_0 ~= nil then
4117 _val_1 = _obj_0.b
4118 end
4119 end
4120 local _val_2
4121 do
4122 local _obj_0 = _exp_0[2]
4123 if _obj_0 ~= nil then
4124 _val_2 = _obj_0.a
4125 end
4126 end
4127 local _val_3
4128 do
4129 local _obj_0 = _exp_0[2]
4130 if _obj_0 ~= nil then
4131 _val_3 = _obj_0.b
4132 end
4133 end
4134 local _val_4
4135 do
4136 local _obj_0 = _exp_0[3]
4137 if _obj_0 ~= nil then
4138 _val_4 = _obj_0.a
4139 end
4140 end
4141 local _val_5
4142 do
4143 local _obj_0 = _exp_0[3]
4144 if _obj_0 ~= nil then
4145 _val_5 = _obj_0.b
4146 end
4147 end
4148 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
4149 print("matched", fourth)
4150 end
4151end
4152local segments = {
4153 "admin",
4154 "users",
4155 "logs",
4156 "view"
4157}
4158local _type_0 = type(segments)
4159local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4160if _tab_0 then
4161 local groups
4162 do
4163 local _accum_0 = { }
4164 local _len_0 = 1
4165 local _max_0 = #segments + -3 + 1
4166 for _index_0 = 1, _max_0 do
4167 local _item_0 = segments[_index_0]
4168 _accum_0[_len_0] = _item_0
4169 _len_0 = _len_0 + 1
4170 end
4171 groups = _accum_0
4172 end
4173 local resource = segments[#segments - 1]
4174 local action = segments[#segments]
4175 if resource ~= nil and action ~= nil then
4176 print("Group:", groups)
4177 print("Resource:", resource)
4178 print("Action:", action)
4179 end
4180end
3299local Inventory 4181local Inventory
3300local _class_0 4182local _class_0
3301local _base_0 = { 4183local _base_0 = {
@@ -3952,6 +4834,10 @@ do
3952 _with_1["key-name"] = value 4834 _with_1["key-name"] = value
3953end 4835end
3954_with_0[#_with_0 + 1] = "abc" 4836_with_0[#_with_0 + 1] = "abc"
4837local _with_0 = obj
4838if _with_0 ~= nil then
4839 print(obj.name)
4840end
3955do 4841do
3956 local var = "hello" 4842 local var = "hello"
3957 print(var) 4843 print(var)
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index 1a10555..de76829 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -20,6 +20,38 @@ local inventory = {
20 } 20 }
21 } 21 }
22} 22}
23local map
24map = function(arr, action)
25 local _accum_0 = { }
26 local _len_0 = 1
27 for _index_0 = 1, #arr do
28 local item = arr[_index_0]
29 _accum_0[_len_0] = action(item)
30 _len_0 = _len_0 + 1
31 end
32 return _accum_0
33end
34local filter
35filter = function(arr, cond)
36 local _accum_0 = { }
37 local _len_0 = 1
38 for _index_0 = 1, #arr do
39 local item = arr[_index_0]
40 if cond(item) then
41 _accum_0[_len_0] = item
42 _len_0 = _len_0 + 1
43 end
44 end
45 return _accum_0
46end
47local reduce
48reduce = function(arr, init, action)
49 for _index_0 = 1, #arr do
50 local item = arr[_index_0]
51 init = action(init, item)
52 end
53 return init
54end
23print(reduce(filter(map({ 55print(reduce(filter(map({
24 1, 56 1,
25 2, 57 2,
@@ -77,6 +109,12 @@ end
77print("yuescript") 109print("yuescript")
78print(3) 110print(3)
79print("有效的枚举类型:", "Static") 111print("有效的枚举类型:", "Static")
112do
113 print(123, "hello")
114end
115do
116 print(123, "hello")
117end
80if tb ~= nil then 118if tb ~= nil then
81 tb:func() 119 tb:func()
82end 120end
@@ -177,6 +215,16 @@ for _key_0, _value_0 in pairs(b) do
177 end 215 end
178end 216end
179merge = _tab_0 217merge = _tab_0
218local last
219do
220 local _item_0 = data.items
221 last = _item_0[#_item_0]
222end
223local second_last
224do
225 local _item_0 = data.items
226 second_last = _item_0[#_item_0 - 1]
227end
180local mt = { } 228local mt = { }
181local add 229local add
182add = function(self, right) 230add = function(self, right)
@@ -307,6 +355,14 @@ func({
307 2, 355 2,
308 3 356 3
309}) 357})
358local f
359f = function()
360 return {
361 1,
362 2,
363 3
364 }
365end
310local tb = { 366local tb = {
311 name = "abc", 367 name = "abc",
312 values = { 368 values = {
@@ -467,8 +523,7 @@ local x = f()
467local y = x 523local y = x
468local z = x 524local z = x
469do 525do
470 local a 526 local a = 1
471 a = 1
472 local x, y, z 527 local x, y, z
473 print("预先声明后续所有变量为局部变量") 528 print("预先声明后续所有变量为局部变量")
474 x = function() 529 x = function()
@@ -478,8 +533,7 @@ do
478 instance = Item:new() 533 instance = Item:new()
479end 534end
480do 535do
481 local X 536 local X = 1
482 X = 1
483 local B 537 local B
484 print("只预先声明后续大写的变量为局部变量") 538 print("只预先声明后续大写的变量为局部变量")
485 local a = 1 539 local a = 1
@@ -488,19 +542,17 @@ end
488do 542do
489 a = 1 543 a = 1
490 print("预先声明所有变量为全局变量") 544 print("预先声明所有变量为全局变量")
491 local x
492 x = function() 545 x = function()
493 return 1 + y + z 546 return 1 + y + z
494 end 547 end
495 local y, z = 2, 3 548 y, z = 2, 3
496end 549end
497do 550do
498 x = 1 551 x = 1
499 print("只预先声明大写的变量为全局变量") 552 print("只预先声明大写的变量为全局变量")
500 local a = 1 553 local a = 1
501 local B = 2 554 B = 2
502 local Temp 555 local Temp = "一个局部值"
503 Temp = "一个局部值"
504end 556end
505local thing = { 557local thing = {
506 1, 558 1,
@@ -551,6 +603,59 @@ end
551local two, four 603local two, four
552local _obj_0 = items 604local _obj_0 = items
553two, four = _obj_0[2], _obj_0[4] 605two, four = _obj_0[2], _obj_0[4]
606local orders = {
607 "first",
608 "second",
609 "third",
610 "fourth",
611 "last"
612}
613local first, bulk, last = orders[1], (function()
614 local _accum_0 = { }
615 local _len_0 = 1
616 local _max_0 = #orders + -2 + 1
617 for _index_0 = 2, _max_0 do
618 local _item_0 = orders[_index_0]
619 _accum_0[_len_0] = _item_0
620 _len_0 = _len_0 + 1
621 end
622 return _accum_0
623end)(), orders[#orders]
624print(first)
625print(bulk)
626print(last)
627local first, rest
628do
629 local _obj_0 = orders
630 first, rest = _obj_0[1], (function()
631 local _accum_0 = { }
632 local _len_0 = 1
633 local _max_0 = #_obj_0
634 for _index_0 = 2, _max_0 do
635 local _item_0 = _obj_0[_index_0]
636 _accum_0[_len_0] = _item_0
637 _len_0 = _len_0 + 1
638 end
639 return _accum_0
640 end)()
641end
642local start, last
643do
644 local _obj_0 = orders
645 start, last = (function()
646 local _accum_0 = { }
647 local _len_0 = 1
648 local _max_0 = #_obj_0 + -2 + 1
649 for _index_0 = 1, _max_0 do
650 local _item_0 = _obj_0[_index_0]
651 _accum_0[_len_0] = _item_0
652 _len_0 = _len_0 + 1
653 end
654 return _accum_0
655 end)(), _obj_0[#_obj_0]
656end
657local _obj_0 = orders
658first, last = _obj_0[1], _obj_0[#_obj_0]
554local tuples = { 659local tuples = {
555 { 660 {
556 "hello", 661 "hello",
@@ -652,6 +757,56 @@ end)
652if success then 757if success then
653 print(result) 758 print(result)
654end 759end
760local a, b, c
761do
762 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
763 return func()
764 end)
765 if _ok_0 then
766 a, b, c = _ret_0, _ret_1, _ret_2
767 end
768end
769do
770 local _exp_0 = ((function()
771 return (function(_arg_0, ...)
772 local _ok_0 = _arg_0
773 if _ok_0 then
774 return ...
775 end
776 end)(pcall(function()
777 return func()
778 end))
779 end)())
780 if _exp_0 ~= nil then
781 a = _exp_0
782 else
783 a = "default"
784 end
785end
786f((function()
787 return (function(_arg_0, ...)
788 local _ok_0 = _arg_0
789 if _ok_0 then
790 return ...
791 end
792 end)(pcall(function()
793 return func()
794 end))
795end)())
796f((function()
797 return (function(_arg_0, ...)
798 local _ok_0 = _arg_0
799 if _ok_0 then
800 return ...
801 end
802 end)(xpcall(function()
803 print(123)
804 return func()
805 end, function(e)
806 print(e)
807 return e
808 end))
809end)())
655local a <const> = 123 810local a <const> = 123
656local _ <close> = setmetatable({ }, { 811local _ <close> = setmetatable({ }, {
657 __close = function() 812 __close = function()
@@ -661,10 +816,19 @@ local _ <close> = setmetatable({ }, {
661local a, b, c, d 816local a, b, c, d
662local _obj_0 = tb 817local _obj_0 = tb
663a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 818a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
819Constant = 123
664local some_string = "这是一个字符串\n 并包括一个换行。" 820local some_string = "这是一个字符串\n 并包括一个换行。"
665print("我有" .. tostring(math.random() * 100) .. "%的把握。") 821print("我有" .. tostring(math.random() * 100) .. "%的把握。")
666local integer = 1000000 822local integer = 1000000
667local hex = 0xEFBBBF 823local hex = 0xEFBBBF
824local binary = 19
825local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
826local fn
827fn = function()
828 local str = "foo:\n bar: baz"
829 return str
830end
831local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
668local my_function 832local my_function
669my_function = function() end 833my_function = function() end
670my_function() 834my_function()
@@ -753,6 +917,36 @@ if func(1, 2, 3, "你好", "世界") then
753 print("hello") 917 print("hello")
754 print("我在if内部") 918 print("我在if内部")
755end 919end
920local f1
921f1 = function(_arg_0)
922 local a, b, c
923 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
924 return print(a, b, c)
925end
926f1({
927 a = 1,
928 b = "2",
929 c = { }
930})
931local f2
932f2 = function(_arg_0, c)
933 local a1, b
934 a1, b = _arg_0.a, _arg_0.b
935 if a1 == nil then
936 a1 = 123
937 end
938 if b == nil then
939 b = 'abc'
940 end
941 if c == nil then
942 c = { }
943 end
944 return print(a1, b, c)
945end
946local arg1 = {
947 a = 0
948}
949f2(arg1, arg2)
756f(function() 950f(function()
757 return print("hello") 951 return print("hello")
758end) 952end)
@@ -858,11 +1052,10 @@ for i, item in ipairs(items) do
858 _len_0 = _len_0 + 1 1052 _len_0 = _len_0 + 1
859end 1053end
860doubled = _accum_0 1054doubled = _accum_0
861local iter = ipairs(items)
862local slice 1055local slice
863local _accum_0 = { } 1056local _accum_0 = { }
864local _len_0 = 1 1057local _len_0 = 1
865for i, item in iter do 1058for i, item in ipairs(items) do
866 if i > 1 and i < 3 then 1059 if i > 1 and i < 3 then
867 _accum_0[_len_0] = item 1060 _accum_0[_len_0] = item
868 _len_0 = _len_0 + 1 1061 _len_0 = _len_0 + 1
@@ -969,8 +1162,7 @@ local slice
969local _accum_0 = { } 1162local _accum_0 = { }
970local _len_0 = 1 1163local _len_0 = 1
971local _list_0 = items 1164local _list_0 = items
972local _max_0 = 5 1165for _index_0 = 1, 5 do
973for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
974 local item = _list_0[_index_0] 1166 local item = _list_0[_index_0]
975 _accum_0[_len_0] = item 1167 _accum_0[_len_0] = item
976 _len_0 = _len_0 + 1 1168 _len_0 = _len_0 + 1
@@ -980,7 +1172,8 @@ local slice
980local _accum_0 = { } 1172local _accum_0 = { }
981local _len_0 = 1 1173local _len_0 = 1
982local _list_0 = items 1174local _list_0 = items
983for _index_0 = 2, #_list_0 do 1175local _max_0 = #_list_0
1176for _index_0 = 2, _max_0 do
984 local item = _list_0[_index_0] 1177 local item = _list_0[_index_0]
985 _accum_0[_len_0] = item 1178 _accum_0[_len_0] = item
986 _len_0 = _len_0 + 1 1179 _len_0 = _len_0 + 1
@@ -990,12 +1183,46 @@ local slice
990local _accum_0 = { } 1183local _accum_0 = { }
991local _len_0 = 1 1184local _len_0 = 1
992local _list_0 = items 1185local _list_0 = items
993for _index_0 = 1, #_list_0, 2 do 1186local _max_0 = #_list_0
1187for _index_0 = 1, _max_0, 2 do
994 local item = _list_0[_index_0] 1188 local item = _list_0[_index_0]
995 _accum_0[_len_0] = item 1189 _accum_0[_len_0] = item
996 _len_0 = _len_0 + 1 1190 _len_0 = _len_0 + 1
997end 1191end
998slice = _accum_0 1192slice = _accum_0
1193local slice
1194local _accum_0 = { }
1195local _len_0 = 1
1196local _list_0 = items
1197local _min_0 = #_list_0 + -4 + 1
1198local _max_0 = #_list_0 + -1 + 1
1199for _index_0 = _min_0, _max_0 do
1200 local item = _list_0[_index_0]
1201 _accum_0[_len_0] = item
1202 _len_0 = _len_0 + 1
1203end
1204slice = _accum_0
1205local reverse_slice
1206local _accum_0 = { }
1207local _len_0 = 1
1208local _list_0 = items
1209local _min_0 = #_list_0 + -1 + 1
1210for _index_0 = _min_0, 1, -1 do
1211 local item = _list_0[_index_0]
1212 _accum_0[_len_0] = item
1213 _len_0 = _len_0 + 1
1214end
1215reverse_slice = _accum_0
1216local sub_list
1217local _accum_0 = { }
1218local _len_0 = 1
1219local _list_0 = items
1220for _index_0 = 2, 4 do
1221 local _item_0 = _list_0[_index_0]
1222 _accum_0[_len_0] = _item_0
1223 _len_0 = _len_0 + 1
1224end
1225sub_list = _accum_0
999for i = 10, 20 do 1226for i = 10, 20 do
1000 print(i) 1227 print(i)
1001end 1228end
@@ -1006,8 +1233,7 @@ for key, value in pairs(object) do
1006 print(key, value) 1233 print(key, value)
1007end 1234end
1008local _list_0 = items 1235local _list_0 = items
1009local _max_0 = 4 1236for _index_0 = 2, 4 do
1010for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1011 local item = _list_0[_index_0] 1237 local item = _list_0[_index_0]
1012 print(item) 1238 print(item)
1013end 1239end
@@ -1025,12 +1251,24 @@ local _len_0 = 1
1025for i = 1, 20 do 1251for i = 1, 20 do
1026 if i % 2 == 0 then 1252 if i % 2 == 0 then
1027 _accum_0[_len_0] = i * 2 1253 _accum_0[_len_0] = i * 2
1254 _len_0 = _len_0 + 1
1028 else 1255 else
1029 _accum_0[_len_0] = i 1256 _accum_0[_len_0] = i
1257 _len_0 = _len_0 + 1
1030 end 1258 end
1031 _len_0 = _len_0 + 1
1032end 1259end
1033doubled_evens = _accum_0 1260doubled_evens = _accum_0
1261local first_large
1262local _accum_0
1263local _list_0 = numbers
1264for _index_0 = 1, #_list_0 do
1265 local n = _list_0[_index_0]
1266 if n > 10 then
1267 _accum_0 = n
1268 break
1269 end
1270end
1271first_large = _accum_0
1034local func_a 1272local func_a
1035func_a = function() 1273func_a = function()
1036 for i = 1, 10 do 1274 for i = 1, 10 do
@@ -1179,7 +1417,7 @@ if "Robert" == name then
1179elseif "Dan" == name or "Daniel" == name then 1417elseif "Dan" == name or "Daniel" == name then
1180 print("你的名字是Dan") 1418 print("你的名字是Dan")
1181else 1419else
1182 print("我不知道你的名字") 1420 print("我不认识,你的名字" .. tostring(name))
1183end 1421end
1184local b = 1 1422local b = 1
1185local next_number 1423local next_number
@@ -1279,6 +1517,192 @@ if _tab_0 then
1279 end 1517 end
1280 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1518 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1281end 1519end
1520local _exp_0 = tb
1521local _type_0 = type(_exp_0)
1522local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1523local _match_0 = false
1524if _tab_0 then
1525 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1526 _match_0 = true
1527 print("1, 2, 3")
1528 end
1529end
1530if not _match_0 then
1531 local _match_1 = false
1532 if _tab_0 then
1533 local b = _exp_0[2]
1534 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1535 _match_1 = true
1536 print("1, " .. tostring(b) .. ", 3")
1537 end
1538 end
1539 if not _match_1 then
1540 if _tab_0 then
1541 local b = _exp_0[3]
1542 if b == nil then
1543 b = 3
1544 end
1545 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1546 print("1, 2, " .. tostring(b))
1547 end
1548 end
1549 end
1550end
1551local _exp_0 = tb
1552local _type_0 = type(_exp_0)
1553local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1554local _match_0 = false
1555if _tab_0 then
1556 local result = _exp_0.result
1557 if true == _exp_0.success and result ~= nil then
1558 _match_0 = true
1559 print("成功", result)
1560 end
1561end
1562if not _match_0 then
1563 local _match_1 = false
1564 if _tab_0 then
1565 if false == _exp_0.success then
1566 _match_1 = true
1567 print("失败", result)
1568 end
1569 end
1570 if not _match_1 then
1571 print("无效值")
1572 end
1573end
1574local _exp_0 = tb
1575local _type_0 = type(_exp_0)
1576local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1577local _match_0 = false
1578if _tab_0 then
1579 local content
1580 do
1581 local _obj_0 = _exp_0.data
1582 local _type_1 = type(_obj_0)
1583 if "table" == _type_1 or "userdata" == _type_1 then
1584 content = _obj_0.content
1585 end
1586 end
1587 local _val_0
1588 do
1589 local _obj_0 = _exp_0.data
1590 if _obj_0 ~= nil then
1591 _val_0 = _obj_0.type
1592 end
1593 end
1594 if "success" == _val_0 and content ~= nil then
1595 _match_0 = true
1596 print("成功", content)
1597 end
1598end
1599if not _match_0 then
1600 local _match_1 = false
1601 if _tab_0 then
1602 local content
1603 do
1604 local _obj_0 = _exp_0.data
1605 local _type_1 = type(_obj_0)
1606 if "table" == _type_1 or "userdata" == _type_1 then
1607 content = _obj_0.content
1608 end
1609 end
1610 local _val_0
1611 do
1612 local _obj_0 = _exp_0.data
1613 if _obj_0 ~= nil then
1614 _val_0 = _obj_0.type
1615 end
1616 end
1617 if "error" == _val_0 and content ~= nil then
1618 _match_1 = true
1619 print("失败", content)
1620 end
1621 end
1622 if not _match_1 then
1623 print("无效值")
1624 end
1625end
1626local _exp_0 = tb
1627local _type_0 = type(_exp_0)
1628local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1629if _tab_0 then
1630 local fourth = _exp_0[4]
1631 local _val_0
1632 do
1633 local _obj_0 = _exp_0[1]
1634 if _obj_0 ~= nil then
1635 _val_0 = _obj_0.a
1636 end
1637 end
1638 local _val_1
1639 do
1640 local _obj_0 = _exp_0[1]
1641 if _obj_0 ~= nil then
1642 _val_1 = _obj_0.b
1643 end
1644 end
1645 local _val_2
1646 do
1647 local _obj_0 = _exp_0[2]
1648 if _obj_0 ~= nil then
1649 _val_2 = _obj_0.a
1650 end
1651 end
1652 local _val_3
1653 do
1654 local _obj_0 = _exp_0[2]
1655 if _obj_0 ~= nil then
1656 _val_3 = _obj_0.b
1657 end
1658 end
1659 local _val_4
1660 do
1661 local _obj_0 = _exp_0[3]
1662 if _obj_0 ~= nil then
1663 _val_4 = _obj_0.a
1664 end
1665 end
1666 local _val_5
1667 do
1668 local _obj_0 = _exp_0[3]
1669 if _obj_0 ~= nil then
1670 _val_5 = _obj_0.b
1671 end
1672 end
1673 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
1674 print("匹配成功", fourth)
1675 end
1676end
1677local segments = {
1678 "admin",
1679 "users",
1680 "logs",
1681 "view"
1682}
1683local _type_0 = type(segments)
1684local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1685if _tab_0 then
1686 local groups
1687 do
1688 local _accum_0 = { }
1689 local _len_0 = 1
1690 local _max_0 = #segments + -3 + 1
1691 for _index_0 = 1, _max_0 do
1692 local _item_0 = segments[_index_0]
1693 _accum_0[_len_0] = _item_0
1694 _len_0 = _len_0 + 1
1695 end
1696 groups = _accum_0
1697 end
1698 local resource = segments[#segments - 1]
1699 local action = segments[#segments]
1700 if resource ~= nil and action ~= nil then
1701 print("Group:", groups)
1702 print("Resource:", resource)
1703 print("Action:", action)
1704 end
1705end
1282local Inventory 1706local Inventory
1283local _class_0 1707local _class_0
1284local _base_0 = { 1708local _base_0 = {
@@ -1935,6 +2359,10 @@ do
1935 _with_1["key-name"] = value 2359 _with_1["key-name"] = value
1936end 2360end
1937_with_0[#_with_0 + 1] = "abc" 2361_with_0[#_with_0 + 1] = "abc"
2362local _with_0 = obj
2363if _with_0 ~= nil then
2364 print(obj.name)
2365end
1938do 2366do
1939 local var = "hello" 2367 local var = "hello"
1940 print(var) 2368 print(var)
@@ -2025,6 +2453,38 @@ local inventory = {
2025 } 2453 }
2026 } 2454 }
2027} 2455}
2456local map
2457map = function(arr, action)
2458 local _accum_0 = { }
2459 local _len_0 = 1
2460 for _index_0 = 1, #arr do
2461 local item = arr[_index_0]
2462 _accum_0[_len_0] = action(item)
2463 _len_0 = _len_0 + 1
2464 end
2465 return _accum_0
2466end
2467local filter
2468filter = function(arr, cond)
2469 local _accum_0 = { }
2470 local _len_0 = 1
2471 for _index_0 = 1, #arr do
2472 local item = arr[_index_0]
2473 if cond(item) then
2474 _accum_0[_len_0] = item
2475 _len_0 = _len_0 + 1
2476 end
2477 end
2478 return _accum_0
2479end
2480local reduce
2481reduce = function(arr, init, action)
2482 for _index_0 = 1, #arr do
2483 local item = arr[_index_0]
2484 init = action(init, item)
2485 end
2486 return init
2487end
2028print(reduce(filter(map({ 2488print(reduce(filter(map({
2029 1, 2489 1,
2030 2, 2490 2,
@@ -2082,6 +2542,12 @@ end
2082print("yuescript") 2542print("yuescript")
2083print(3) 2543print(3)
2084print("有效的枚举类型:", "Static") 2544print("有效的枚举类型:", "Static")
2545do
2546 print(123, "hello")
2547end
2548do
2549 print(123, "hello")
2550end
2085if tb ~= nil then 2551if tb ~= nil then
2086 tb:func() 2552 tb:func()
2087end 2553end
@@ -2182,6 +2648,16 @@ for _key_0, _value_0 in pairs(b) do
2182 end 2648 end
2183end 2649end
2184merge = _tab_0 2650merge = _tab_0
2651local last
2652do
2653 local _item_0 = data.items
2654 last = _item_0[#_item_0]
2655end
2656local second_last
2657do
2658 local _item_0 = data.items
2659 second_last = _item_0[#_item_0 - 1]
2660end
2185local mt = { } 2661local mt = { }
2186local add 2662local add
2187add = function(self, right) 2663add = function(self, right)
@@ -2312,6 +2788,14 @@ func({
2312 2, 2788 2,
2313 3 2789 3
2314}) 2790})
2791local f
2792f = function()
2793 return {
2794 1,
2795 2,
2796 3
2797 }
2798end
2315local tb = { 2799local tb = {
2316 name = "abc", 2800 name = "abc",
2317 values = { 2801 values = {
@@ -2472,8 +2956,7 @@ local x = f()
2472local y = x 2956local y = x
2473local z = x 2957local z = x
2474do 2958do
2475 local a 2959 local a = 1
2476 a = 1
2477 local x, y, z 2960 local x, y, z
2478 print("预先声明后续所有变量为局部变量") 2961 print("预先声明后续所有变量为局部变量")
2479 x = function() 2962 x = function()
@@ -2483,8 +2966,7 @@ do
2483 instance = Item:new() 2966 instance = Item:new()
2484end 2967end
2485do 2968do
2486 local X 2969 local X = 1
2487 X = 1
2488 local B 2970 local B
2489 print("只预先声明后续大写的变量为局部变量") 2971 print("只预先声明后续大写的变量为局部变量")
2490 local a = 1 2972 local a = 1
@@ -2493,19 +2975,17 @@ end
2493do 2975do
2494 a = 1 2976 a = 1
2495 print("预先声明所有变量为全局变量") 2977 print("预先声明所有变量为全局变量")
2496 local x
2497 x = function() 2978 x = function()
2498 return 1 + y + z 2979 return 1 + y + z
2499 end 2980 end
2500 local y, z = 2, 3 2981 y, z = 2, 3
2501end 2982end
2502do 2983do
2503 x = 1 2984 x = 1
2504 print("只预先声明大写的变量为全局变量") 2985 print("只预先声明大写的变量为全局变量")
2505 local a = 1 2986 local a = 1
2506 local B = 2 2987 B = 2
2507 local Temp 2988 local Temp = "一个局部值"
2508 Temp = "一个局部值"
2509end 2989end
2510local thing = { 2990local thing = {
2511 1, 2991 1,
@@ -2556,6 +3036,59 @@ end
2556local two, four 3036local two, four
2557local _obj_0 = items 3037local _obj_0 = items
2558two, four = _obj_0[2], _obj_0[4] 3038two, four = _obj_0[2], _obj_0[4]
3039local orders = {
3040 "first",
3041 "second",
3042 "third",
3043 "fourth",
3044 "last"
3045}
3046local first, bulk, last = orders[1], (function()
3047 local _accum_0 = { }
3048 local _len_0 = 1
3049 local _max_0 = #orders + -2 + 1
3050 for _index_0 = 2, _max_0 do
3051 local _item_0 = orders[_index_0]
3052 _accum_0[_len_0] = _item_0
3053 _len_0 = _len_0 + 1
3054 end
3055 return _accum_0
3056end)(), orders[#orders]
3057print(first)
3058print(bulk)
3059print(last)
3060local first, rest
3061do
3062 local _obj_0 = orders
3063 first, rest = _obj_0[1], (function()
3064 local _accum_0 = { }
3065 local _len_0 = 1
3066 local _max_0 = #_obj_0
3067 for _index_0 = 2, _max_0 do
3068 local _item_0 = _obj_0[_index_0]
3069 _accum_0[_len_0] = _item_0
3070 _len_0 = _len_0 + 1
3071 end
3072 return _accum_0
3073 end)()
3074end
3075local start, last
3076do
3077 local _obj_0 = orders
3078 start, last = (function()
3079 local _accum_0 = { }
3080 local _len_0 = 1
3081 local _max_0 = #_obj_0 + -2 + 1
3082 for _index_0 = 1, _max_0 do
3083 local _item_0 = _obj_0[_index_0]
3084 _accum_0[_len_0] = _item_0
3085 _len_0 = _len_0 + 1
3086 end
3087 return _accum_0
3088 end)(), _obj_0[#_obj_0]
3089end
3090local _obj_0 = orders
3091first, last = _obj_0[1], _obj_0[#_obj_0]
2559local tuples = { 3092local tuples = {
2560 { 3093 {
2561 "hello", 3094 "hello",
@@ -2657,6 +3190,56 @@ end)
2657if success then 3190if success then
2658 print(result) 3191 print(result)
2659end 3192end
3193local a, b, c
3194do
3195 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3196 return func()
3197 end)
3198 if _ok_0 then
3199 a, b, c = _ret_0, _ret_1, _ret_2
3200 end
3201end
3202do
3203 local _exp_0 = ((function()
3204 return (function(_arg_0, ...)
3205 local _ok_0 = _arg_0
3206 if _ok_0 then
3207 return ...
3208 end
3209 end)(pcall(function()
3210 return func()
3211 end))
3212 end)())
3213 if _exp_0 ~= nil then
3214 a = _exp_0
3215 else
3216 a = "default"
3217 end
3218end
3219f((function()
3220 return (function(_arg_0, ...)
3221 local _ok_0 = _arg_0
3222 if _ok_0 then
3223 return ...
3224 end
3225 end)(pcall(function()
3226 return func()
3227 end))
3228end)())
3229f((function()
3230 return (function(_arg_0, ...)
3231 local _ok_0 = _arg_0
3232 if _ok_0 then
3233 return ...
3234 end
3235 end)(xpcall(function()
3236 print(123)
3237 return func()
3238 end, function(e)
3239 print(e)
3240 return e
3241 end))
3242end)())
2660local a <const> = 123 3243local a <const> = 123
2661local _ <close> = setmetatable({ }, { 3244local _ <close> = setmetatable({ }, {
2662 __close = function() 3245 __close = function()
@@ -2666,10 +3249,19 @@ local _ <close> = setmetatable({ }, {
2666local a, b, c, d 3249local a, b, c, d
2667local _obj_0 = tb 3250local _obj_0 = tb
2668a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3251a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3252Constant = 123
2669local some_string = "这是一个字符串\n 并包括一个换行。" 3253local some_string = "这是一个字符串\n 并包括一个换行。"
2670print("我有" .. tostring(math.random() * 100) .. "%的把握。") 3254print("我有" .. tostring(math.random() * 100) .. "%的把握。")
2671local integer = 1000000 3255local integer = 1000000
2672local hex = 0xEFBBBF 3256local hex = 0xEFBBBF
3257local binary = 19
3258local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3259local fn
3260fn = function()
3261 local str = "foo:\n bar: baz"
3262 return str
3263end
3264local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2673local my_function 3265local my_function
2674my_function = function() end 3266my_function = function() end
2675my_function() 3267my_function()
@@ -2758,6 +3350,66 @@ if func(1, 2, 3, "你好", "世界") then
2758 print("你好") 3350 print("你好")
2759 print("我在if内部") 3351 print("我在if内部")
2760end 3352end
3353local f1
3354f1 = function(_arg_0)
3355 local a, b, c
3356 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
3357 return print(a, b, c)
3358end
3359f1({
3360 a = 1,
3361 b = "2",
3362 c = { }
3363})
3364local f2
3365f2 = function(_arg_0, c)
3366 local a1, b
3367 a1, b = _arg_0.a, _arg_0.b
3368 if a1 == nil then
3369 a1 = 123
3370 end
3371 if b == nil then
3372 b = 'abc'
3373 end
3374 if c == nil then
3375 c = { }
3376 end
3377 return print(a1, b, c)
3378end
3379local arg1 = {
3380 a = 0
3381}
3382f2(arg1, arg2)
3383local findFirstEven
3384findFirstEven = function(list)
3385 for _index_0 = 1, #list do
3386 local item = list[_index_0]
3387 if type(item) == "table" then
3388 for _index_1 = 1, #item do
3389 local sub = item[_index_1]
3390 if sub % 2 == 0 then
3391 return sub
3392 end
3393 end
3394 end
3395 end
3396 return nil
3397end
3398local findFirstEven
3399findFirstEven = function(list)
3400 for _index_0 = 1, #list do
3401 local item = list[_index_0]
3402 if type(item) == "table" then
3403 for _index_1 = 1, #item do
3404 local sub = item[_index_1]
3405 if sub % 2 == 0 then
3406 return sub
3407 end
3408 end
3409 end
3410 end
3411 return nil
3412end
2761f(function() 3413f(function()
2762 return print("hello") 3414 return print("hello")
2763end) 3415end)
@@ -2863,11 +3515,10 @@ for i, item in ipairs(items) do
2863 _len_0 = _len_0 + 1 3515 _len_0 = _len_0 + 1
2864end 3516end
2865doubled = _accum_0 3517doubled = _accum_0
2866local iter = ipairs(items)
2867local slice 3518local slice
2868local _accum_0 = { } 3519local _accum_0 = { }
2869local _len_0 = 1 3520local _len_0 = 1
2870for i, item in iter do 3521for i, item in ipairs(items) do
2871 if i > 1 and i < 3 then 3522 if i > 1 and i < 3 then
2872 _accum_0[_len_0] = item 3523 _accum_0[_len_0] = item
2873 _len_0 = _len_0 + 1 3524 _len_0 = _len_0 + 1
@@ -2974,8 +3625,18 @@ local slice
2974local _accum_0 = { } 3625local _accum_0 = { }
2975local _len_0 = 1 3626local _len_0 = 1
2976local _list_0 = items 3627local _list_0 = items
2977local _max_0 = 5 3628for _index_0 = 1, 5 do
2978for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 3629 local item = _list_0[_index_0]
3630 _accum_0[_len_0] = item
3631 _len_0 = _len_0 + 1
3632end
3633slice = _accum_0
3634local slice
3635local _accum_0 = { }
3636local _len_0 = 1
3637local _list_0 = items
3638local _max_0 = #_list_0
3639for _index_0 = 2, _max_0 do
2979 local item = _list_0[_index_0] 3640 local item = _list_0[_index_0]
2980 _accum_0[_len_0] = item 3641 _accum_0[_len_0] = item
2981 _len_0 = _len_0 + 1 3642 _len_0 = _len_0 + 1
@@ -2985,7 +3646,8 @@ local slice
2985local _accum_0 = { } 3646local _accum_0 = { }
2986local _len_0 = 1 3647local _len_0 = 1
2987local _list_0 = items 3648local _list_0 = items
2988for _index_0 = 2, #_list_0 do 3649local _max_0 = #_list_0
3650for _index_0 = 1, _max_0, 2 do
2989 local item = _list_0[_index_0] 3651 local item = _list_0[_index_0]
2990 _accum_0[_len_0] = item 3652 _accum_0[_len_0] = item
2991 _len_0 = _len_0 + 1 3653 _len_0 = _len_0 + 1
@@ -2995,12 +3657,35 @@ local slice
2995local _accum_0 = { } 3657local _accum_0 = { }
2996local _len_0 = 1 3658local _len_0 = 1
2997local _list_0 = items 3659local _list_0 = items
2998for _index_0 = 1, #_list_0, 2 do 3660local _min_0 = #_list_0 + -4 + 1
3661local _max_0 = #_list_0 + -1 + 1
3662for _index_0 = _min_0, _max_0 do
2999 local item = _list_0[_index_0] 3663 local item = _list_0[_index_0]
3000 _accum_0[_len_0] = item 3664 _accum_0[_len_0] = item
3001 _len_0 = _len_0 + 1 3665 _len_0 = _len_0 + 1
3002end 3666end
3003slice = _accum_0 3667slice = _accum_0
3668local reverse_slice
3669local _accum_0 = { }
3670local _len_0 = 1
3671local _list_0 = items
3672local _min_0 = #_list_0 + -1 + 1
3673for _index_0 = _min_0, 1, -1 do
3674 local item = _list_0[_index_0]
3675 _accum_0[_len_0] = item
3676 _len_0 = _len_0 + 1
3677end
3678reverse_slice = _accum_0
3679local sub_list
3680local _accum_0 = { }
3681local _len_0 = 1
3682local _list_0 = items
3683for _index_0 = 2, 4 do
3684 local _item_0 = _list_0[_index_0]
3685 _accum_0[_len_0] = _item_0
3686 _len_0 = _len_0 + 1
3687end
3688sub_list = _accum_0
3004for i = 10, 20 do 3689for i = 10, 20 do
3005 print(i) 3690 print(i)
3006end 3691end
@@ -3011,8 +3696,7 @@ for key, value in pairs(object) do
3011 print(key, value) 3696 print(key, value)
3012end 3697end
3013local _list_0 = items 3698local _list_0 = items
3014local _max_0 = 4 3699for _index_0 = 2, 4 do
3015for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3016 local item = _list_0[_index_0] 3700 local item = _list_0[_index_0]
3017 print(item) 3701 print(item)
3018end 3702end
@@ -3030,12 +3714,24 @@ local _len_0 = 1
3030for i = 1, 20 do 3714for i = 1, 20 do
3031 if i % 2 == 0 then 3715 if i % 2 == 0 then
3032 _accum_0[_len_0] = i * 2 3716 _accum_0[_len_0] = i * 2
3717 _len_0 = _len_0 + 1
3033 else 3718 else
3034 _accum_0[_len_0] = i 3719 _accum_0[_len_0] = i
3720 _len_0 = _len_0 + 1
3035 end 3721 end
3036 _len_0 = _len_0 + 1
3037end 3722end
3038doubled_evens = _accum_0 3723doubled_evens = _accum_0
3724local first_large
3725local _accum_0
3726local _list_0 = numbers
3727for _index_0 = 1, #_list_0 do
3728 local n = _list_0[_index_0]
3729 if n > 10 then
3730 _accum_0 = n
3731 break
3732 end
3733end
3734first_large = _accum_0
3039local func_a 3735local func_a
3040func_a = function() 3736func_a = function()
3041 for i = 1, 10 do 3737 for i = 1, 10 do
@@ -3184,7 +3880,7 @@ if "Robert" == name then
3184elseif "Dan" == name or "Daniel" == name then 3880elseif "Dan" == name or "Daniel" == name then
3185 print("你的名字是Dan") 3881 print("你的名字是Dan")
3186else 3882else
3187 print("我不知道你的名字") 3883 print("我不认识,你的名字" .. tostring(name))
3188end 3884end
3189local b = 1 3885local b = 1
3190local next_number 3886local next_number
@@ -3284,6 +3980,192 @@ if _tab_0 then
3284 end 3980 end
3285 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3981 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3286end 3982end
3983local _exp_0 = tb
3984local _type_0 = type(_exp_0)
3985local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3986local _match_0 = false
3987if _tab_0 then
3988 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3989 _match_0 = true
3990 print("1, 2, 3")
3991 end
3992end
3993if not _match_0 then
3994 local _match_1 = false
3995 if _tab_0 then
3996 local b = _exp_0[2]
3997 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3998 _match_1 = true
3999 print("1, " .. tostring(b) .. ", 3")
4000 end
4001 end
4002 if not _match_1 then
4003 if _tab_0 then
4004 local b = _exp_0[3]
4005 if b == nil then
4006 b = 3
4007 end
4008 if 1 == _exp_0[1] and 2 == _exp_0[2] then
4009 print("1, 2, " .. tostring(b))
4010 end
4011 end
4012 end
4013end
4014local _exp_0 = tb
4015local _type_0 = type(_exp_0)
4016local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4017local _match_0 = false
4018if _tab_0 then
4019 local result = _exp_0.result
4020 if true == _exp_0.success and result ~= nil then
4021 _match_0 = true
4022 print("成功", result)
4023 end
4024end
4025if not _match_0 then
4026 local _match_1 = false
4027 if _tab_0 then
4028 if false == _exp_0.success then
4029 _match_1 = true
4030 print("失败", result)
4031 end
4032 end
4033 if not _match_1 then
4034 print("无效值")
4035 end
4036end
4037local _exp_0 = tb
4038local _type_0 = type(_exp_0)
4039local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4040local _match_0 = false
4041if _tab_0 then
4042 local content
4043 do
4044 local _obj_0 = _exp_0.data
4045 local _type_1 = type(_obj_0)
4046 if "table" == _type_1 or "userdata" == _type_1 then
4047 content = _obj_0.content
4048 end
4049 end
4050 local _val_0
4051 do
4052 local _obj_0 = _exp_0.data
4053 if _obj_0 ~= nil then
4054 _val_0 = _obj_0.type
4055 end
4056 end
4057 if "success" == _val_0 and content ~= nil then
4058 _match_0 = true
4059 print("成功", content)
4060 end
4061end
4062if not _match_0 then
4063 local _match_1 = false
4064 if _tab_0 then
4065 local content
4066 do
4067 local _obj_0 = _exp_0.data
4068 local _type_1 = type(_obj_0)
4069 if "table" == _type_1 or "userdata" == _type_1 then
4070 content = _obj_0.content
4071 end
4072 end
4073 local _val_0
4074 do
4075 local _obj_0 = _exp_0.data
4076 if _obj_0 ~= nil then
4077 _val_0 = _obj_0.type
4078 end
4079 end
4080 if "error" == _val_0 and content ~= nil then
4081 _match_1 = true
4082 print("失败", content)
4083 end
4084 end
4085 if not _match_1 then
4086 print("无效值")
4087 end
4088end
4089local _exp_0 = tb
4090local _type_0 = type(_exp_0)
4091local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4092if _tab_0 then
4093 local fourth = _exp_0[4]
4094 local _val_0
4095 do
4096 local _obj_0 = _exp_0[1]
4097 if _obj_0 ~= nil then
4098 _val_0 = _obj_0.a
4099 end
4100 end
4101 local _val_1
4102 do
4103 local _obj_0 = _exp_0[1]
4104 if _obj_0 ~= nil then
4105 _val_1 = _obj_0.b
4106 end
4107 end
4108 local _val_2
4109 do
4110 local _obj_0 = _exp_0[2]
4111 if _obj_0 ~= nil then
4112 _val_2 = _obj_0.a
4113 end
4114 end
4115 local _val_3
4116 do
4117 local _obj_0 = _exp_0[2]
4118 if _obj_0 ~= nil then
4119 _val_3 = _obj_0.b
4120 end
4121 end
4122 local _val_4
4123 do
4124 local _obj_0 = _exp_0[3]
4125 if _obj_0 ~= nil then
4126 _val_4 = _obj_0.a
4127 end
4128 end
4129 local _val_5
4130 do
4131 local _obj_0 = _exp_0[3]
4132 if _obj_0 ~= nil then
4133 _val_5 = _obj_0.b
4134 end
4135 end
4136 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
4137 print("匹配成功", fourth)
4138 end
4139end
4140local segments = {
4141 "admin",
4142 "users",
4143 "logs",
4144 "view"
4145}
4146local _type_0 = type(segments)
4147local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4148if _tab_0 then
4149 local groups
4150 do
4151 local _accum_0 = { }
4152 local _len_0 = 1
4153 local _max_0 = #segments + -3 + 1
4154 for _index_0 = 1, _max_0 do
4155 local _item_0 = segments[_index_0]
4156 _accum_0[_len_0] = _item_0
4157 _len_0 = _len_0 + 1
4158 end
4159 groups = _accum_0
4160 end
4161 local resource = segments[#segments - 1]
4162 local action = segments[#segments]
4163 if resource ~= nil and action ~= nil then
4164 print("Group:", groups)
4165 print("Resource:", resource)
4166 print("Action:", action)
4167 end
4168end
3287local Inventory 4169local Inventory
3288local _class_0 4170local _class_0
3289local _base_0 = { 4171local _base_0 = {
@@ -3940,6 +4822,10 @@ do
3940 _with_1["key-name"] = value 4822 _with_1["key-name"] = value
3941end 4823end
3942_with_0[#_with_0 + 1] = "abc" 4824_with_0[#_with_0 + 1] = "abc"
4825local _with_0 = obj
4826if _with_0 ~= nil then
4827 print(obj.name)
4828end
3943do 4829do
3944 local var = "hello" 4830 local var = "hello"
3945 print(var) 4831 print(var)
diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua
index 9a7c478..663bd44 100644
--- a/spec/outputs/comprehension.lua
+++ b/spec/outputs/comprehension.lua
@@ -243,8 +243,11 @@ end
243do 243do
244 local _accum_0 = { } 244 local _accum_0 = { }
245 local _len_0 = 1 245 local _len_0 = 1
246 local _min_0 = 1 + 2
246 local _max_0 = 3 + 4 247 local _max_0 = 3 + 4
247 for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do 248 _min_0 = _min_0 < 0 and #items + _min_0 + 1 or _min_0
249 _max_0 = _max_0 < 0 and #items + _max_0 + 1 or _max_0
250 for _index_0 = _min_0, _max_0 do
248 local item = items[_index_0] 251 local item = items[_index_0]
249 _accum_0[_len_0] = item 252 _accum_0[_len_0] = item
250 _len_0 = _len_0 + 1 253 _len_0 = _len_0 + 1
@@ -254,8 +257,11 @@ end
254do 257do
255 local _accum_0 = { } 258 local _accum_0 = { }
256 local _len_0 = 1 259 local _len_0 = 1
260 local _min_0 = hello() * 4
257 local _max_0 = 2 - thing[4] 261 local _max_0 = 2 - thing[4]
258 for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 or _max_0 do 262 _min_0 = _min_0 < 0 and #items + _min_0 + 1 or _min_0
263 _max_0 = _max_0 < 0 and #items + _max_0 + 1 or _max_0
264 for _index_0 = _min_0, _max_0 do
259 local item = items[_index_0] 265 local item = items[_index_0]
260 _accum_0[_len_0] = item 266 _accum_0[_len_0] = item
261 _len_0 = _len_0 + 1 267 _len_0 = _len_0 + 1
diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua
index 083419a..e194909 100644
--- a/spec/outputs/cond.lua
+++ b/spec/outputs/cond.lua
@@ -313,14 +313,12 @@ do
313 end 313 end
314end 314end
315do 315do
316 do 316 local _des_0 = { }
317 local _des_0 = { } 317 if _des_0 then
318 if _des_0 then 318 _M = _des_0
319 _M = _des_0 319 local Thing = _M.Thing
320 local Thing = _M.Thing 320 local _obj_0 = _M
321 local _obj_0 = _M 321 a, b = _obj_0.a, _obj_0.b
322 a, b = _obj_0.a, _obj_0.b
323 end
324 end 322 end
325end 323end
326do 324do
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua
index 44da58b..ba216b5 100644
--- a/spec/outputs/destructure.lua
+++ b/spec/outputs/destructure.lua
@@ -621,4 +621,94 @@ do
621 print(meta_field, abc, def) 621 print(meta_field, abc, def)
622 end 622 end
623end 623end
624do
625 local clients = {
626 "VIP_Alice",
627 "User_Bob",
628 "User_Clara",
629 "VIP_Eva"
630 }
631 local vipStart, regulars, vipEnd = clients[1], (function()
632 local _accum_0 = { }
633 local _len_0 = 1
634 local _max_0 = #clients + -2 + 1
635 for _index_0 = 2, _max_0 do
636 local _item_0 = clients[_index_0]
637 _accum_0[_len_0] = _item_0
638 _len_0 = _len_0 + 1
639 end
640 return _accum_0
641 end)(), clients[#clients]
642 print(vipStart)
643 print(regulars)
644 print(vipEnd)
645end
646do
647 local setupMeeting
648 setupMeeting = function(participants)
649 local chair, secretary = participants[1], participants[#participants]
650 return print(chair, secretary)
651 end
652 setupMeeting({
653 "Alice",
654 "Bob",
655 "Charlie",
656 "David"
657 })
658end
659do
660 local getTransactions
661 getTransactions = function()
662 return {
663 {
664 id = "T1",
665 amount = 100
666 },
667 {
668 id = "T2",
669 amount = 200
670 },
671 {
672 id = "T3",
673 amount = 300
674 }
675 }
676 end
677 local id, amount
678 do
679 local _item_0 = getTransactions()
680 local _obj_0 = _item_0[#_item_0]
681 id, amount = _obj_0.id, _obj_0.amount
682 end
683 assert(id == "T3")
684 assert(amount == 300)
685end
686do
687 local middle
688 local _accum_0 = { }
689 local _len_0 = 1
690 local _list_0 = tb
691 local _max_0 = #_list_0 + -2 + 1
692 for _index_0 = 2, _max_0 do
693 local _item_0 = _list_0[_index_0]
694 _accum_0[_len_0] = _item_0
695 _len_0 = _len_0 + 1
696 end
697 middle = _accum_0
698end
699do
700 local a, abc, b, def, sub, d, e
701 local _obj_0 = tb
702 a, abc, b, def, sub, d, e = _obj_0[1], _obj_0.abc, _obj_0[2], _obj_0.def, (function()
703 local _accum_0 = { }
704 local _len_0 = 1
705 local _max_0 = #_obj_0 + -3 + 1
706 for _index_0 = 3, _max_0 do
707 local _item_0 = _obj_0[_index_0]
708 _accum_0[_len_0] = _item_0
709 _len_0 = _len_0 + 1
710 end
711 return _accum_0
712 end)(), _obj_0[#_obj_0 - 1], _obj_0[#_obj_0]
713end
624return nil 714return nil
diff --git a/spec/outputs/do.lua b/spec/outputs/do.lua
index 6473e03..96d1022 100644
--- a/spec/outputs/do.lua
+++ b/spec/outputs/do.lua
@@ -32,10 +32,10 @@ local t = {
32} 32}
33return function(y, k) 33return function(y, k)
34 if y == nil then 34 if y == nil then
35 do 35 y = ((function()
36 x = 10 + 2 36 x = 10 + 2
37 y = x 37 return x
38 end 38 end)())
39 end 39 end
40 if k == nil then 40 if k == nil then
41 do 41 do
diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua
index c1735c4..db7ed67 100644
--- a/spec/outputs/funcs.lua
+++ b/spec/outputs/funcs.lua
@@ -283,4 +283,157 @@ do
283 end 283 end
284 print(func()) 284 print(func())
285end 285end
286local _anon_func_0 = function(_arg_0)
287 local _accum_0 = { }
288 local _len_0 = 1
289 local _max_0 = #_arg_0
290 for _index_0 = 1, _max_0 do
291 local _item_0 = _arg_0[_index_0]
292 _accum_0[_len_0] = _item_0
293 _len_0 = _len_0 + 1
294 end
295 return _accum_0
296end
297do
298 local f
299 f = function(_arg_0)
300 local a, b, c
301 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
302 return print(a, b, c)
303 end
304 f = function(_arg_0)
305 local a, b, c
306 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
307 return print(a, b, c)
308 end
309 local g
310 g = function(x, _arg_0)
311 local y
312 y = _arg_0.y
313 return print(x, y)
314 end
315 local i
316 i = function(_arg_0)
317 local ax, by
318 ax, by = _arg_0.a, _arg_0.b
319 if ax == nil then
320 ax = 0
321 end
322 if by == nil then
323 by = 0
324 end
325 return print(ax, by)
326 end
327 j = function(name, _arg_0)
328 local uid, role
329 uid, role = _arg_0.id, _arg_0.role
330 if uid == nil then
331 uid = "n/a"
332 end
333 if role == nil then
334 role = "guest"
335 end
336 return print(name, uid, role)
337 end
338 local m
339 m = function(_arg_0)
340 local name, age, ver
341 name, age, ver = _arg_0.user.name, _arg_0.user.age, _arg_0.meta.ver
342 if ver == nil then
343 ver = 1
344 end
345 return print(name, age, ver)
346 end
347 local m1
348 m1 = function(_arg_0)
349 local name, age, meta
350 name, age, meta = _arg_0.user.name, _arg_0.user.age, _arg_0.meta
351 if meta == nil then
352 meta = { }
353 end
354 return print(name, age, meta and meta.ver or "nil")
355 end
356 local new
357 new = function(self, _arg_0)
358 local name, age
359 name, age = _arg_0.name, _arg_0.age
360 if name == nil then
361 name = "anon"
362 end
363 if age == nil then
364 age = 0
365 end
366 self.name = name
367 self.age = age
368 end
369 local set
370 set = function(self, _arg_0)
371 local name, age
372 name, age = _arg_0.name, _arg_0.age
373 if name == nil then
374 name = self.name
375 end
376 if age == nil then
377 age = self.age
378 end
379 self.name = name
380 self.age = age
381 end
382 local logKV
383 logKV = function(_arg_0, ...)
384 local k, v
385 k, v = _arg_0.k, _arg_0.v
386 print("kv:", k, v)
387 return print("rest count:", select("#", ...))
388 end
389 do
390 local foo
391 foo = function(_arg_0)
392 local a, b
393 a, b = _arg_0.a, _arg_0.b
394 if b == nil then
395 b = 0
396 end
397 return print(a, b)
398 end
399 end
400 local t1
401 t1 = function(_arg_0, x)
402 local a
403 a = _arg_0.a
404 return print(a, x)
405 end
406 local t2
407 t2 = function(_arg_0)
408 local a
409 a = _arg_0.a
410 return print(a)
411 end
412 local w
413 w = function(id, _arg_0, _arg_1)
414 local x, y
415 x, y = _arg_0.x, _arg_0.y
416 if x == nil then
417 x = 0
418 end
419 if y == nil then
420 y = 0
421 end
422 local flag
423 flag = _arg_1.flag
424 return print(id, x, y, flag)
425 end
426 local g1
427 g1 = function(_arg_0)
428 local a, ax
429 a, ax = _arg_0.a, _arg_0.a
430 return print(a, ax)
431 end
432 local g4
433 g4 = function(_arg_0)
434 local a, b, rest
435 a, b, rest = _arg_0.a, _arg_0.b, _anon_func_0(_arg_0)
436 return print(a, b)
437 end
438end
286return nil 439return nil
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua
index 7e74387..3918f85 100644
--- a/spec/outputs/global.lua
+++ b/spec/outputs/global.lua
@@ -87,3 +87,34 @@ do
87 end 87 end
88 local h = 100 88 local h = 100
89end 89end
90do
91 x = y
92 local foobar = "all lowercase"
93 FooBar = "pascal case"
94 FOOBAR = "all uppercase"
95end
96do
97 do
98 local _class_0
99 local _base_0 = { }
100 if _base_0.__index == nil then
101 _base_0.__index = _base_0
102 end
103 _class_0 = setmetatable({
104 __init = function() end,
105 __base = _base_0,
106 __name = "A"
107 }, {
108 __index = _base_0,
109 __call = function(cls, ...)
110 local _self_0 = setmetatable({ }, _base_0)
111 cls.__init(_self_0, ...)
112 return _self_0
113 end
114 })
115 _base_0.__class = _class_0
116 A = _class_0
117 end
118 Flag = 1
119 const, x, y = "const", 1, 2
120end
diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua
index 83c99e2..7aa130f 100644
--- a/spec/outputs/import.lua
+++ b/spec/outputs/import.lua
@@ -166,3 +166,13 @@ do
166 local _obj_1 = require("m") 166 local _obj_1 = require("m")
167 g, i = _obj_1[1], getmetatable(_obj_1[2]).__close 167 g, i = _obj_1[1], getmetatable(_obj_1[2]).__close
168end 168end
169do
170 local require <const> = require
171 local stringlib <const> = string
172 local format <const> = string.format
173 local io_read <const> = io.read
174 local type
175 type = function() end
176 local tp <const> = _G.type
177 local yue <const> = _G["月"]
178end
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua
index 48ec9c8..2ed7b95 100644
--- a/spec/outputs/lists.lua
+++ b/spec/outputs/lists.lua
@@ -230,31 +230,36 @@ x = {
230 6, 230 6,
231 7 231 7
232} 232}
233local _max_0 = -5 233local _max_0 = #x + -5 + 1
234for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do 234for _index_0 = 2, _max_0, 2 do
235 local y = x[_index_0] 235 local y = x[_index_0]
236 print(y) 236 print(y)
237end 237end
238local _max_1 = 3 238for _index_0 = 1, 3 do
239for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do
240 local y = x[_index_0] 239 local y = x[_index_0]
241 print(y) 240 print(y)
242end 241end
243for _index_0 = 2, #x do 242local _max_1 = #x
243for _index_0 = 2, _max_1 do
244 local y = x[_index_0] 244 local y = x[_index_0]
245 print(y) 245 print(y)
246end 246end
247for _index_0 = 1, #x, 2 do 247local _max_2 = #x
248for _index_0 = 1, _max_2, 2 do
248 local y = x[_index_0] 249 local y = x[_index_0]
249 print(y) 250 print(y)
250end 251end
251for _index_0 = 2, #x, 2 do 252local _max_3 = #x
253for _index_0 = 2, _max_3, 2 do
252 local y = x[_index_0] 254 local y = x[_index_0]
253 print(y) 255 print(y)
254end 256end
255local a, b, c = 1, 5, 2 257local a, b, c = 1, 5, 2
256local _max_2 = b 258local _min_0 = a
257for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do 259local _max_4 = b
260_min_0 = _min_0 < 0 and #x + _min_0 + 1 or _min_0
261_max_4 = _max_4 < 0 and #x + _max_4 + 1 or _max_4
262for _index_0 = _min_0, _max_4, c do
258 local y = x[_index_0] 263 local y = x[_index_0]
259 print(y) 264 print(y)
260end 265end
@@ -287,7 +292,10 @@ do
287 a 292 a
288 }) 293 })
289 local _list_0 = f 294 local _list_0 = f
290 for _index_0 = a, #_list_0 do 295 local _min_1 = a
296 local _max_5 = #_list_0
297 _min_1 = _min_1 < 0 and #_list_0 + _min_1 + 1 or _min_1
298 for _index_0 = _min_1, _max_5 do
291 local v = _list_0[_index_0] 299 local v = _list_0[_index_0]
292 print(v) 300 print(v)
293 end 301 end
@@ -327,4 +335,191 @@ do
327 job = "jobless" 335 job = "jobless"
328 end 336 end
329end 337end
338do
339 local transactions = {
340 "T001",
341 "T002",
342 "T003",
343 "T004",
344 "T005"
345 }
346 local middleTransactions
347 do
348 local _accum_0 = { }
349 local _len_0 = 1
350 local _max_5 = #transactions + -2 + 1
351 for _index_0 = 2, _max_5 do
352 local _item_0 = transactions[_index_0]
353 _accum_0[_len_0] = _item_0
354 _len_0 = _len_0 + 1
355 end
356 middleTransactions = _accum_0
357 end
358 print(middleTransactions)
359end
360do
361 local logs = {
362 {
363 start = 0,
364 ["end"] = 100
365 },
366 {
367 start = 100,
368 ["end"] = 200
369 },
370 {
371 start = 200,
372 ["end"] = 123
373 }
374 }
375 print(logs[#logs]["end"])
376end
377do
378 local pendingOrders = {
379 "O001",
380 "O002",
381 "O003",
382 "O004"
383 }
384 print(pendingOrders[#pendingOrders - 1])
385end
386do
387 local getOrders
388 getOrders = function()
389 return {
390 {
391 id = "O1001",
392 status = "pending"
393 },
394 {
395 id = "O1002",
396 status = "processing"
397 },
398 {
399 id = "O1003",
400 status = "done"
401 }
402 }
403 end
404 local lastStatus
405 do
406 local _item_0 = getOrders()
407 lastStatus = _item_0[#_item_0].status
408 end
409 assert(lastStatus == "done")
410end
411do
412 local cloneList1
413 cloneList1 = function(list)
414 local _accum_0 = { }
415 local _len_0 = 1
416 local _max_5 = #list
417 for _index_0 = 1, _max_5 do
418 local _item_0 = list[_index_0]
419 _accum_0[_len_0] = _item_0
420 _len_0 = _len_0 + 1
421 end
422 return _accum_0
423 end
424 local cloneList2
425 cloneList2 = function(list)
426 local _tab_0 = { }
427 local _idx_0 = #_tab_0 + 1
428 for _index_0 = 1, #list do
429 local _value_0 = list[_index_0]
430 _tab_0[_idx_0] = _value_0
431 _idx_0 = _idx_0 + 1
432 end
433 return _tab_0
434 end
435 local cloneTable
436 cloneTable = function(tb)
437 local _tab_0 = { }
438 local _idx_0 = 1
439 for _key_0, _value_0 in pairs(tb) do
440 if _idx_0 == _key_0 then
441 _tab_0[#_tab_0 + 1] = _value_0
442 _idx_0 = _idx_0 + 1
443 else
444 _tab_0[_key_0] = _value_0
445 end
446 end
447 return _tab_0
448 end
449end
450do
451 print((function()
452 local _item_0 = globalTB
453 return _item_0[#_item_0]
454 end)(), (function()
455 local _item_0 = a.b.c
456 return _item_0[#_item_0 - 2]
457 end)(), (function()
458 if x ~= nil then
459 local _obj_0 = x.y
460 if _obj_0 ~= nil then
461 local _obj_1 = _obj_0(x).z
462 if _obj_1 ~= nil then
463 return _obj_1[#_obj_1 - 3]
464 end
465 return nil
466 end
467 return nil
468 end
469 return nil
470 end)())
471end
472local _anon_func_0 = function(globalTB)
473 local _item_0 = globalTB
474 local _call_0 = _item_0[#_item_0]
475 return _call_0["end"](_call_0, 123)
476end
477local _anon_func_1 = function(a)
478 local _item_0
479 do
480 local _accum_0 = { }
481 local _len_0 = 1
482 local _list_0 = a.b.c
483 local _max_5 = #_list_0 + -5 + 1
484 for _index_0 = 5, _max_5 do
485 local _item_1 = _list_0[_index_0]
486 _accum_0[_len_0] = _item_1
487 _len_0 = _len_0 + 1
488 end
489 _item_0 = _accum_0
490 end
491 return _item_0[#_item_0 - 2]
492end
493local _anon_func_2 = function(x)
494 if x ~= nil then
495 local _obj_0 = x.y
496 if _obj_0 ~= nil then
497 local _obj_1 = _obj_0(x).z
498 if _obj_1 ~= nil then
499 local _obj_2 = _obj_1[#_obj_1 - 3]
500 if _obj_2 ~= nil then
501 local _accum_0 = { }
502 local _len_0 = 1
503 local _max_5 = #_obj_2 + -3 + 1
504 for _index_0 = 1, _max_5 do
505 local _item_0 = _obj_2[_index_0]
506 _accum_0[_len_0] = _item_0
507 _len_0 = _len_0 + 1
508 end
509 return _accum_0
510 end
511 return nil
512 end
513 return nil
514 end
515 return nil
516 end
517 return nil
518end
519do
520 local f
521 f = function()
522 return print(_anon_func_0(globalTB), _anon_func_1(a), _anon_func_2(x))
523 end
524end
330return nil 525return nil
diff --git a/spec/outputs/literals.lua b/spec/outputs/literals.lua
index a578d58..6de5411 100644
--- a/spec/outputs/literals.lua
+++ b/spec/outputs/literals.lua
@@ -8,10 +8,18 @@ local _ = {
8 0xfF2323, 8 0xfF2323,
9 0xabcdef, 9 0xabcdef,
10 0xABCDEF, 10 0xABCDEF,
11 0XFBC400,
11 0x123p-123, 12 0x123p-123,
12 0xABCP+321, 13 0xABCP+321,
13 0x.1p-111, 14 0x.1p-111,
14 0xABCP-321, 15 0xABCP-321,
16 0x0.1E,
17 0xA23p-4,
18 0X1.921FB54442D18P+1,
19 1,
20 8,
21 15,
22 201,
15 .2323, 23 .2323,
16 .2323e-1, 24 .2323e-1,
17 .2323e13434, 25 .2323e13434,
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua
index 8624d49..6ab4bbb 100644
--- a/spec/outputs/loops.lua
+++ b/spec/outputs/loops.lua
@@ -60,8 +60,8 @@ do
60 local y = hello[_index_0] 60 local y = hello[_index_0]
61 if y % 2 == 0 then 61 if y % 2 == 0 then
62 _accum_0[_len_0] = y 62 _accum_0[_len_0] = y
63 _len_0 = _len_0 + 1
63 end 64 end
64 _len_0 = _len_0 + 1
65 end 65 end
66 x = _accum_0 66 x = _accum_0
67end 67end
@@ -132,13 +132,11 @@ do
132end 132end
133do 133do
134 local _accum_0 = { } 134 local _accum_0 = { }
135 local _len_0 = 1
136 local _list_2 = 3 135 local _list_2 = 3
137 for _index_0 = 1, #_list_2 do 136 for _index_0 = 1, #_list_2 do
138 local thing = _list_2[_index_0] 137 local thing = _list_2[_index_0]
139 y = "hello" 138 y = "hello"
140 break 139 break
141 _len_0 = _len_0 + 1
142 end 140 end
143 x = _accum_0 141 x = _accum_0
144end 142end
@@ -370,3 +368,131 @@ do
370 end 368 end
371 until false 369 until false
372end 370end
371local _anon_func_0 = function(i, tb)
372 local _accum_0 = { }
373 local _len_0 = 1
374 while tb[i] do
375 i = i + 1
376 _accum_0[_len_0] = i - 1
377 _len_0 = _len_0 + 1
378 end
379 return _accum_0
380end
381do
382 local index
383 do
384 local _accum_0
385 for i = 1, #tb do
386 if tb[i] then
387 _accum_0 = i
388 break
389 end
390 end
391 index = _accum_0
392 end
393 f((function()
394 local _accum_0
395 for i = 1, #tb do
396 if tb[i] then
397 _accum_0 = i
398 break
399 end
400 end
401 return _accum_0
402 end)())
403 f((function()
404 local _accum_0 = { }
405 local _len_0 = 1
406 for i = 1, #tb do
407 if tb[i] then
408 _accum_0[_len_0] = i
409 _len_0 = _len_0 + 1
410 end
411 end
412 return _accum_0
413 end)())
414 i = 1
415 local ids
416 do
417 local _accum_0 = { }
418 local _len_0 = 1
419 while tb[i] do
420 i = i + 1
421 _accum_0[_len_0] = i - 1
422 _len_0 = _len_0 + 1
423 end
424 ids = _accum_0
425 end
426 i = 1
427 local idx
428 do
429 local _accum_0
430 while tb[i] do
431 i = i + 1
432 _accum_0 = i - 1
433 break
434 end
435 idx = _accum_0
436 end
437 local f1
438 f1 = function()
439 i = 1
440 return f(_anon_func_0(i, tb))
441 end
442 i = 1
443 f((function()
444 local _accum_0
445 while tb[i] do
446 i = i + 1
447 _accum_0 = i - 1
448 break
449 end
450 return _accum_0
451 end)())
452 local _accum_0 = { }
453 local _len_0 = 1
454 local _list_3 = items
455 for _index_0 = 1, #_list_3 do
456 local item = _list_3[_index_0]
457 local _type_0 = type(item)
458 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
459 if _tab_0 then
460 local value = item.value
461 if "A" == item.type and value ~= nil then
462 if value > 5 then
463 _accum_0[_len_0] = item
464 _len_0 = _len_0 + 1
465 end
466 end
467 end
468 end
469 list = _accum_0
470end
471do
472 repeat
473 print(1)
474 until true
475 do
476 local _accum_0
477 repeat
478 a = func()
479 _accum_0 = a.x
480 break
481 until a.v
482 x = _accum_0
483 end
484 local items
485 local _accum_0 = { }
486 local _len_0 = 1
487 repeat
488 local item = getItem()
489 if not item then
490 break
491 end
492 if item.value > 0 then
493 _accum_0[_len_0] = item
494 _len_0 = _len_0 + 1
495 end
496 until false
497 items = _accum_0
498end
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua
index aa74ed9..89c6e63 100644
--- a/spec/outputs/macro.lua
+++ b/spec/outputs/macro.lua
@@ -26,6 +26,10 @@ print({
26 123, 26 123,
27 'xyz' 27 'xyz'
28}) 28})
29print({
30 456,
31 'abc'
32})
29do 33do
30 assert(item == nil) 34 assert(item == nil)
31end 35end
@@ -191,13 +195,11 @@ end
191do 195do
192 local a = 8 196 local a = 8
193 a = (function() 197 a = (function()
194 local a 198 local a = 1
195 a = 1
196 return a + 1 199 return a + 1
197 end)() 200 end)()
198 a = a + (function() 201 a = a + (function()
199 local a 202 local a = 1
200 a = 1
201 return a + 1 203 return a + 1
202 end)() 204 end)()
203 print(a) 205 print(a)
@@ -215,6 +217,13 @@ function tb:func()
215end 217end
216end 218end
217print(x) 219print(x)
220local yue = require("yue")
221do
222local function f2(a)
223 return a + 1
224end
225x = x + f2(3)
226end
218local sel 227local sel
219sel = function(a, b, c) 228sel = function(a, b, c)
220 if a then 229 if a then
@@ -274,18 +283,12 @@ local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()):
274end)):Destroy() 283end)):Destroy()
275do 284do
276 do 285 do
277 local _1 286 local _1 = origin.transform.root.gameObject:Parents()
278 _1 = origin.transform.root.gameObject:Parents() 287 local _2 = _1:Descendants()
279 local _2 288 local _3 = _2:SelectEnable()
280 _2 = _1:Descendants() 289 local _4 = _3:SelectVisible()
281 local _3 290 local _5 = _4:TagEqual("fx")
282 _3 = _2:SelectEnable() 291 local _6 = _5:Where(function(x)
283 local _4
284 _4 = _3:SelectVisible()
285 local _5
286 _5 = _4:TagEqual("fx")
287 local _6
288 _6 = _5:Where(function(x)
289 return x.name:EndsWith("(Clone)") 292 return x.name:EndsWith("(Clone)")
290 end) 293 end)
291 _6:Destroy() 294 _6:Destroy()
@@ -325,7 +328,7 @@ print((setmetatable({
325 return 998 328 return 998
326 end 329 end
327})) 330}))
328print("current line: " .. tostring(323)) 331print("current line: " .. tostring(349))
329do 332do
330 do 333 do
331-- TODO 334-- TODO
@@ -338,10 +341,8 @@ local _1
338_1 = function() 341_1 = function()
339 print(1) 342 print(1)
340 local _accum_0 = { } 343 local _accum_0 = { }
341 local _len_0 = 1
342 while false do 344 while false do
343 break 345 break
344 _len_0 = _len_0 + 1
345 end 346 end
346 return _accum_0 347 return _accum_0
347end 348end
diff --git a/spec/outputs/plus.lua b/spec/outputs/plus.lua
index bd89bfe..dda0660 100644
--- a/spec/outputs/plus.lua
+++ b/spec/outputs/plus.lua
@@ -65,7 +65,6 @@ backpack = {
65local start = { 65local start = {
66 something = "cold" 66 something = "cold"
67} 67}
68local bathe 68local bathe = {
69bathe = {
70 on = "fire" 69 on = "fire"
71} 70}
diff --git a/spec/outputs/props.lua b/spec/outputs/props.lua
new file mode 100644
index 0000000..2c282e0
--- /dev/null
+++ b/spec/outputs/props.lua
@@ -0,0 +1,240 @@
1local Props
2do
3 local _class_0
4 local assignReadOnly
5 local _base_0 = {
6 __index = function(self, name)
7 local cls = getmetatable(self)
8 do
9 local item
10 do
11 local _obj_0 = cls.__getter
12 if _obj_0 ~= nil then
13 item = _obj_0[name]
14 end
15 end
16 if item then
17 return item(self)
18 else
19 item = rawget(cls, name)
20 if item then
21 return item
22 else
23 local c = cls
24 repeat
25 c = getmetatable(c)
26 if c then
27 local _obj_0 = c.__getter
28 if _obj_0 ~= nil then
29 item = _obj_0[name]
30 end
31 if item then
32 if cls.__getter == nil then
33 cls.__getter = { }
34 end
35 cls.__getter[name] = item
36 return item(self)
37 else
38 item = rawget(c, name)
39 if item then
40 rawset(cls, name, item)
41 return item
42 end
43 end
44 else
45 break
46 end
47 until false
48 end
49 end
50 end
51 return nil
52 end,
53 __newindex = function(self, name, value)
54 local cls = getmetatable(self)
55 local item
56 local _obj_0 = cls.__setter
57 if _obj_0 ~= nil then
58 item = _obj_0[name]
59 end
60 if item then
61 return item(self, value)
62 else
63 local c = cls
64 repeat
65 c = getmetatable(c)
66 if c then
67 local _obj_1 = c.__setter
68 if _obj_1 ~= nil then
69 item = _obj_1[name]
70 end
71 if item then
72 if cls.__setter == nil then
73 cls.__setter = { }
74 end
75 cls.__setter[name] = item
76 item(self, value)
77 return
78 end
79 else
80 break
81 end
82 until false
83 return rawset(self, name, value)
84 end
85 end,
86 prop = function(self, name, props)
87 local get, set = props.get, props.set
88 if set == nil then
89 set = assignReadOnly
90 end
91 do
92 local getter = rawget(self.__base, "__getter")
93 if getter then
94 getter[name] = get
95 else
96 rawset(self.__base, "__getter", {
97 [name] = get
98 })
99 end
100 end
101 local setter = rawget(self.__base, "__setter")
102 if setter then
103 setter[name] = set
104 else
105 return rawset(self.__base, "__setter", {
106 [name] = set
107 })
108 end
109 end
110 }
111 if _base_0.__index == nil then
112 _base_0.__index = _base_0
113 end
114 _class_0 = setmetatable({
115 __init = function() end,
116 __base = _base_0,
117 __name = "Props"
118 }, {
119 __index = _base_0,
120 __call = function(cls, ...)
121 local _self_0 = setmetatable({ }, _base_0)
122 cls.__init(_self_0, ...)
123 return _self_0
124 end
125 })
126 _base_0.__class = _class_0
127 local self = _class_0;
128 assignReadOnly = function()
129 return error("assigning a readonly property")
130 end
131 Props = _class_0
132end
133local A
134do
135 local _class_0
136 local _parent_0 = Props
137 local _base_0 = { }
138 for _key_0, _val_0 in pairs(_parent_0.__base) do
139 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
140 _base_0[_key_0] = _val_0
141 end
142 end
143 if _base_0.__index == nil then
144 _base_0.__index = _base_0
145 end
146 setmetatable(_base_0, _parent_0.__base)
147 _class_0 = setmetatable({
148 __init = function(self)
149 self._x = 0
150 end,
151 __base = _base_0,
152 __name = "A",
153 __parent = _parent_0
154 }, {
155 __index = function(cls, name)
156 local val = rawget(_base_0, name)
157 if val == nil then
158 local parent = rawget(cls, "__parent")
159 if parent then
160 return parent[name]
161 end
162 else
163 return val
164 end
165 end,
166 __call = function(cls, ...)
167 local _self_0 = setmetatable({ }, _base_0)
168 cls.__init(_self_0, ...)
169 return _self_0
170 end
171 })
172 _base_0.__class = _class_0
173 local self = _class_0;
174 self:prop('x', {
175 get = function(self)
176 return self._x + 1000
177 end,
178 set = function(self, v)
179 self._x = v
180 end
181 })
182 if _parent_0.__inherited then
183 _parent_0.__inherited(_parent_0, _class_0)
184 end
185 A = _class_0
186end
187local B
188do
189 local _class_0
190 local _parent_0 = A
191 local _base_0 = { }
192 for _key_0, _val_0 in pairs(_parent_0.__base) do
193 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
194 _base_0[_key_0] = _val_0
195 end
196 end
197 if _base_0.__index == nil then
198 _base_0.__index = _base_0
199 end
200 setmetatable(_base_0, _parent_0.__base)
201 _class_0 = setmetatable({
202 __init = function(self, ...)
203 return _class_0.__parent.__init(self, ...)
204 end,
205 __base = _base_0,
206 __name = "B",
207 __parent = _parent_0
208 }, {
209 __index = function(cls, name)
210 local val = rawget(_base_0, name)
211 if val == nil then
212 local parent = rawget(cls, "__parent")
213 if parent then
214 return parent[name]
215 end
216 else
217 return val
218 end
219 end,
220 __call = function(cls, ...)
221 local _self_0 = setmetatable({ }, _base_0)
222 cls.__init(_self_0, ...)
223 return _self_0
224 end
225 })
226 _base_0.__class = _class_0
227 local self = _class_0;
228 self:prop('abc', {
229 get = function(self)
230 return "hello"
231 end
232 })
233 if _parent_0.__inherited then
234 _parent_0.__inherited(_parent_0, _class_0)
235 end
236 B = _class_0
237end
238local b = B()
239b.x = 999
240return print(b.x, b.abc)
diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua
index febea62..b536e6d 100644
--- a/spec/outputs/string.lua
+++ b/spec/outputs/string.lua
@@ -1,3 +1,4 @@
1local _module_0 = { }
1local hi = "hello" 2local hi = "hello"
2local hello = "what the heckyes" 3local hello = "what the heckyes"
3print(hi) 4print(hi)
@@ -41,4 +42,42 @@ local _ = "hello";
41("hello"):format().hello(1, 2, 3); 42("hello"):format().hello(1, 2, 3);
42("hello"):format(1, 2, 3) 43("hello"):format(1, 2, 3)
43something("hello"):world() 44something("hello"):world()
44return something(("hello"):world()) 45something(("hello"):world())
46do
47 local str = "key: value"
48 str = "config:\n\tenabled: true\n\tlevel: 5"
49 str = "header: start\nfooter: end"
50 str = "name: " .. tostring(username)
51 str = "count: " .. tostring(total) .. " items"
52 str = "user: " .. tostring(name) .. "\nid: " .. tostring(id)
53 str = "path: \"C:\\\\Program Files\\\\App\"\ndesc: 'single \"quote\" test'"
54 str = "key: value \nnext: 123 "
55 str = "list:\n - \"one\"\n - \"two\""
56 str = "-- comment\ncontent text\n-- comment"
57 str = tostring(1 + 2) .. '\n' .. tostring(2 + 3) .. '\n' .. tostring("a" .. "b")
58 local obj = {
59 settings = "mode: " .. tostring(mode) .. "\nflags:\n\t- " .. tostring(flag1) .. "\n\t- default"
60 }
61 local fn
62 fn = function()
63 return "Hello\nname: " .. tostring(userName)
64 end
65 str = "result:\n\tstatus: " .. tostring((function()
66 if ok then
67 return "pass"
68 else
69 return "fail"
70 end
71 end)()) .. "\n\tcode: " .. tostring(code)
72 local summary = "date: " .. tostring(os.date()) .. "\nvalues:\n\t-\n\t\ta: " .. tostring(aVal) .. "\n\t\tb: " .. tostring(bVal or defaultB)
73 local msg = send("Hello, " .. tostring(user) .. "!\nToday is " .. tostring(os.date("%A")) .. ".")
74 local desc
75 do
76 local prefix = "Result"
77 desc = tostring(prefix) .. ":\nvalue: " .. tostring(compute())
78 end
79 print(("1\n2\n3"))
80end
81local yaml = "version: " .. tostring(ver) .. "\nok: true"
82_module_0["yaml"] = yaml
83return _module_0
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua
index e4dedc9..7c1004b 100644
--- a/spec/outputs/switch.lua
+++ b/spec/outputs/switch.lua
@@ -415,4 +415,366 @@ do
415 end 415 end
416 end 416 end
417end 417end
418do
419 local _exp_0 = tb
420 local _type_0 = type(_exp_0)
421 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
422 local _match_0 = false
423 if _tab_0 then
424 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
425 _match_0 = true
426 print("1, 2, 3")
427 end
428 end
429 if not _match_0 then
430 local _match_1 = false
431 if _tab_0 then
432 local b = _exp_0[2]
433 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
434 _match_1 = true
435 print("1, " .. tostring(b) .. ", 3")
436 end
437 end
438 if not _match_1 then
439 if _tab_0 then
440 local b = _exp_0[3]
441 if b == nil then
442 b = 3
443 end
444 if 1 == _exp_0[1] and 2 == _exp_0[2] then
445 print("1, 2, " .. tostring(b))
446 end
447 end
448 end
449 end
450end
451do
452 local _exp_0 = tb
453 local _type_0 = type(_exp_0)
454 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
455 local _match_0 = false
456 if _tab_0 then
457 local result = _exp_0.result
458 if true == _exp_0.success and result ~= nil then
459 _match_0 = true
460 print("success", result)
461 end
462 end
463 if not _match_0 then
464 local _match_1 = false
465 if _tab_0 then
466 if false == _exp_0.success then
467 _match_1 = true
468 print("failed", result)
469 end
470 end
471 if not _match_1 then
472 print("invalid")
473 end
474 end
475end
476do
477 local _exp_0 = tb
478 local _type_0 = type(_exp_0)
479 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
480 local _match_0 = false
481 if _tab_0 then
482 local content = _exp_0.content
483 if "success" == _exp_0.type and content ~= nil then
484 _match_0 = true
485 print("success", content)
486 end
487 end
488 if not _match_0 then
489 local _match_1 = false
490 if _tab_0 then
491 local content = _exp_0.content
492 if "error" == _exp_0.type and content ~= nil then
493 _match_1 = true
494 print("failed", content)
495 end
496 end
497 if not _match_1 then
498 print("invalid")
499 end
500 end
501end
502do
503 do
504 local _exp_0 = tb
505 local _type_0 = type(_exp_0)
506 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
507 if _tab_0 then
508 local fourth = _exp_0[4]
509 local _val_0
510 do
511 local _obj_0 = _exp_0[1]
512 if _obj_0 ~= nil then
513 _val_0 = _obj_0.a
514 end
515 end
516 local _val_1
517 do
518 local _obj_0 = _exp_0[1]
519 if _obj_0 ~= nil then
520 _val_1 = _obj_0.b
521 end
522 end
523 local _val_2
524 do
525 local _obj_0 = _exp_0[2]
526 if _obj_0 ~= nil then
527 _val_2 = _obj_0.a
528 end
529 end
530 local _val_3
531 do
532 local _obj_0 = _exp_0[2]
533 if _obj_0 ~= nil then
534 _val_3 = _obj_0.b
535 end
536 end
537 local _val_4
538 do
539 local _obj_0 = _exp_0[3]
540 if _obj_0 ~= nil then
541 _val_4 = _obj_0.a
542 end
543 end
544 local _val_5
545 do
546 local _obj_0 = _exp_0[3]
547 if _obj_0 ~= nil then
548 _val_5 = _obj_0.b
549 end
550 end
551 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
552 print("matched", fourth)
553 end
554 end
555 end
556 local _exp_0 = tb
557 local _type_0 = type(_exp_0)
558 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
559 local _match_0 = false
560 if _tab_0 then
561 local _val_0
562 do
563 local _obj_0 = _exp_0[1]
564 if _obj_0 ~= nil then
565 _val_0 = _obj_0.c
566 end
567 end
568 local _val_1
569 do
570 local _obj_0 = _exp_0[1]
571 if _obj_0 ~= nil then
572 _val_1 = _obj_0.d
573 end
574 end
575 local _val_2
576 do
577 local _obj_0 = _exp_0[2]
578 if _obj_0 ~= nil then
579 _val_2 = _obj_0.c
580 end
581 end
582 local _val_3
583 do
584 local _obj_0 = _exp_0[2]
585 if _obj_0 ~= nil then
586 _val_3 = _obj_0.d
587 end
588 end
589 local _val_4
590 do
591 local _obj_0 = _exp_0[3]
592 if _obj_0 ~= nil then
593 _val_4 = _obj_0.c
594 end
595 end
596 local _val_5
597 do
598 local _obj_0 = _exp_0[3]
599 if _obj_0 ~= nil then
600 _val_5 = _obj_0.d
601 end
602 end
603 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 then
604 _match_0 = true
605 print("OK")
606 end
607 end
608 if not _match_0 then
609 if _tab_0 then
610 local sixth = _exp_0[6]
611 local _val_0
612 do
613 local _obj_0 = _exp_0[3]
614 if _obj_0 ~= nil then
615 _val_0 = _obj_0.a
616 end
617 end
618 local _val_1
619 do
620 local _obj_0 = _exp_0[3]
621 if _obj_0 ~= nil then
622 _val_1 = _obj_0.b
623 end
624 end
625 local _val_2
626 do
627 local _obj_0 = _exp_0[4]
628 if _obj_0 ~= nil then
629 _val_2 = _obj_0.a
630 end
631 end
632 local _val_3
633 do
634 local _obj_0 = _exp_0[4]
635 if _obj_0 ~= nil then
636 _val_3 = _obj_0.b
637 end
638 end
639 local _val_4
640 do
641 local _obj_0 = _exp_0[5]
642 if _obj_0 ~= nil then
643 _val_4 = _obj_0.a
644 end
645 end
646 local _val_5
647 do
648 local _obj_0 = _exp_0[5]
649 if _obj_0 ~= nil then
650 _val_5 = _obj_0.b
651 end
652 end
653 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and sixth ~= nil then
654 print("matched", sixth)
655 end
656 end
657 end
658end
659do
660 local v = "hello"
661 if "hello" == v then
662 print("matched hello")
663 else
664 print("not matched")
665 end
666end
667do
668 local f
669 f = function()
670 return "ok"
671 end
672 local val = f()
673 if "ok" == val then
674 print("it's ok")
675 end
676end
677do
678 local g
679 g = function()
680 return 42
681 end
682 local result = g()
683 if 1 == result or 2 == result then
684 print("small")
685 elseif 42 == result then
686 print("life universe everything")
687 else
688 print("other " .. tostring(result))
689 end
690end
691do
692 local check
693 check = function()
694 if true then
695 return "yes"
696 else
697 return "no"
698 end
699 end
700 local x = check()
701 if "yes" == x then
702 print("affirmative")
703 else
704 print("negative")
705 end
706end
707do
708 local t
709 t = function()
710 local tb = {
711 a = 1
712 }
713 tb.a = 2
714 return tb
715 end
716 local data = t()
717 local _type_0 = type(data)
718 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
719 local _match_0 = false
720 if _tab_0 then
721 if 2 == data.a then
722 _match_0 = true
723 print("matched")
724 end
725 end
726 if not _match_0 then
727 print("not matched")
728 end
729end
730do
731 local clientData = {
732 "Meta",
733 "CUST_1001",
734 "CHK123"
735 }
736 local _type_0 = type(clientData)
737 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
738 if _tab_0 then
739 local metadata
740 do
741 local _accum_0 = { }
742 local _len_0 = 1
743 local _max_0 = #clientData + -3 + 1
744 for _index_0 = 1, _max_0 do
745 local _item_0 = clientData[_index_0]
746 _accum_0[_len_0] = _item_0
747 _len_0 = _len_0 + 1
748 end
749 metadata = _accum_0
750 end
751 local customerId = clientData[#clientData - 1]
752 local checksum = clientData[#clientData]
753 if customerId ~= nil and checksum ~= nil then
754 print(metadata)
755 print(customerId)
756 print(checksum)
757 end
758 end
759end
760do
761 local handlePath
762 handlePath = function(segments)
763 local _type_0 = type(segments)
764 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
765 if _tab_0 then
766 local resource = segments[#segments - 1]
767 local action = segments[#segments]
768 if resource ~= nil and action ~= nil then
769 print("Resource:", resource)
770 return print("Action:", action)
771 end
772 end
773 end
774 handlePath({
775 "admin",
776 "logs",
777 "view"
778 })
779end
418return nil 780return nil
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua
index 5fd1821..040a325 100644
--- a/spec/outputs/syntax.lua
+++ b/spec/outputs/syntax.lua
@@ -239,9 +239,11 @@ x = 0
239local _list_0 = values 239local _list_0 = values
240for _index_0 = 1, #_list_0 do 240for _index_0 = 1, #_list_0 do
241 local v = _list_0[_index_0] 241 local v = _list_0[_index_0]
242 if ntype(v) == "fndef" then 242 _ = ((function()
243 _ = x + 1 243 if ntype(v) == "fndef" then
244 end 244 return x + 1
245 end
246 end)())
245end 247end
246hello = { 248hello = {
247 something = world, 249 something = world,
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua
index f358811..3f851de 100644
--- a/spec/outputs/tables.lua
+++ b/spec/outputs/tables.lua
@@ -366,6 +366,28 @@ local menus = {
366 } 366 }
367 } 367 }
368} 368}
369_ = {
370 boolean = {
371 true,
372 false
373 },
374 float = {
375 3.14,
376 -6.8523015e+5
377 },
378 int = {
379 123,
380 -685230
381 },
382 null = {
383 nodeName = 'node',
384 parent = nil
385 },
386 string = {
387 'Hello world',
388 "newline\nnewline2"
389 }
390}
369local tb 391local tb
370do 392do
371 local _tab_0 = { } 393 local _tab_0 = { }
diff --git a/spec/outputs/try_catch.lua b/spec/outputs/try_catch.lua
index d4c80c1..edb2341 100644
--- a/spec/outputs/try_catch.lua
+++ b/spec/outputs/try_catch.lua
@@ -8,10 +8,10 @@ local _anon_func_2 = function(tb)
8 return tb.func() 8 return tb.func()
9end 9end
10local _anon_func_3 = function(tb) 10local _anon_func_3 = function(tb)
11 return tb.func() 11 return (tb.func())
12end 12end
13local _anon_func_4 = function(tb) 13local _anon_func_4 = function(tb)
14 return tb:func(1, 2, 3) 14 return (tb:func(1, 2, 3))
15end 15end
16local _anon_func_5 = function(tb) 16local _anon_func_5 = function(tb)
17 return tb.func(1) 17 return tb.func(1)
@@ -22,6 +22,44 @@ end
22local _anon_func_7 = function(a, b, c, tb) 22local _anon_func_7 = function(a, b, c, tb)
23 return tb.f(a, b, c) 23 return tb.f(a, b, c)
24end 24end
25local _anon_func_8 = function(_arg_0, ...)
26 local ok = _arg_0
27 return ...
28end
29local _anon_func_10 = function(_arg_0, ...)
30 local _ok_0 = _arg_0
31 if _ok_0 then
32 return ...
33 end
34end
35local _anon_func_9 = function(func, pcall)
36 return _anon_func_10(pcall(func))
37end
38local _anon_func_12 = function(_arg_0, ...)
39 local _ok_0 = _arg_0
40 if _ok_0 then
41 return ...
42 end
43end
44local _anon_func_11 = function(func, pcall)
45 return _anon_func_12(pcall(func))
46end
47local _anon_func_14 = function(_arg_0, ...)
48 local _ok_0 = _arg_0
49 if _ok_0 then
50 return ...
51 end
52end
53local _anon_func_15 = function(func, print)
54 print(123)
55 return func()
56end
57local _anon_func_13 = function(func, print, xpcall)
58 return _anon_func_14(xpcall(_anon_func_15, function(e)
59 print(e)
60 return e
61 end, func, print))
62end
25local f 63local f
26f = function() 64f = function()
27 xpcall(function() 65 xpcall(function()
@@ -64,7 +102,7 @@ f = function()
64 print("OK") 102 print("OK")
65 end 103 end
66 if xpcall(function() 104 if xpcall(function()
67 return func(1) 105 return (func(1))
68 end, function(err) 106 end, function(err)
69 return print(err) 107 return print(err)
70 end) then 108 end) then
@@ -104,10 +142,236 @@ f = function()
104 do 142 do
105 x(function() 143 x(function()
106 local tb, a, b, c 144 local tb, a, b, c
107 f = function() 145 local f1
146 f1 = function()
108 return pcall(_anon_func_7, a, b, c, tb) 147 return pcall(_anon_func_7, a, b, c, tb)
109 end 148 end
110 end) 149 end)
111 end 150 end
151 do
152 local f1
153 f1 = function()
154 do
155 return _anon_func_8(pcall(function()
156 return func()
157 end))
158 end
159 end
160 end
161 do
162 local func
163 local a, b, c
164 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
165 if _ok_0 then
166 a, b, c = _ret_0, _ret_1, _ret_2
167 end
168 end
169 do
170 local a, b, c
171 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
172 return func()
173 end)
174 if _ok_0 then
175 a, b, c = _ret_0, _ret_1, _ret_2
176 end
177 end
178 do
179 local a
180 local _exp_0 = (_anon_func_9(func, pcall))
181 if _exp_0 ~= nil then
182 a = _exp_0
183 else
184 a = "default"
185 end
186 end
187 do
188 f(_anon_func_11(func, pcall))
189 end
190 do
191 f(_anon_func_13(func, print, xpcall))
192 end
112 return nil 193 return nil
113end 194end
195local _anon_func_16 = function(a, b, c, tb)
196 return tb.f(a, b, c)
197end
198local _anon_func_17 = function(_arg_0, ...)
199 local ok = _arg_0
200 return ...
201end
202do
203 xpcall(function()
204 return func(1, 2, 3)
205 end, function(err)
206 return print(err)
207 end)
208 xpcall(function()
209 return func(1, 2, 3)
210 end, function(err)
211 return print(err)
212 end)
213 pcall(function()
214 print("trying")
215 return func(1, 2, 3)
216 end)
217 do
218 local success, result = xpcall(function()
219 return func(1, 2, 3)
220 end, function(err)
221 return print(err)
222 end)
223 success, result = pcall(function()
224 return func(1, 2, 3)
225 end)
226 end
227 local tb = { }
228 pcall(function()
229 return tb.func
230 end)
231 pcall(function()
232 return tb.func()
233 end)
234 pcall(function()
235 return tb.func()
236 end)
237 pcall(function()
238 return (tb.func())
239 end)
240 pcall(function()
241 return (tb:func(1, 2, 3))
242 end)
243 pcall(function()
244 return tb.func(1)
245 end)
246 pcall(function()
247 return tb.func(1)
248 end)
249 if (xpcall(function()
250 return func(1)
251 end, function(err)
252 return print(err)
253 end)) then
254 print("OK")
255 end
256 if xpcall(function()
257 return (func(1))
258 end, function(err)
259 return print(err)
260 end) then
261 print("OK")
262 end
263 do
264 do
265 local success, result = pcall(function()
266 return func("abc", 123)
267 end)
268 if success then
269 print(result)
270 end
271 end
272 local success, result = xpcall(function()
273 return func("abc", 123)
274 end, function(err)
275 return print(err)
276 end)
277 success, result = xpcall(function()
278 return func("abc", 123)
279 end, function(err)
280 return print(err)
281 end)
282 if success then
283 print(result)
284 end
285 end
286 do
287 pcall(function()
288 return func(1, 2, 3)
289 end)
290 pcall(function()
291 return func(1, 2, 3)
292 end)
293 end
294 do
295 x(function()
296 local tb, a, b, c
297 local f1
298 f1 = function()
299 return pcall(_anon_func_16, a, b, c, tb)
300 end
301 end)
302 end
303 do
304 local f1
305 f1 = function()
306 do
307 return _anon_func_17(pcall(function()
308 return func()
309 end))
310 end
311 end
312 end
313 do
314 local func
315 local a, b, c
316 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
317 if _ok_0 then
318 a, b, c = _ret_0, _ret_1, _ret_2
319 end
320 end
321 do
322 local a, b, c
323 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
324 return func()
325 end)
326 if _ok_0 then
327 a, b, c = _ret_0, _ret_1, _ret_2
328 end
329 end
330 do
331 local a
332 local _exp_0 = ((function()
333 return (function(_arg_0, ...)
334 local _ok_0 = _arg_0
335 if _ok_0 then
336 return ...
337 end
338 end)(pcall(function()
339 return func()
340 end))
341 end)())
342 if _exp_0 ~= nil then
343 a = _exp_0
344 else
345 a = "default"
346 end
347 end
348 do
349 f((function()
350 return (function(_arg_0, ...)
351 local _ok_0 = _arg_0
352 if _ok_0 then
353 return ...
354 end
355 end)(pcall(function()
356 return func()
357 end))
358 end)())
359 end
360 do
361 f((function()
362 return (function(_arg_0, ...)
363 local _ok_0 = _arg_0
364 if _ok_0 then
365 return ...
366 end
367 end)(xpcall(function()
368 print(123)
369 return func()
370 end, function(e)
371 print(e)
372 return e
373 end))
374 end)())
375 end
376end
377return nil
diff --git a/spec/outputs/unicode/assign.lua b/spec/outputs/unicode/assign.lua
index bf43953..e00d016 100644
--- a/spec/outputs/unicode/assign.lua
+++ b/spec/outputs/unicode/assign.lua
@@ -36,17 +36,15 @@ local _u53d8_u91cfx
36do 36do
37 local _u51fd_u6570 = _u83b7_u53d6_u5904_u7406_u51fd_u6570() 37 local _u51fd_u6570 = _u83b7_u53d6_u5904_u7406_u51fd_u6570()
38 if _u51fd_u6570 then 38 if _u51fd_u6570 then
39 do 39 _u53d8_u91cfx = ((function()
40 _u51fd_u6570() 40 _u51fd_u6570()
41 _u53d8_u91cfx = 123 41 return 123
42 end 42 end)())
43 end 43 end
44end 44end
45local _anon_func_0 = function(_u6253_u5370) 45local _anon_func_0 = function(_u6253_u5370)
46 do 46 _u6253_u5370(123)
47 _u6253_u5370(123) 47 return { }
48 return { }
49 end
50end 48end
51return __u65e0_u6548_u53d8_u91cf(function() 49return __u65e0_u6548_u53d8_u91cf(function()
52 setmetatable(a_u53d8_u91cf, _anon_func_0(_u6253_u5370)) 50 setmetatable(a_u53d8_u91cf, _anon_func_0(_u6253_u5370))
diff --git a/spec/outputs/unicode/attrib.lua b/spec/outputs/unicode/attrib.lua
index 1c48de4..5e5bb99 100644
--- a/spec/outputs/unicode/attrib.lua
+++ b/spec/outputs/unicode/attrib.lua
@@ -48,17 +48,21 @@ do
48 end 48 end
49 local _u5173_u95ed_u53d8_u91cfb 49 local _u5173_u95ed_u53d8_u91cfb
50 if not false then 50 if not false then
51 if _u6761_u4ef6x then 51 _u5173_u95ed_u53d8_u91cfb = ((function()
52 _u5173_u95ed_u53d8_u91cfb = 1 52 if _u6761_u4ef6x then
53 end 53 return 1
54 end
55 end)())
54 end 56 end
55 local _close_0 <close> = _u5173_u95ed_u53d8_u91cfb 57 local _close_0 <close> = _u5173_u95ed_u53d8_u91cfb
56 local _u5e38_u91cfc 58 local _u5e38_u91cfc
57 if true then 59 if true then
58 local _exp_0 = _u6761_u4ef6x 60 _u5e38_u91cfc = ((function()
59 if "abc" == _exp_0 then 61 local _exp_0 = _u6761_u4ef6x
60 _u5e38_u91cfc = 998 62 if "abc" == _exp_0 then
61 end 63 return 998
64 end
65 end)())
62 end 66 end
63 local _u5173_u95ed_u53d8_u91cfd 67 local _u5173_u95ed_u53d8_u91cfd
64 if (function() 68 if (function()
diff --git a/spec/outputs/unicode/comprehension.lua b/spec/outputs/unicode/comprehension.lua
index 60e490f..92bce69 100644
--- a/spec/outputs/unicode/comprehension.lua
+++ b/spec/outputs/unicode/comprehension.lua
@@ -243,8 +243,11 @@ end
243do 243do
244 local _accum_0 = { } 244 local _accum_0 = { }
245 local _len_0 = 1 245 local _len_0 = 1
246 local _min_0 = 1 + 2
246 local _max_0 = 3 + 4 247 local _max_0 = 3 + 4
247 for _index_0 = 1 + 2, _max_0 < 0 and #_u5217_u8868 + _max_0 or _max_0 do 248 _min_0 = _min_0 < 0 and #_u5217_u8868 + _min_0 + 1 or _min_0
249 _max_0 = _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0
250 for _index_0 = _min_0, _max_0 do
248 local _u9879_u76ee = _u5217_u8868[_index_0] 251 local _u9879_u76ee = _u5217_u8868[_index_0]
249 _accum_0[_len_0] = _u9879_u76ee 252 _accum_0[_len_0] = _u9879_u76ee
250 _len_0 = _len_0 + 1 253 _len_0 = _len_0 + 1
@@ -254,8 +257,11 @@ end
254do 257do
255 local _accum_0 = { } 258 local _accum_0 = { }
256 local _len_0 = 1 259 local _len_0 = 1
260 local _min_0 = _u4f60_u597d() * 4
257 local _max_0 = 2 - _u4e1c_u897f[4] 261 local _max_0 = 2 - _u4e1c_u897f[4]
258 for _index_0 = _u4f60_u597d() * 4, _max_0 < 0 and #_u5217_u8868 + _max_0 or _max_0 do 262 _min_0 = _min_0 < 0 and #_u5217_u8868 + _min_0 + 1 or _min_0
263 _max_0 = _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0
264 for _index_0 = _min_0, _max_0 do
259 local _u9879_u76ee = _u5217_u8868[_index_0] 265 local _u9879_u76ee = _u5217_u8868[_index_0]
260 _accum_0[_len_0] = _u9879_u76ee 266 _accum_0[_len_0] = _u9879_u76ee
261 _len_0 = _len_0 + 1 267 _len_0 = _len_0 + 1
diff --git a/spec/outputs/unicode/cond.lua b/spec/outputs/unicode/cond.lua
index 7229001..5e86228 100644
--- a/spec/outputs/unicode/cond.lua
+++ b/spec/outputs/unicode/cond.lua
@@ -314,15 +314,13 @@ do
314 end 314 end
315end 315end
316do 316do
317 do 317 local _des_0 = { }
318 local _des_0 = { } 318 if _des_0 then
319 if _des_0 then 319 __u6a21_u5757 = _des_0
320 __u6a21_u5757 = _des_0 320 local _u4e1c_u897f = __u6a21_u5757["东西"]
321 local _u4e1c_u897f = __u6a21_u5757["东西"] 321 local a_u529f_u80fd, b_u529f_u80fd
322 local a_u529f_u80fd, b_u529f_u80fd 322 local _obj_0 = __u6a21_u5757
323 local _obj_0 = __u6a21_u5757 323 a_u529f_u80fd, b_u529f_u80fd = _obj_0["a功能"], _obj_0["b功能"]
324 a_u529f_u80fd, b_u529f_u80fd = _obj_0["a功能"], _obj_0["b功能"]
325 end
326 end 324 end
327end 325end
328do 326do
diff --git a/spec/outputs/unicode/do.lua b/spec/outputs/unicode/do.lua
index f9c3079..7bf1da3 100644
--- a/spec/outputs/unicode/do.lua
+++ b/spec/outputs/unicode/do.lua
@@ -32,10 +32,10 @@ local _u53d8_u91cft = {
32} 32}
33return function(_u53c2_u6570y, _u53c2_u6570k) 33return function(_u53c2_u6570y, _u53c2_u6570k)
34 if _u53c2_u6570y == nil then 34 if _u53c2_u6570y == nil then
35 do 35 _u53c2_u6570y = ((function()
36 _u53d8_u91cfx = 10 + 2 36 _u53d8_u91cfx = 10 + 2
37 _u53c2_u6570y = _u53d8_u91cfx 37 return _u53d8_u91cfx
38 end 38 end)())
39 end 39 end
40 if _u53c2_u6570k == nil then 40 if _u53c2_u6570k == nil then
41 do 41 do
diff --git a/spec/outputs/unicode/lists.lua b/spec/outputs/unicode/lists.lua
index aafd516..3bf6f50 100644
--- a/spec/outputs/unicode/lists.lua
+++ b/spec/outputs/unicode/lists.lua
@@ -229,31 +229,36 @@ _u53d8_u91cfx = {
229 6, 229 6,
230 7 230 7
231} 231}
232local _max_0 = -5 232local _max_0 = #_u53d8_u91cfx + -5 + 1
233for _index_0 = 2, _max_0 < 0 and #_u53d8_u91cfx + _max_0 or _max_0, 2 do 233for _index_0 = 2, _max_0, 2 do
234 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 234 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
235 _u6253_u5370(_u53d8_u91cfy) 235 _u6253_u5370(_u53d8_u91cfy)
236end 236end
237local _max_1 = 3 237for _index_0 = 1, 3 do
238for _index_0 = 1, _max_1 < 0 and #_u53d8_u91cfx + _max_1 or _max_1 do
239 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 238 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
240 _u6253_u5370(_u53d8_u91cfy) 239 _u6253_u5370(_u53d8_u91cfy)
241end 240end
242for _index_0 = 2, #_u53d8_u91cfx do 241local _max_1 = #_u53d8_u91cfx
242for _index_0 = 2, _max_1 do
243 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 243 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
244 _u6253_u5370(_u53d8_u91cfy) 244 _u6253_u5370(_u53d8_u91cfy)
245end 245end
246for _index_0 = 1, #_u53d8_u91cfx, 2 do 246local _max_2 = #_u53d8_u91cfx
247for _index_0 = 1, _max_2, 2 do
247 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 248 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
248 _u6253_u5370(_u53d8_u91cfy) 249 _u6253_u5370(_u53d8_u91cfy)
249end 250end
250for _index_0 = 2, #_u53d8_u91cfx, 2 do 251local _max_3 = #_u53d8_u91cfx
252for _index_0 = 2, _max_3, 2 do
251 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 253 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
252 _u6253_u5370(_u53d8_u91cfy) 254 _u6253_u5370(_u53d8_u91cfy)
253end 255end
254local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2 256local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2
255local _max_2 = _u53d8_u91cfb 257local _min_0 = _u53d8_u91cfa
256for _index_0 = _u53d8_u91cfa, _max_2 < 0 and #_u53d8_u91cfx + _max_2 or _max_2, _u53d8_u91cfc do 258local _max_4 = _u53d8_u91cfb
259_min_0 = _min_0 < 0 and #_u53d8_u91cfx + _min_0 + 1 or _min_0
260_max_4 = _max_4 < 0 and #_u53d8_u91cfx + _max_4 + 1 or _max_4
261for _index_0 = _min_0, _max_4, _u53d8_u91cfc do
257 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 262 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
258 _u6253_u5370(_u53d8_u91cfy) 263 _u6253_u5370(_u53d8_u91cfy)
259end 264end
diff --git a/spec/outputs/unicode/loops.lua b/spec/outputs/unicode/loops.lua
index 8379993..27bbe2e 100644
--- a/spec/outputs/unicode/loops.lua
+++ b/spec/outputs/unicode/loops.lua
@@ -60,8 +60,8 @@ do
60 local _u53d8_u91cfy = _u4f60_u597d[_index_0] 60 local _u53d8_u91cfy = _u4f60_u597d[_index_0]
61 if _u53d8_u91cfy % 2 == 0 then 61 if _u53d8_u91cfy % 2 == 0 then
62 _accum_0[_len_0] = _u53d8_u91cfy 62 _accum_0[_len_0] = _u53d8_u91cfy
63 _len_0 = _len_0 + 1
63 end 64 end
64 _len_0 = _len_0 + 1
65 end 65 end
66 _u53d8_u91cfx = _accum_0 66 _u53d8_u91cfx = _accum_0
67end 67end
@@ -132,13 +132,11 @@ do
132end 132end
133do 133do
134 local _accum_0 = { } 134 local _accum_0 = { }
135 local _len_0 = 1
136 local _list_2 = 3 135 local _list_2 = 3
137 for _index_0 = 1, #_list_2 do 136 for _index_0 = 1, #_list_2 do
138 local _u4e1c_u897f = _list_2[_index_0] 137 local _u4e1c_u897f = _list_2[_index_0]
139 _u53d8_u91cfy = "你好" 138 _u53d8_u91cfy = "你好"
140 break 139 break
141 _len_0 = _len_0 + 1
142 end 140 end
143 _u53d8_u91cfx = _accum_0 141 _u53d8_u91cfx = _accum_0
144end 142end
diff --git a/spec/outputs/unicode/macro.lua b/spec/outputs/unicode/macro.lua
index e2195e4..b4e78cd 100644
--- a/spec/outputs/unicode/macro.lua
+++ b/spec/outputs/unicode/macro.lua
@@ -167,13 +167,11 @@ end
167do 167do
168 local _u53d8_u91cfa = 8 168 local _u53d8_u91cfa = 8
169 _u53d8_u91cfa = (function() 169 _u53d8_u91cfa = (function()
170 local _u53d8_u91cfa 170 local _u53d8_u91cfa = 1
171 _u53d8_u91cfa = 1
172 return _u53d8_u91cfa + 1 171 return _u53d8_u91cfa + 1
173 end)() 172 end)()
174 _u53d8_u91cfa = _u53d8_u91cfa + (function() 173 _u53d8_u91cfa = _u53d8_u91cfa + (function()
175 local _u53d8_u91cfa 174 local _u53d8_u91cfa = 1
176 _u53d8_u91cfa = 1
177 return _u53d8_u91cfa + 1 175 return _u53d8_u91cfa + 1
178 end)() 176 end)()
179 _u6253_u5370(_u53d8_u91cfa) 177 _u6253_u5370(_u53d8_u91cfa)
@@ -217,24 +215,8 @@ do
217-- 这有个注释 215-- 这有个注释
218end 216end
219local _ = require('下划线') 217local _ = require('下划线')
220local _call_0 = (_({ 218local _anon_func_0 = function(_)
221 1, 219 local _call_0 = (_({
222 2,
223 3,
224 4,
225 -2,
226 3
227}))
228_call_0 = _call_0["链"](_call_0)
229_call_0 = _call_0["映射"](_call_0, function(self)
230 return self * 2
231end)
232_call_0 = _call_0["过滤"](_call_0, function(self)
233 return self > 3
234end)
235local _u7ed3_u679ca = _call_0["取值"](_call_0)
236do
237 local _call_1 = (_({
238 1, 220 1,
239 2, 221 2,
240 3, 222 3,
@@ -242,27 +224,70 @@ do
242 -2, 224 -2,
243 3 225 3
244 })) 226 }))
245 _call_1 = _call_1["链"](_call_1) 227 return _call_0["链"](_call_0)
246 _call_1 = _call_1["映射"](_call_1, function(self) 228end
247 return self * 2 229local _call_0 = ((function()
248 end) 230 local _call_0 = ((function()
249 _call_1 = _call_1["过滤"](_call_1, function(self) 231 local _call_0 = (_anon_func_0(_))
232 return _call_0["映射"](_call_0, function(self)
233 return self * 2
234 end)
235 end)())
236 return _call_0["过滤"](_call_0, function(self)
250 return self > 3 237 return self > 3
251 end) 238 end)
239end)())
240local _u7ed3_u679ca = _call_0["取值"](_call_0)
241local _anon_func_1 = function(_)
242 local _call_1 = (_({
243 1,
244 2,
245 3,
246 4,
247 -2,
248 3
249 }))
250 return _call_1["链"](_call_1)
251end
252do
253 local _call_1 = ((function()
254 local _call_1 = ((function()
255 local _call_1 = (_anon_func_1(_))
256 return _call_1["映射"](_call_1, function(self)
257 return self * 2
258 end)
259 end)())
260 return _call_1["过滤"](_call_1, function(self)
261 return self > 3
262 end)
263 end)())
252 _call_1["每一个"](_call_1, function(self) 264 _call_1["每一个"](_call_1, function(self)
253 return _u6253_u5370(self) 265 return _u6253_u5370(self)
254 end) 266 end)
255end 267end
256local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] 268local _anon_func_2 = function(_u539f_u70b9)
257_call_1 = _call_1["父节点"](_call_1) 269 local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"]
258_call_1 = _call_1["后代"](_call_1) 270 return _call_1["父节点"](_call_1)
259_call_1 = _call_1["选择启用"](_call_1) 271end
260_call_1 = _call_1["选择可见"](_call_1) 272local _call_1 = ((function()
261_call_1 = _call_1["标签等于"](_call_1, "fx") 273 local _call_1 = ((function()
262_call_1 = _call_1["其中"](_call_1, function(x) 274 local _call_1 = ((function()
263 local _call_2 = x["名称"] 275 local _call_1 = ((function()
264 return _call_2["结尾为"](_call_2, "(克隆)") 276 local _call_1 = ((function()
265end) 277 local _call_1 = (_anon_func_2(_u539f_u70b9))
278 return _call_1["后代"](_call_1)
279 end)())
280 return _call_1["选择启用"](_call_1)
281 end)())
282 return _call_1["选择可见"](_call_1)
283 end)())
284 return _call_1["标签等于"](_call_1, "fx")
285 end)())
286 return _call_1["其中"](_call_1, function(x)
287 local _call_2 = x["名称"]
288 return _call_2["结尾为"](_call_2, "(克隆)")
289 end)
290end)())
266_u7ed3_u679c = _call_1["摧毁"](_call_1) 291_u7ed3_u679c = _call_1["摧毁"](_call_1)
267do 292do
268 do 293 do
@@ -334,10 +359,8 @@ local _1
334_1 = function() 359_1 = function()
335 _u6253_u5370(1) 360 _u6253_u5370(1)
336 local _accum_0 = { } 361 local _accum_0 = { }
337 local _len_0 = 1
338 while false do 362 while false do
339 break 363 break
340 _len_0 = _len_0 + 1
341 end 364 end
342 return _accum_0 365 return _accum_0
343end 366end
diff --git a/spec/outputs/unicode/multiline_chain.lua b/spec/outputs/unicode/multiline_chain.lua
index c1da13f..61e7057 100644
--- a/spec/outputs/unicode/multiline_chain.lua
+++ b/spec/outputs/unicode/multiline_chain.lua
@@ -59,10 +59,8 @@ _u51fd_u6570 = function()
59 return _accum_0 59 return _accum_0
60end 60end
61local _anon_func_0 = function(_u53d8_u91cfa) 61local _anon_func_0 = function(_u53d8_u91cfa)
62 do 62 local _call_1 = _u53d8_u91cfa
63 local _call_1 = _u53d8_u91cfa 63 return (_call_1["变量b"](_call_1, 123))["变量c"]("abc")
64 return (_call_1["变量b"](_call_1, 123))["变量c"]("abc")
65 end
66end 64end
67local _u51fd_u65701 65local _u51fd_u65701
68_u51fd_u65701 = function() 66_u51fd_u65701 = function()
diff --git a/spec/outputs/unicode/plus.lua b/spec/outputs/unicode/plus.lua
index 75e4aac..adce62e 100644
--- a/spec/outputs/unicode/plus.lua
+++ b/spec/outputs/unicode/plus.lua
@@ -67,7 +67,6 @@ _u80cc_u5305 = {
67local _u5f00_u59cb = { 67local _u5f00_u59cb = {
68 ["东西"] = "冷" 68 ["东西"] = "冷"
69} 69}
70local _u6d17_u6fa1 70local _u6d17_u6fa1 = {
71_u6d17_u6fa1 = {
72 ["在"] = "火" 71 ["在"] = "火"
73} 72}
diff --git a/spec/outputs/unicode/syntax.lua b/spec/outputs/unicode/syntax.lua
index ea97bb9..a13302b 100644
--- a/spec/outputs/unicode/syntax.lua
+++ b/spec/outputs/unicode/syntax.lua
@@ -258,9 +258,11 @@ _u53d8_u91cfx = 0
258local _list_0 = _u503c 258local _list_0 = _u503c
259for _index_0 = 1, #_list_0 do 259for _index_0 = 1, #_list_0 do
260 local _u53d8_u91cfv = _list_0[_index_0] 260 local _u53d8_u91cfv = _list_0[_index_0]
261 if ntype(_u53d8_u91cfv) == "函数定义" then 261 _ = ((function()
262 _ = _u53d8_u91cfx + 1 262 if ntype(_u53d8_u91cfv) == "函数定义" then
263 end 263 return _u53d8_u91cfx + 1
264 end
265 end)())
264end 266end
265_u4f60_u597d = { 267_u4f60_u597d = {
266 ["某物"] = _u4e16_u754c, 268 ["某物"] = _u4e16_u754c,
@@ -284,10 +286,8 @@ _ = 5 - _u4ec0_u4e48(_u65e0_u804a)
284_u4ec0_u4e48(_u65e0_u804a - 5) 286_u4ec0_u4e48(_u65e0_u804a - 5)
285_u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269 287_u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269
286local _anon_func_0 = function(_u4ec0_u4e48) 288local _anon_func_0 = function(_u4ec0_u4e48)
287 do 289 local _call_8 = _u4ec0_u4e48
288 local _call_8 = _u4ec0_u4e48 290 return _call_8["酷"](_call_8, 100)
289 return _call_8["酷"](_call_8, 100)
290 end
291end 291end
292(function(_u67d0_u7269) 292(function(_u67d0_u7269)
293 if _u67d0_u7269 == nil then 293 if _u67d0_u7269 == nil then
diff --git a/spec/outputs/unicode/try_catch.lua b/spec/outputs/unicode/try_catch.lua
index 22f29f9..f8c7849 100644
--- a/spec/outputs/unicode/try_catch.lua
+++ b/spec/outputs/unicode/try_catch.lua
@@ -32,11 +32,13 @@ pcall(function()
32 return _u8868["函数"]() 32 return _u8868["函数"]()
33end) 33end)
34pcall(function() 34pcall(function()
35 return _u8868["函数"]() 35 return (_u8868["函数"]())
36end) 36end)
37pcall(function() 37pcall(function()
38 local _call_0 = _u8868 38 return ((function()
39 return _call_0["函数"](_call_0, 1, 2, 3) 39 local _call_0 = _u8868
40 return _call_0["函数"](_call_0, 1, 2, 3)
41 end)())
40end) 42end)
41pcall(function() 43pcall(function()
42 return _u8868["函数"](1) 44 return _u8868["函数"](1)
@@ -52,7 +54,7 @@ end)) then
52 _u6253_u5370("好的") 54 _u6253_u5370("好的")
53end 55end
54if xpcall(function() 56if xpcall(function()
55 return _u51fd_u6570(1) 57 return (_u51fd_u6570(1))
56end, function(_u9519_u8bef) 58end, function(_u9519_u8bef)
57 return _u6253_u5370(_u9519_u8bef) 59 return _u6253_u5370(_u9519_u8bef)
58end) then 60end) then
diff --git a/spec/outputs/unicode/vararg.lua b/spec/outputs/unicode/vararg.lua
index b837006..fc894ff 100644
--- a/spec/outputs/unicode/vararg.lua
+++ b/spec/outputs/unicode/vararg.lua
@@ -125,14 +125,10 @@ local _anon_func_11 = function(_u9879_u76ee, ...)
125 return _tbl_0 125 return _tbl_0
126end 126end
127local _anon_func_12 = function(_u51fd_u6570) 127local _anon_func_12 = function(_u51fd_u6570)
128 do 128 return _u51fd_u6570()
129 return _u51fd_u6570()
130 end
131end 129end
132local _anon_func_13 = function(_u51fd_u6570, ...) 130local _anon_func_13 = function(_u51fd_u6570, ...)
133 do 131 return _u51fd_u6570(...)
134 return _u51fd_u6570(...)
135 end
136end 132end
137local _anon_func_14 = function(_u51fd_u6570) 133local _anon_func_14 = function(_u51fd_u6570)
138 local _accum_0 = { } 134 local _accum_0 = { }
@@ -195,15 +191,11 @@ local _anon_func_23 = function(_u51fd_u6570, ...)
195 return nil 191 return nil
196end 192end
197local _anon_func_24 = function(_u6253_u5370, select, ...) 193local _anon_func_24 = function(_u6253_u5370, select, ...)
198 do 194 _u6253_u5370(select("#", ...))
199 _u6253_u5370(select("#", ...)) 195 return _u6253_u5370(...)
200 return _u6253_u5370(...)
201 end
202end 196end
203local _anon_func_25 = function(_u6253_u5370, ...) 197local _anon_func_25 = function(_u6253_u5370, ...)
204 do 198 return _u6253_u5370(...)
205 return _u6253_u5370(...)
206 end
207end 199end
208local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682) 200local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682)
209 if 1 == _u53d8_u91cfx then 201 if 1 == _u53d8_u91cfx then
@@ -214,9 +206,7 @@ local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682)
214 end 206 end
215end 207end
216local _anon_func_27 = function(_u6253_u5370, ...) 208local _anon_func_27 = function(_u6253_u5370, ...)
217 do 209 return _u6253_u5370(...)
218 return _u6253_u5370(...)
219 end
220end 210end
221local _anon_func_28 = function(_u6761_u4ef6) 211local _anon_func_28 = function(_u6761_u4ef6)
222 if _u6761_u4ef6 then 212 if _u6761_u4ef6 then
@@ -224,10 +214,8 @@ local _anon_func_28 = function(_u6761_u4ef6)
224 end 214 end
225end 215end
226local _anon_func_29 = function(_u6253_u5370, _arg_0, ...) 216local _anon_func_29 = function(_u6253_u5370, _arg_0, ...)
227 do 217 local _u8868 = _arg_0
228 local _u8868 = _arg_0 218 return _u6253_u5370(...)
229 return _u6253_u5370(...)
230 end
231end 219end
232local _u8fde_u63a5 220local _u8fde_u63a5
233_u8fde_u63a5 = function(...) 221_u8fde_u63a5 = function(...)
diff --git a/spec/outputs/unicode/with.lua b/spec/outputs/unicode/with.lua
index 7a5ba00..3a32a27 100644
--- a/spec/outputs/unicode/with.lua
+++ b/spec/outputs/unicode/with.lua
@@ -161,17 +161,15 @@ do
161 } 161 }
162end 162end
163do 163do
164 do 164 local _with_0 = _u5b9e_u5fc3_u77e9_u5f62({
165 local _with_0 = _u5b9e_u5fc3_u77e9_u5f62({ 165 ["宽"] = w,
166 ["宽"] = w, 166 ["高"] = h,
167 ["高"] = h, 167 ["颜色"] = 0x66000000
168 ["颜色"] = 0x66000000 168 })
169 }) 169 _u63a9_u7801 = _with_0
170 _u63a9_u7801 = _with_0 170 if _with_0 ~= nil then
171 if _with_0 ~= nil then 171 _with_0["触摸启用"] = true
172 _with_0["触摸启用"] = true 172 _with_0["吞噬触摸"] = true
173 _with_0["吞噬触摸"] = true
174 end
175 end 173 end
176end 174end
177do 175do
diff --git a/spec/outputs/upvalue_func.lua b/spec/outputs/upvalue_func.lua
index 3181adf..3e088be 100644
--- a/spec/outputs/upvalue_func.lua
+++ b/spec/outputs/upvalue_func.lua
@@ -214,10 +214,8 @@ local _anon_func_1 = function(valueB)
214 end 214 end
215end 215end
216local _anon_func_2 = function(print, select, _arg_0, ...) 216local _anon_func_2 = function(print, select, _arg_0, ...)
217 do 217 local ok = _arg_0
218 local ok = _arg_0 218 return print(select(3, ...))
219 return print(select(3, ...))
220 end
221end 219end
222local _anon_func_3 = function(tb) 220local _anon_func_3 = function(tb)
223 if tb ~= nil then 221 if tb ~= nil then
@@ -242,11 +240,9 @@ local _anon_func_5 = function(getmetatable, tb)
242 return _obj_0[1 + 1](_obj_0, "abc") 240 return _obj_0[1 + 1](_obj_0, "abc")
243end 241end
244local _anon_func_6 = function(tb) 242local _anon_func_6 = function(tb)
245 do 243 local _call_0 = tb
246 local _call_0 = tb 244 local _call_1 = _call_0["end"](_call_0)
247 local _call_1 = _call_0["end"](_call_0) 245 return _call_1["🤣"](_call_1, 123)
248 return _call_1["🤣"](_call_1, 123)
249 end
250end 246end
251local _anon_func_7 = function(itemA, listA) 247local _anon_func_7 = function(itemA, listA)
252 for _index_0 = 1, #listA do 248 for _index_0 = 1, #listA do
@@ -354,17 +350,13 @@ local _anon_func_16 = function(pairs, tb, tostring)
354 return _tbl_0 350 return _tbl_0
355end 351end
356local _anon_func_17 = function(print) 352local _anon_func_17 = function(print)
357 do 353 print(123)
358 print(123) 354 return "abc"
359 return "abc"
360 end
361end 355end
362local _anon_func_18 = function(print, select, _arg_0, ...) 356local _anon_func_18 = function(print, select, _arg_0, ...)
363 do 357 local success = _arg_0
364 local success = _arg_0 358 if success then
365 if success then 359 return print(select('#', ...))
366 return print(select('#', ...))
367 end
368 end 360 end
369end 361end
370local _anon_func_19 = function(cond, i) 362local _anon_func_19 = function(cond, i)
@@ -459,11 +451,9 @@ local _anon_func_25 = function(itemA, listA)
459 return false 451 return false
460end 452end
461local _anon_func_24 = function(itemA, listA, tb) 453local _anon_func_24 = function(itemA, listA, tb)
462 do 454 local _call_0 = tb
463 local _call_0 = tb 455 local _call_1 = _call_0["end"](_call_0)
464 local _call_1 = _call_0["end"](_call_0) 456 return _call_1["🤣"](_call_1, 123 and (#listA > 0 and _anon_func_25(itemA, listA)))
465 return _call_1["🤣"](_call_1, 123 and (#listA > 0 and _anon_func_25(itemA, listA)))
466 end
467end 457end
468GameEngine:onEvent("SomeEvent", function() 458GameEngine:onEvent("SomeEvent", function()
469 return func(value + (_anon_func_21(cond)) + (_anon_func_22(valueB)) > _anon_func_23(tb) + _anon_func_24(itemA, listA, tb)) 459 return func(value + (_anon_func_21(cond)) + (_anon_func_22(valueB)) > _anon_func_23(tb) + _anon_func_24(itemA, listA, tb))
@@ -503,13 +493,11 @@ local _anon_func_27 = function(char)
503 return nil 493 return nil
504end 494end
505local _anon_func_28 = function(os, _arg_0, ...) 495local _anon_func_28 = function(os, _arg_0, ...)
506 do 496 local ok = _arg_0
507 local ok = _arg_0 497 if ok then
508 if ok then 498 return ...
509 return ... 499 else
510 else 500 return os.exit(1)
511 return os.exit(1)
512 end
513 end 501 end
514end 502end
515local _anon_func_29 = function(debug_env_after, debug_env_before, env, func) 503local _anon_func_29 = function(debug_env_after, debug_env_before, env, func)
diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua
index dabba44..254aa6a 100644
--- a/spec/outputs/vararg.lua
+++ b/spec/outputs/vararg.lua
@@ -125,14 +125,10 @@ local _anon_func_11 = function(items, ...)
125 return _tbl_0 125 return _tbl_0
126end 126end
127local _anon_func_12 = function(func) 127local _anon_func_12 = function(func)
128 do 128 return func()
129 return func()
130 end
131end 129end
132local _anon_func_13 = function(func, ...) 130local _anon_func_13 = function(func, ...)
133 do 131 return func(...)
134 return func(...)
135 end
136end 132end
137local _anon_func_14 = function(func) 133local _anon_func_14 = function(func)
138 local _accum_0 = { } 134 local _accum_0 = { }
@@ -195,15 +191,11 @@ local _anon_func_23 = function(func, ...)
195 return nil 191 return nil
196end 192end
197local _anon_func_24 = function(print, select, ...) 193local _anon_func_24 = function(print, select, ...)
198 do 194 print(select("#", ...))
199 print(select("#", ...)) 195 return print(...)
200 return print(...)
201 end
202end 196end
203local _anon_func_25 = function(print, ...) 197local _anon_func_25 = function(print, ...)
204 do 198 return print(...)
205 return print(...)
206 end
207end 199end
208local _anon_func_26 = function(tb, tb2, x) 200local _anon_func_26 = function(tb, tb2, x)
209 if 1 == x then 201 if 1 == x then
@@ -214,9 +206,7 @@ local _anon_func_26 = function(tb, tb2, x)
214 end 206 end
215end 207end
216local _anon_func_27 = function(print, ...) 208local _anon_func_27 = function(print, ...)
217 do 209 return print(...)
218 return print(...)
219 end
220end 210end
221local _anon_func_28 = function(cond) 211local _anon_func_28 = function(cond)
222 if cond then 212 if cond then
@@ -224,10 +214,8 @@ local _anon_func_28 = function(cond)
224 end 214 end
225end 215end
226local _anon_func_29 = function(print, _arg_0, ...) 216local _anon_func_29 = function(print, _arg_0, ...)
227 do 217 local tb = _arg_0
228 local tb = _arg_0 218 return print(...)
229 return print(...)
230 end
231end 219end
232local join 220local join
233join = function(...) 221join = function(...)
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua
index 5d33bdb..530915e 100644
--- a/spec/outputs/with.lua
+++ b/spec/outputs/with.lua
@@ -158,17 +158,15 @@ do
158 } 158 }
159end 159end
160do 160do
161 do 161 local _with_0 = SolidRect({
162 local _with_0 = SolidRect({ 162 width = w,
163 width = w, 163 height = h,
164 height = h, 164 color = 0x66000000
165 color = 0x66000000 165 })
166 }) 166 mask = _with_0
167 mask = _with_0 167 if _with_0 ~= nil then
168 if _with_0 ~= nil then 168 _with_0.touchEnabled = true
169 _with_0.touchEnabled = true 169 _with_0.swallowTouches = true
170 _with_0.swallowTouches = true
171 end
172 end 170 end
173end 171end
174do 172do
@@ -189,4 +187,66 @@ do
189 return _with_0[123] 187 return _with_0[123]
190 end 188 end
191end 189end
190do
191 f((function()
192 local _with_0 = item
193 do
194 local _accum_0
195 repeat
196 if _with_0.id > 0 then
197 _accum_0 = _with_0.content
198 break
199 end
200 until true
201 _with_0 = _accum_0
202 end
203 return _with_0
204 end)())
205 local a
206 do
207 local _with_0 = tb
208 do
209 local _accum_0
210 repeat
211 if _with_0.v then
212 _accum_0 = _with_0.a
213 break
214 end
215 until true
216 _with_0 = _accum_0
217 end
218 a = _with_0
219 end
220 local _accum_0
221 while true do
222 local _with_0 = tb
223 local _accum_1
224 repeat
225 if _with_0 ~= nil then
226 _accum_1 = 1
227 break
228 end
229 until true
230 _with_0 = _accum_1
231 _accum_0 = _with_0
232 break
233 end
234 a = _accum_0
235end
236do
237 local a
238 local _accum_0
239 for i = 1, 100 do
240 local x = tb[i]
241 if x ~= nil then
242 local _des_0 = 1
243 if _des_0 then
244 x.id = _des_0
245 _accum_0 = x
246 break
247 end
248 end
249 end
250 a = _accum_0
251end
192return nil 252return nil