aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/inputs/backcall.yue4
-rw-r--r--spec/inputs/destructure.yue40
-rw-r--r--spec/inputs/global.yue6
-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.lua18
-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.lua12
-rw-r--r--spec/outputs/attrib.lua18
-rw-r--r--spec/outputs/codes_from_doc.lua844
-rw-r--r--spec/outputs/codes_from_doc_zh.lua844
-rw-r--r--spec/outputs/comprehension.lua10
-rw-r--r--spec/outputs/destructure.lua90
-rw-r--r--spec/outputs/do.lua6
-rw-r--r--spec/outputs/global.lua25
-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.lua15
-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/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.lua95
-rw-r--r--spec/outputs/unicode/multiline_chain.lua6
-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/upvalue_func.lua48
-rw-r--r--spec/outputs/vararg.lua28
-rw-r--r--spec/outputs/with.lua62
56 files changed, 4385 insertions, 318 deletions
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/global.yue b/spec/inputs/global.yue
index ce1cc15..4e3b8aa 100644
--- a/spec/inputs/global.yue
+++ b/spec/inputs/global.yue
@@ -82,3 +82,9 @@ do
82 FooBar = "pascal case" 82 FooBar = "pascal case"
83 FOOBAR = "all uppercase" 83 FOOBAR = "all uppercase"
84 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 a156e84..bda24bc 100644
--- a/spec/outputs/5.1/attrib.lua
+++ b/spec/outputs/5.1/attrib.lua
@@ -136,9 +136,11 @@ do
136 end 136 end
137 local b 137 local b
138 if not false then 138 if not false then
139 if x then 139 b = ((function()
140 b = 1 140 if x then
141 end 141 return 1
142 end
143 end)())
142 end 144 end
143 local _close_0 145 local _close_0
144 if (function() 146 if (function()
@@ -164,10 +166,12 @@ do
164 end)(pcall(function() 166 end)(pcall(function()
165 local c 167 local c
166 if true then 168 if true then
167 local _exp_0 = x 169 c = ((function()
168 if "abc" == _exp_0 then 170 local _exp_0 = x
169 c = 998 171 if "abc" == _exp_0 then
170 end 172 return 998
173 end
174 end)())
171 end 175 end
172 local d 176 local d
173 if (function() 177 if (function()
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 f889865..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))
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/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 27f8de5..b7d1236 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 = {
@@ -547,6 +603,59 @@ end
547local two, four 603local two, four
548local _obj_0 = items 604local _obj_0 = items
549two, 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]
550local tuples = { 659local tuples = {
551 { 660 {
552 "hello", 661 "hello",
@@ -648,6 +757,56 @@ end)
648if success then 757if success then
649 print(result) 758 print(result)
650end 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)())
651local a <const> = 123 810local a <const> = 123
652local _ <close> = setmetatable({ }, { 811local _ <close> = setmetatable({ }, {
653 __close = function() 812 __close = function()
@@ -657,10 +816,19 @@ local _ <close> = setmetatable({ }, {
657local a, b, c, d 816local a, b, c, d
658local _obj_0 = tb 817local _obj_0 = tb
659a, 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
660local 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."
661print("I am " .. tostring(math.random() * 100) .. "% sure.") 821print("I am " .. tostring(math.random() * 100) .. "% sure.")
662local integer = 1000000 822local integer = 1000000
663local 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) .. "!\"'"
664local my_function 832local my_function
665my_function = function() end 833my_function = function() end
666my_function() 834my_function()
@@ -860,11 +1028,10 @@ for i, item in ipairs(items) do
860 _len_0 = _len_0 + 1 1028 _len_0 = _len_0 + 1
861end 1029end
862doubled = _accum_0 1030doubled = _accum_0
863local iter = ipairs(items)
864local slice 1031local slice
865local _accum_0 = { } 1032local _accum_0 = { }
866local _len_0 = 1 1033local _len_0 = 1
867for i, item in iter do 1034for i, item in ipairs(items) do
868 if i > 1 and i < 3 then 1035 if i > 1 and i < 3 then
869 _accum_0[_len_0] = item 1036 _accum_0[_len_0] = item
870 _len_0 = _len_0 + 1 1037 _len_0 = _len_0 + 1
@@ -971,8 +1138,7 @@ local slice
971local _accum_0 = { } 1138local _accum_0 = { }
972local _len_0 = 1 1139local _len_0 = 1
973local _list_0 = items 1140local _list_0 = items
974local _max_0 = 5 1141for _index_0 = 1, 5 do
975for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
976 local item = _list_0[_index_0] 1142 local item = _list_0[_index_0]
977 _accum_0[_len_0] = item 1143 _accum_0[_len_0] = item
978 _len_0 = _len_0 + 1 1144 _len_0 = _len_0 + 1
@@ -982,7 +1148,8 @@ local slice
982local _accum_0 = { } 1148local _accum_0 = { }
983local _len_0 = 1 1149local _len_0 = 1
984local _list_0 = items 1150local _list_0 = items
985for _index_0 = 2, #_list_0 do 1151local _max_0 = #_list_0
1152for _index_0 = 2, _max_0 do
986 local item = _list_0[_index_0] 1153 local item = _list_0[_index_0]
987 _accum_0[_len_0] = item 1154 _accum_0[_len_0] = item
988 _len_0 = _len_0 + 1 1155 _len_0 = _len_0 + 1
@@ -992,12 +1159,46 @@ local slice
992local _accum_0 = { } 1159local _accum_0 = { }
993local _len_0 = 1 1160local _len_0 = 1
994local _list_0 = items 1161local _list_0 = items
995for _index_0 = 1, #_list_0, 2 do 1162local _max_0 = #_list_0
1163for _index_0 = 1, _max_0, 2 do
996 local item = _list_0[_index_0] 1164 local item = _list_0[_index_0]
997 _accum_0[_len_0] = item 1165 _accum_0[_len_0] = item
998 _len_0 = _len_0 + 1 1166 _len_0 = _len_0 + 1
999end 1167end
1000slice = _accum_0 1168slice = _accum_0
1169local slice
1170local _accum_0 = { }
1171local _len_0 = 1
1172local _list_0 = items
1173local _min_0 = #_list_0 + -4 + 1
1174local _max_0 = #_list_0 + -1 + 1
1175for _index_0 = _min_0, _max_0 do
1176 local item = _list_0[_index_0]
1177 _accum_0[_len_0] = item
1178 _len_0 = _len_0 + 1
1179end
1180slice = _accum_0
1181local reverse_slice
1182local _accum_0 = { }
1183local _len_0 = 1
1184local _list_0 = items
1185local _min_0 = #_list_0 + -1 + 1
1186for _index_0 = _min_0, 1, -1 do
1187 local item = _list_0[_index_0]
1188 _accum_0[_len_0] = item
1189 _len_0 = _len_0 + 1
1190end
1191reverse_slice = _accum_0
1192local sub_list
1193local _accum_0 = { }
1194local _len_0 = 1
1195local _list_0 = items
1196for _index_0 = 2, 4 do
1197 local _item_0 = _list_0[_index_0]
1198 _accum_0[_len_0] = _item_0
1199 _len_0 = _len_0 + 1
1200end
1201sub_list = _accum_0
1001for i = 10, 20 do 1202for i = 10, 20 do
1002 print(i) 1203 print(i)
1003end 1204end
@@ -1008,8 +1209,7 @@ for key, value in pairs(object) do
1008 print(key, value) 1209 print(key, value)
1009end 1210end
1010local _list_0 = items 1211local _list_0 = items
1011local _max_0 = 4 1212for _index_0 = 2, 4 do
1012for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1013 local item = _list_0[_index_0] 1213 local item = _list_0[_index_0]
1014 print(item) 1214 print(item)
1015end 1215end
@@ -1027,12 +1227,24 @@ local _len_0 = 1
1027for i = 1, 20 do 1227for i = 1, 20 do
1028 if i % 2 == 0 then 1228 if i % 2 == 0 then
1029 _accum_0[_len_0] = i * 2 1229 _accum_0[_len_0] = i * 2
1230 _len_0 = _len_0 + 1
1030 else 1231 else
1031 _accum_0[_len_0] = i 1232 _accum_0[_len_0] = i
1233 _len_0 = _len_0 + 1
1032 end 1234 end
1033 _len_0 = _len_0 + 1
1034end 1235end
1035doubled_evens = _accum_0 1236doubled_evens = _accum_0
1237local first_large
1238local _accum_0
1239local _list_0 = numbers
1240for _index_0 = 1, #_list_0 do
1241 local n = _list_0[_index_0]
1242 if n > 10 then
1243 _accum_0 = n
1244 break
1245 end
1246end
1247first_large = _accum_0
1036local func_a 1248local func_a
1037func_a = function() 1249func_a = function()
1038 for i = 1, 10 do 1250 for i = 1, 10 do
@@ -1181,7 +1393,7 @@ if "Robert" == name then
1181elseif "Dan" == name or "Daniel" == name then 1393elseif "Dan" == name or "Daniel" == name then
1182 print("Your name, it's Dan") 1394 print("Your name, it's Dan")
1183else 1395else
1184 print("I don't know about your name") 1396 print("I don't know about you with name " .. tostring(name))
1185end 1397end
1186local b = 1 1398local b = 1
1187local next_number 1399local next_number
@@ -1281,6 +1493,192 @@ if _tab_0 then
1281 end 1493 end
1282 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1494 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1283end 1495end
1496local _exp_0 = tb
1497local _type_0 = type(_exp_0)
1498local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1499local _match_0 = false
1500if _tab_0 then
1501 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1502 _match_0 = true
1503 print("1, 2, 3")
1504 end
1505end
1506if not _match_0 then
1507 local _match_1 = false
1508 if _tab_0 then
1509 local b = _exp_0[2]
1510 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1511 _match_1 = true
1512 print("1, " .. tostring(b) .. ", 3")
1513 end
1514 end
1515 if not _match_1 then
1516 if _tab_0 then
1517 local b = _exp_0[3]
1518 if b == nil then
1519 b = 3
1520 end
1521 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1522 print("1, 2, " .. tostring(b))
1523 end
1524 end
1525 end
1526end
1527local _exp_0 = tb
1528local _type_0 = type(_exp_0)
1529local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1530local _match_0 = false
1531if _tab_0 then
1532 local result = _exp_0.result
1533 if true == _exp_0.success and result ~= nil then
1534 _match_0 = true
1535 print("success", result)
1536 end
1537end
1538if not _match_0 then
1539 local _match_1 = false
1540 if _tab_0 then
1541 if false == _exp_0.success then
1542 _match_1 = true
1543 print("failed", result)
1544 end
1545 end
1546 if not _match_1 then
1547 print("invalid")
1548 end
1549end
1550local _exp_0 = tb
1551local _type_0 = type(_exp_0)
1552local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1553local _match_0 = false
1554if _tab_0 then
1555 local content
1556 do
1557 local _obj_0 = _exp_0.data
1558 local _type_1 = type(_obj_0)
1559 if "table" == _type_1 or "userdata" == _type_1 then
1560 content = _obj_0.content
1561 end
1562 end
1563 local _val_0
1564 do
1565 local _obj_0 = _exp_0.data
1566 if _obj_0 ~= nil then
1567 _val_0 = _obj_0.type
1568 end
1569 end
1570 if "success" == _val_0 and content ~= nil then
1571 _match_0 = true
1572 print("success", content)
1573 end
1574end
1575if not _match_0 then
1576 local _match_1 = false
1577 if _tab_0 then
1578 local content
1579 do
1580 local _obj_0 = _exp_0.data
1581 local _type_1 = type(_obj_0)
1582 if "table" == _type_1 or "userdata" == _type_1 then
1583 content = _obj_0.content
1584 end
1585 end
1586 local _val_0
1587 do
1588 local _obj_0 = _exp_0.data
1589 if _obj_0 ~= nil then
1590 _val_0 = _obj_0.type
1591 end
1592 end
1593 if "error" == _val_0 and content ~= nil then
1594 _match_1 = true
1595 print("failed", content)
1596 end
1597 end
1598 if not _match_1 then
1599 print("invalid")
1600 end
1601end
1602local _exp_0 = tb
1603local _type_0 = type(_exp_0)
1604local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1605if _tab_0 then
1606 local fourth = _exp_0[4]
1607 local _val_0
1608 do
1609 local _obj_0 = _exp_0[1]
1610 if _obj_0 ~= nil then
1611 _val_0 = _obj_0.a
1612 end
1613 end
1614 local _val_1
1615 do
1616 local _obj_0 = _exp_0[1]
1617 if _obj_0 ~= nil then
1618 _val_1 = _obj_0.b
1619 end
1620 end
1621 local _val_2
1622 do
1623 local _obj_0 = _exp_0[2]
1624 if _obj_0 ~= nil then
1625 _val_2 = _obj_0.a
1626 end
1627 end
1628 local _val_3
1629 do
1630 local _obj_0 = _exp_0[2]
1631 if _obj_0 ~= nil then
1632 _val_3 = _obj_0.b
1633 end
1634 end
1635 local _val_4
1636 do
1637 local _obj_0 = _exp_0[3]
1638 if _obj_0 ~= nil then
1639 _val_4 = _obj_0.a
1640 end
1641 end
1642 local _val_5
1643 do
1644 local _obj_0 = _exp_0[3]
1645 if _obj_0 ~= nil then
1646 _val_5 = _obj_0.b
1647 end
1648 end
1649 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
1650 print("matched", fourth)
1651 end
1652end
1653local segments = {
1654 "admin",
1655 "users",
1656 "logs",
1657 "view"
1658}
1659local _type_0 = type(segments)
1660local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1661if _tab_0 then
1662 local groups
1663 do
1664 local _accum_0 = { }
1665 local _len_0 = 1
1666 local _max_0 = #segments + -3 + 1
1667 for _index_0 = 1, _max_0 do
1668 local _item_0 = segments[_index_0]
1669 _accum_0[_len_0] = _item_0
1670 _len_0 = _len_0 + 1
1671 end
1672 groups = _accum_0
1673 end
1674 local resource = segments[#segments - 1]
1675 local action = segments[#segments]
1676 if resource ~= nil and action ~= nil then
1677 print("Group:", groups)
1678 print("Resource:", resource)
1679 print("Action:", action)
1680 end
1681end
1284local Inventory 1682local Inventory
1285local _class_0 1683local _class_0
1286local _base_0 = { 1684local _base_0 = {
@@ -1937,6 +2335,10 @@ do
1937 _with_1["key-name"] = value 2335 _with_1["key-name"] = value
1938end 2336end
1939_with_0[#_with_0 + 1] = "abc" 2337_with_0[#_with_0 + 1] = "abc"
2338local _with_0 = obj
2339if _with_0 ~= nil then
2340 print(obj.name)
2341end
1940do 2342do
1941 local var = "hello" 2343 local var = "hello"
1942 print(var) 2344 print(var)
@@ -2027,6 +2429,38 @@ local inventory = {
2027 } 2429 }
2028 } 2430 }
2029} 2431}
2432local map
2433map = function(arr, action)
2434 local _accum_0 = { }
2435 local _len_0 = 1
2436 for _index_0 = 1, #arr do
2437 local item = arr[_index_0]
2438 _accum_0[_len_0] = action(item)
2439 _len_0 = _len_0 + 1
2440 end
2441 return _accum_0
2442end
2443local filter
2444filter = function(arr, cond)
2445 local _accum_0 = { }
2446 local _len_0 = 1
2447 for _index_0 = 1, #arr do
2448 local item = arr[_index_0]
2449 if cond(item) then
2450 _accum_0[_len_0] = item
2451 _len_0 = _len_0 + 1
2452 end
2453 end
2454 return _accum_0
2455end
2456local reduce
2457reduce = function(arr, init, action)
2458 for _index_0 = 1, #arr do
2459 local item = arr[_index_0]
2460 init = action(init, item)
2461 end
2462 return init
2463end
2030print(reduce(filter(map({ 2464print(reduce(filter(map({
2031 1, 2465 1,
2032 2, 2466 2,
@@ -2084,6 +2518,12 @@ end
2084print("yuescript") 2518print("yuescript")
2085print(3) 2519print(3)
2086print("Valid enum type:", "Static") 2520print("Valid enum type:", "Static")
2521do
2522 print(123, "hello")
2523end
2524do
2525 print(123, "hello")
2526end
2087if tb ~= nil then 2527if tb ~= nil then
2088 tb:func() 2528 tb:func()
2089end 2529end
@@ -2184,6 +2624,16 @@ for _key_0, _value_0 in pairs(b) do
2184 end 2624 end
2185end 2625end
2186merge = _tab_0 2626merge = _tab_0
2627local last
2628do
2629 local _item_0 = data.items
2630 last = _item_0[#_item_0]
2631end
2632local second_last
2633do
2634 local _item_0 = data.items
2635 second_last = _item_0[#_item_0 - 1]
2636end
2187local mt = { } 2637local mt = { }
2188local add 2638local add
2189add = function(self, right) 2639add = function(self, right)
@@ -2314,6 +2764,14 @@ func({
2314 2, 2764 2,
2315 3 2765 3
2316}) 2766})
2767local f
2768f = function()
2769 return {
2770 1,
2771 2,
2772 3
2773 }
2774end
2317local tb = { 2775local tb = {
2318 name = "abc", 2776 name = "abc",
2319 values = { 2777 values = {
@@ -2554,6 +3012,59 @@ end
2554local two, four 3012local two, four
2555local _obj_0 = items 3013local _obj_0 = items
2556two, four = _obj_0[2], _obj_0[4] 3014two, four = _obj_0[2], _obj_0[4]
3015local orders = {
3016 "first",
3017 "second",
3018 "third",
3019 "fourth",
3020 "last"
3021}
3022local first, bulk, last = orders[1], (function()
3023 local _accum_0 = { }
3024 local _len_0 = 1
3025 local _max_0 = #orders + -2 + 1
3026 for _index_0 = 2, _max_0 do
3027 local _item_0 = orders[_index_0]
3028 _accum_0[_len_0] = _item_0
3029 _len_0 = _len_0 + 1
3030 end
3031 return _accum_0
3032end)(), orders[#orders]
3033print(first)
3034print(bulk)
3035print(last)
3036local first, rest
3037do
3038 local _obj_0 = orders
3039 first, rest = _obj_0[1], (function()
3040 local _accum_0 = { }
3041 local _len_0 = 1
3042 local _max_0 = #_obj_0
3043 for _index_0 = 2, _max_0 do
3044 local _item_0 = _obj_0[_index_0]
3045 _accum_0[_len_0] = _item_0
3046 _len_0 = _len_0 + 1
3047 end
3048 return _accum_0
3049 end)()
3050end
3051local start, last
3052do
3053 local _obj_0 = orders
3054 start, last = (function()
3055 local _accum_0 = { }
3056 local _len_0 = 1
3057 local _max_0 = #_obj_0 + -2 + 1
3058 for _index_0 = 1, _max_0 do
3059 local _item_0 = _obj_0[_index_0]
3060 _accum_0[_len_0] = _item_0
3061 _len_0 = _len_0 + 1
3062 end
3063 return _accum_0
3064 end)(), _obj_0[#_obj_0]
3065end
3066local _obj_0 = orders
3067first, last = _obj_0[1], _obj_0[#_obj_0]
2557local tuples = { 3068local tuples = {
2558 { 3069 {
2559 "hello", 3070 "hello",
@@ -2655,6 +3166,56 @@ end)
2655if success then 3166if success then
2656 print(result) 3167 print(result)
2657end 3168end
3169local a, b, c
3170do
3171 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3172 return func()
3173 end)
3174 if _ok_0 then
3175 a, b, c = _ret_0, _ret_1, _ret_2
3176 end
3177end
3178do
3179 local _exp_0 = ((function()
3180 return (function(_arg_0, ...)
3181 local _ok_0 = _arg_0
3182 if _ok_0 then
3183 return ...
3184 end
3185 end)(pcall(function()
3186 return func()
3187 end))
3188 end)())
3189 if _exp_0 ~= nil then
3190 a = _exp_0
3191 else
3192 a = "default"
3193 end
3194end
3195f((function()
3196 return (function(_arg_0, ...)
3197 local _ok_0 = _arg_0
3198 if _ok_0 then
3199 return ...
3200 end
3201 end)(pcall(function()
3202 return func()
3203 end))
3204end)())
3205f((function()
3206 return (function(_arg_0, ...)
3207 local _ok_0 = _arg_0
3208 if _ok_0 then
3209 return ...
3210 end
3211 end)(xpcall(function()
3212 print(123)
3213 return func()
3214 end, function(e)
3215 print(e)
3216 return e
3217 end))
3218end)())
2658local a <const> = 123 3219local a <const> = 123
2659local _ <close> = setmetatable({ }, { 3220local _ <close> = setmetatable({ }, {
2660 __close = function() 3221 __close = function()
@@ -2664,10 +3225,19 @@ local _ <close> = setmetatable({ }, {
2664local a, b, c, d 3225local a, b, c, d
2665local _obj_0 = tb 3226local _obj_0 = tb
2666a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3227a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3228Constant = 123
2667local some_string = "Here is a string\n that has a line break in it." 3229local some_string = "Here is a string\n that has a line break in it."
2668print("I am " .. tostring(math.random() * 100) .. "% sure.") 3230print("I am " .. tostring(math.random() * 100) .. "% sure.")
2669local integer = 1000000 3231local integer = 1000000
2670local hex = 0xEFBBBF 3232local hex = 0xEFBBBF
3233local binary = 19
3234local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3235local fn
3236fn = function()
3237 local str = "foo:\n bar: baz"
3238 return str
3239end
3240local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2671local my_function 3241local my_function
2672my_function = function() end 3242my_function = function() end
2673my_function() 3243my_function()
@@ -2867,11 +3437,10 @@ for i, item in ipairs(items) do
2867 _len_0 = _len_0 + 1 3437 _len_0 = _len_0 + 1
2868end 3438end
2869doubled = _accum_0 3439doubled = _accum_0
2870local iter = ipairs(items)
2871local slice 3440local slice
2872local _accum_0 = { } 3441local _accum_0 = { }
2873local _len_0 = 1 3442local _len_0 = 1
2874for i, item in iter do 3443for i, item in ipairs(items) do
2875 if i > 1 and i < 3 then 3444 if i > 1 and i < 3 then
2876 _accum_0[_len_0] = item 3445 _accum_0[_len_0] = item
2877 _len_0 = _len_0 + 1 3446 _len_0 = _len_0 + 1
@@ -2978,8 +3547,7 @@ local slice
2978local _accum_0 = { } 3547local _accum_0 = { }
2979local _len_0 = 1 3548local _len_0 = 1
2980local _list_0 = items 3549local _list_0 = items
2981local _max_0 = 5 3550for _index_0 = 1, 5 do
2982for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
2983 local item = _list_0[_index_0] 3551 local item = _list_0[_index_0]
2984 _accum_0[_len_0] = item 3552 _accum_0[_len_0] = item
2985 _len_0 = _len_0 + 1 3553 _len_0 = _len_0 + 1
@@ -2989,7 +3557,8 @@ local slice
2989local _accum_0 = { } 3557local _accum_0 = { }
2990local _len_0 = 1 3558local _len_0 = 1
2991local _list_0 = items 3559local _list_0 = items
2992for _index_0 = 2, #_list_0 do 3560local _max_0 = #_list_0
3561for _index_0 = 2, _max_0 do
2993 local item = _list_0[_index_0] 3562 local item = _list_0[_index_0]
2994 _accum_0[_len_0] = item 3563 _accum_0[_len_0] = item
2995 _len_0 = _len_0 + 1 3564 _len_0 = _len_0 + 1
@@ -2999,12 +3568,46 @@ local slice
2999local _accum_0 = { } 3568local _accum_0 = { }
3000local _len_0 = 1 3569local _len_0 = 1
3001local _list_0 = items 3570local _list_0 = items
3002for _index_0 = 1, #_list_0, 2 do 3571local _max_0 = #_list_0
3572for _index_0 = 1, _max_0, 2 do
3003 local item = _list_0[_index_0] 3573 local item = _list_0[_index_0]
3004 _accum_0[_len_0] = item 3574 _accum_0[_len_0] = item
3005 _len_0 = _len_0 + 1 3575 _len_0 = _len_0 + 1
3006end 3576end
3007slice = _accum_0 3577slice = _accum_0
3578local slice
3579local _accum_0 = { }
3580local _len_0 = 1
3581local _list_0 = items
3582local _min_0 = #_list_0 + -4 + 1
3583local _max_0 = #_list_0 + -1 + 1
3584for _index_0 = _min_0, _max_0 do
3585 local item = _list_0[_index_0]
3586 _accum_0[_len_0] = item
3587 _len_0 = _len_0 + 1
3588end
3589slice = _accum_0
3590local reverse_slice
3591local _accum_0 = { }
3592local _len_0 = 1
3593local _list_0 = items
3594local _min_0 = #_list_0 + -1 + 1
3595for _index_0 = _min_0, 1, -1 do
3596 local item = _list_0[_index_0]
3597 _accum_0[_len_0] = item
3598 _len_0 = _len_0 + 1
3599end
3600reverse_slice = _accum_0
3601local sub_list
3602local _accum_0 = { }
3603local _len_0 = 1
3604local _list_0 = items
3605for _index_0 = 2, 4 do
3606 local _item_0 = _list_0[_index_0]
3607 _accum_0[_len_0] = _item_0
3608 _len_0 = _len_0 + 1
3609end
3610sub_list = _accum_0
3008for i = 10, 20 do 3611for i = 10, 20 do
3009 print(i) 3612 print(i)
3010end 3613end
@@ -3015,8 +3618,7 @@ for key, value in pairs(object) do
3015 print(key, value) 3618 print(key, value)
3016end 3619end
3017local _list_0 = items 3620local _list_0 = items
3018local _max_0 = 4 3621for _index_0 = 2, 4 do
3019for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3020 local item = _list_0[_index_0] 3622 local item = _list_0[_index_0]
3021 print(item) 3623 print(item)
3022end 3624end
@@ -3034,12 +3636,24 @@ local _len_0 = 1
3034for i = 1, 20 do 3636for i = 1, 20 do
3035 if i % 2 == 0 then 3637 if i % 2 == 0 then
3036 _accum_0[_len_0] = i * 2 3638 _accum_0[_len_0] = i * 2
3639 _len_0 = _len_0 + 1
3037 else 3640 else
3038 _accum_0[_len_0] = i 3641 _accum_0[_len_0] = i
3642 _len_0 = _len_0 + 1
3039 end 3643 end
3040 _len_0 = _len_0 + 1
3041end 3644end
3042doubled_evens = _accum_0 3645doubled_evens = _accum_0
3646local first_large
3647local _accum_0
3648local _list_0 = numbers
3649for _index_0 = 1, #_list_0 do
3650 local n = _list_0[_index_0]
3651 if n > 10 then
3652 _accum_0 = n
3653 break
3654 end
3655end
3656first_large = _accum_0
3043local func_a 3657local func_a
3044func_a = function() 3658func_a = function()
3045 for i = 1, 10 do 3659 for i = 1, 10 do
@@ -3188,7 +3802,7 @@ if "Robert" == name then
3188elseif "Dan" == name or "Daniel" == name then 3802elseif "Dan" == name or "Daniel" == name then
3189 print("Your name, it's Dan") 3803 print("Your name, it's Dan")
3190else 3804else
3191 print("I don't know about your name") 3805 print("I don't know about you with name " .. tostring(name))
3192end 3806end
3193local b = 1 3807local b = 1
3194local next_number 3808local next_number
@@ -3288,6 +3902,192 @@ if _tab_0 then
3288 end 3902 end
3289 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3903 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3290end 3904end
3905local _exp_0 = tb
3906local _type_0 = type(_exp_0)
3907local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3908local _match_0 = false
3909if _tab_0 then
3910 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3911 _match_0 = true
3912 print("1, 2, 3")
3913 end
3914end
3915if not _match_0 then
3916 local _match_1 = false
3917 if _tab_0 then
3918 local b = _exp_0[2]
3919 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3920 _match_1 = true
3921 print("1, " .. tostring(b) .. ", 3")
3922 end
3923 end
3924 if not _match_1 then
3925 if _tab_0 then
3926 local b = _exp_0[3]
3927 if b == nil then
3928 b = 3
3929 end
3930 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3931 print("1, 2, " .. tostring(b))
3932 end
3933 end
3934 end
3935end
3936local _exp_0 = tb
3937local _type_0 = type(_exp_0)
3938local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3939local _match_0 = false
3940if _tab_0 then
3941 local result = _exp_0.result
3942 if true == _exp_0.success and result ~= nil then
3943 _match_0 = true
3944 print("success", result)
3945 end
3946end
3947if not _match_0 then
3948 local _match_1 = false
3949 if _tab_0 then
3950 if false == _exp_0.success then
3951 _match_1 = true
3952 print("failed", result)
3953 end
3954 end
3955 if not _match_1 then
3956 print("invalid")
3957 end
3958end
3959local _exp_0 = tb
3960local _type_0 = type(_exp_0)
3961local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3962local _match_0 = false
3963if _tab_0 then
3964 local content
3965 do
3966 local _obj_0 = _exp_0.data
3967 local _type_1 = type(_obj_0)
3968 if "table" == _type_1 or "userdata" == _type_1 then
3969 content = _obj_0.content
3970 end
3971 end
3972 local _val_0
3973 do
3974 local _obj_0 = _exp_0.data
3975 if _obj_0 ~= nil then
3976 _val_0 = _obj_0.type
3977 end
3978 end
3979 if "success" == _val_0 and content ~= nil then
3980 _match_0 = true
3981 print("success", content)
3982 end
3983end
3984if not _match_0 then
3985 local _match_1 = false
3986 if _tab_0 then
3987 local content
3988 do
3989 local _obj_0 = _exp_0.data
3990 local _type_1 = type(_obj_0)
3991 if "table" == _type_1 or "userdata" == _type_1 then
3992 content = _obj_0.content
3993 end
3994 end
3995 local _val_0
3996 do
3997 local _obj_0 = _exp_0.data
3998 if _obj_0 ~= nil then
3999 _val_0 = _obj_0.type
4000 end
4001 end
4002 if "error" == _val_0 and content ~= nil then
4003 _match_1 = true
4004 print("failed", content)
4005 end
4006 end
4007 if not _match_1 then
4008 print("invalid")
4009 end
4010end
4011local _exp_0 = tb
4012local _type_0 = type(_exp_0)
4013local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4014if _tab_0 then
4015 local fourth = _exp_0[4]
4016 local _val_0
4017 do
4018 local _obj_0 = _exp_0[1]
4019 if _obj_0 ~= nil then
4020 _val_0 = _obj_0.a
4021 end
4022 end
4023 local _val_1
4024 do
4025 local _obj_0 = _exp_0[1]
4026 if _obj_0 ~= nil then
4027 _val_1 = _obj_0.b
4028 end
4029 end
4030 local _val_2
4031 do
4032 local _obj_0 = _exp_0[2]
4033 if _obj_0 ~= nil then
4034 _val_2 = _obj_0.a
4035 end
4036 end
4037 local _val_3
4038 do
4039 local _obj_0 = _exp_0[2]
4040 if _obj_0 ~= nil then
4041 _val_3 = _obj_0.b
4042 end
4043 end
4044 local _val_4
4045 do
4046 local _obj_0 = _exp_0[3]
4047 if _obj_0 ~= nil then
4048 _val_4 = _obj_0.a
4049 end
4050 end
4051 local _val_5
4052 do
4053 local _obj_0 = _exp_0[3]
4054 if _obj_0 ~= nil then
4055 _val_5 = _obj_0.b
4056 end
4057 end
4058 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
4059 print("matched", fourth)
4060 end
4061end
4062local segments = {
4063 "admin",
4064 "users",
4065 "logs",
4066 "view"
4067}
4068local _type_0 = type(segments)
4069local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4070if _tab_0 then
4071 local groups
4072 do
4073 local _accum_0 = { }
4074 local _len_0 = 1
4075 local _max_0 = #segments + -3 + 1
4076 for _index_0 = 1, _max_0 do
4077 local _item_0 = segments[_index_0]
4078 _accum_0[_len_0] = _item_0
4079 _len_0 = _len_0 + 1
4080 end
4081 groups = _accum_0
4082 end
4083 local resource = segments[#segments - 1]
4084 local action = segments[#segments]
4085 if resource ~= nil and action ~= nil then
4086 print("Group:", groups)
4087 print("Resource:", resource)
4088 print("Action:", action)
4089 end
4090end
3291local Inventory 4091local Inventory
3292local _class_0 4092local _class_0
3293local _base_0 = { 4093local _base_0 = {
@@ -3944,6 +4744,10 @@ do
3944 _with_1["key-name"] = value 4744 _with_1["key-name"] = value
3945end 4745end
3946_with_0[#_with_0 + 1] = "abc" 4746_with_0[#_with_0 + 1] = "abc"
4747local _with_0 = obj
4748if _with_0 ~= nil then
4749 print(obj.name)
4750end
3947do 4751do
3948 local var = "hello" 4752 local var = "hello"
3949 print(var) 4753 print(var)
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index ffa0483..b54d6d7 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 = {
@@ -547,6 +603,59 @@ end
547local two, four 603local two, four
548local _obj_0 = items 604local _obj_0 = items
549two, 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]
550local tuples = { 659local tuples = {
551 { 660 {
552 "hello", 661 "hello",
@@ -648,6 +757,56 @@ end)
648if success then 757if success then
649 print(result) 758 print(result)
650end 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)())
651local a <const> = 123 810local a <const> = 123
652local _ <close> = setmetatable({ }, { 811local _ <close> = setmetatable({ }, {
653 __close = function() 812 __close = function()
@@ -657,10 +816,19 @@ local _ <close> = setmetatable({ }, {
657local a, b, c, d 816local a, b, c, d
658local _obj_0 = tb 817local _obj_0 = tb
659a, 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
660local some_string = "这是一个字符串\n 并包括一个换行。" 820local some_string = "这是一个字符串\n 并包括一个换行。"
661print("我有" .. tostring(math.random() * 100) .. "%的把握。") 821print("我有" .. tostring(math.random() * 100) .. "%的把握。")
662local integer = 1000000 822local integer = 1000000
663local 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) .. "!\"'"
664local my_function 832local my_function
665my_function = function() end 833my_function = function() end
666my_function() 834my_function()
@@ -854,11 +1022,10 @@ for i, item in ipairs(items) do
854 _len_0 = _len_0 + 1 1022 _len_0 = _len_0 + 1
855end 1023end
856doubled = _accum_0 1024doubled = _accum_0
857local iter = ipairs(items)
858local slice 1025local slice
859local _accum_0 = { } 1026local _accum_0 = { }
860local _len_0 = 1 1027local _len_0 = 1
861for i, item in iter do 1028for i, item in ipairs(items) do
862 if i > 1 and i < 3 then 1029 if i > 1 and i < 3 then
863 _accum_0[_len_0] = item 1030 _accum_0[_len_0] = item
864 _len_0 = _len_0 + 1 1031 _len_0 = _len_0 + 1
@@ -965,8 +1132,7 @@ local slice
965local _accum_0 = { } 1132local _accum_0 = { }
966local _len_0 = 1 1133local _len_0 = 1
967local _list_0 = items 1134local _list_0 = items
968local _max_0 = 5 1135for _index_0 = 1, 5 do
969for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
970 local item = _list_0[_index_0] 1136 local item = _list_0[_index_0]
971 _accum_0[_len_0] = item 1137 _accum_0[_len_0] = item
972 _len_0 = _len_0 + 1 1138 _len_0 = _len_0 + 1
@@ -976,7 +1142,8 @@ local slice
976local _accum_0 = { } 1142local _accum_0 = { }
977local _len_0 = 1 1143local _len_0 = 1
978local _list_0 = items 1144local _list_0 = items
979for _index_0 = 2, #_list_0 do 1145local _max_0 = #_list_0
1146for _index_0 = 2, _max_0 do
980 local item = _list_0[_index_0] 1147 local item = _list_0[_index_0]
981 _accum_0[_len_0] = item 1148 _accum_0[_len_0] = item
982 _len_0 = _len_0 + 1 1149 _len_0 = _len_0 + 1
@@ -986,12 +1153,46 @@ local slice
986local _accum_0 = { } 1153local _accum_0 = { }
987local _len_0 = 1 1154local _len_0 = 1
988local _list_0 = items 1155local _list_0 = items
989for _index_0 = 1, #_list_0, 2 do 1156local _max_0 = #_list_0
1157for _index_0 = 1, _max_0, 2 do
990 local item = _list_0[_index_0] 1158 local item = _list_0[_index_0]
991 _accum_0[_len_0] = item 1159 _accum_0[_len_0] = item
992 _len_0 = _len_0 + 1 1160 _len_0 = _len_0 + 1
993end 1161end
994slice = _accum_0 1162slice = _accum_0
1163local slice
1164local _accum_0 = { }
1165local _len_0 = 1
1166local _list_0 = items
1167local _min_0 = #_list_0 + -4 + 1
1168local _max_0 = #_list_0 + -1 + 1
1169for _index_0 = _min_0, _max_0 do
1170 local item = _list_0[_index_0]
1171 _accum_0[_len_0] = item
1172 _len_0 = _len_0 + 1
1173end
1174slice = _accum_0
1175local reverse_slice
1176local _accum_0 = { }
1177local _len_0 = 1
1178local _list_0 = items
1179local _min_0 = #_list_0 + -1 + 1
1180for _index_0 = _min_0, 1, -1 do
1181 local item = _list_0[_index_0]
1182 _accum_0[_len_0] = item
1183 _len_0 = _len_0 + 1
1184end
1185reverse_slice = _accum_0
1186local sub_list
1187local _accum_0 = { }
1188local _len_0 = 1
1189local _list_0 = items
1190for _index_0 = 2, 4 do
1191 local _item_0 = _list_0[_index_0]
1192 _accum_0[_len_0] = _item_0
1193 _len_0 = _len_0 + 1
1194end
1195sub_list = _accum_0
995for i = 10, 20 do 1196for i = 10, 20 do
996 print(i) 1197 print(i)
997end 1198end
@@ -1002,8 +1203,7 @@ for key, value in pairs(object) do
1002 print(key, value) 1203 print(key, value)
1003end 1204end
1004local _list_0 = items 1205local _list_0 = items
1005local _max_0 = 4 1206for _index_0 = 2, 4 do
1006for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1007 local item = _list_0[_index_0] 1207 local item = _list_0[_index_0]
1008 print(item) 1208 print(item)
1009end 1209end
@@ -1021,12 +1221,24 @@ local _len_0 = 1
1021for i = 1, 20 do 1221for i = 1, 20 do
1022 if i % 2 == 0 then 1222 if i % 2 == 0 then
1023 _accum_0[_len_0] = i * 2 1223 _accum_0[_len_0] = i * 2
1224 _len_0 = _len_0 + 1
1024 else 1225 else
1025 _accum_0[_len_0] = i 1226 _accum_0[_len_0] = i
1227 _len_0 = _len_0 + 1
1026 end 1228 end
1027 _len_0 = _len_0 + 1
1028end 1229end
1029doubled_evens = _accum_0 1230doubled_evens = _accum_0
1231local first_large
1232local _accum_0
1233local _list_0 = numbers
1234for _index_0 = 1, #_list_0 do
1235 local n = _list_0[_index_0]
1236 if n > 10 then
1237 _accum_0 = n
1238 break
1239 end
1240end
1241first_large = _accum_0
1030local func_a 1242local func_a
1031func_a = function() 1243func_a = function()
1032 for i = 1, 10 do 1244 for i = 1, 10 do
@@ -1175,7 +1387,7 @@ if "Robert" == name then
1175elseif "Dan" == name or "Daniel" == name then 1387elseif "Dan" == name or "Daniel" == name then
1176 print("你的名字是Dan") 1388 print("你的名字是Dan")
1177else 1389else
1178 print("我不知道你的名字") 1390 print("我不认识,你的名字" .. tostring(name))
1179end 1391end
1180local b = 1 1392local b = 1
1181local next_number 1393local next_number
@@ -1275,6 +1487,192 @@ if _tab_0 then
1275 end 1487 end
1276 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1488 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1277end 1489end
1490local _exp_0 = tb
1491local _type_0 = type(_exp_0)
1492local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1493local _match_0 = false
1494if _tab_0 then
1495 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1496 _match_0 = true
1497 print("1, 2, 3")
1498 end
1499end
1500if not _match_0 then
1501 local _match_1 = false
1502 if _tab_0 then
1503 local b = _exp_0[2]
1504 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1505 _match_1 = true
1506 print("1, " .. tostring(b) .. ", 3")
1507 end
1508 end
1509 if not _match_1 then
1510 if _tab_0 then
1511 local b = _exp_0[3]
1512 if b == nil then
1513 b = 3
1514 end
1515 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1516 print("1, 2, " .. tostring(b))
1517 end
1518 end
1519 end
1520end
1521local _exp_0 = tb
1522local _type_0 = type(_exp_0)
1523local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1524local _match_0 = false
1525if _tab_0 then
1526 local result = _exp_0.result
1527 if true == _exp_0.success and result ~= nil then
1528 _match_0 = true
1529 print("成功", result)
1530 end
1531end
1532if not _match_0 then
1533 local _match_1 = false
1534 if _tab_0 then
1535 if false == _exp_0.success then
1536 _match_1 = true
1537 print("失败", result)
1538 end
1539 end
1540 if not _match_1 then
1541 print("无效值")
1542 end
1543end
1544local _exp_0 = tb
1545local _type_0 = type(_exp_0)
1546local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1547local _match_0 = false
1548if _tab_0 then
1549 local content
1550 do
1551 local _obj_0 = _exp_0.data
1552 local _type_1 = type(_obj_0)
1553 if "table" == _type_1 or "userdata" == _type_1 then
1554 content = _obj_0.content
1555 end
1556 end
1557 local _val_0
1558 do
1559 local _obj_0 = _exp_0.data
1560 if _obj_0 ~= nil then
1561 _val_0 = _obj_0.type
1562 end
1563 end
1564 if "success" == _val_0 and content ~= nil then
1565 _match_0 = true
1566 print("成功", content)
1567 end
1568end
1569if not _match_0 then
1570 local _match_1 = false
1571 if _tab_0 then
1572 local content
1573 do
1574 local _obj_0 = _exp_0.data
1575 local _type_1 = type(_obj_0)
1576 if "table" == _type_1 or "userdata" == _type_1 then
1577 content = _obj_0.content
1578 end
1579 end
1580 local _val_0
1581 do
1582 local _obj_0 = _exp_0.data
1583 if _obj_0 ~= nil then
1584 _val_0 = _obj_0.type
1585 end
1586 end
1587 if "error" == _val_0 and content ~= nil then
1588 _match_1 = true
1589 print("失败", content)
1590 end
1591 end
1592 if not _match_1 then
1593 print("无效值")
1594 end
1595end
1596local _exp_0 = tb
1597local _type_0 = type(_exp_0)
1598local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1599if _tab_0 then
1600 local fourth = _exp_0[4]
1601 local _val_0
1602 do
1603 local _obj_0 = _exp_0[1]
1604 if _obj_0 ~= nil then
1605 _val_0 = _obj_0.a
1606 end
1607 end
1608 local _val_1
1609 do
1610 local _obj_0 = _exp_0[1]
1611 if _obj_0 ~= nil then
1612 _val_1 = _obj_0.b
1613 end
1614 end
1615 local _val_2
1616 do
1617 local _obj_0 = _exp_0[2]
1618 if _obj_0 ~= nil then
1619 _val_2 = _obj_0.a
1620 end
1621 end
1622 local _val_3
1623 do
1624 local _obj_0 = _exp_0[2]
1625 if _obj_0 ~= nil then
1626 _val_3 = _obj_0.b
1627 end
1628 end
1629 local _val_4
1630 do
1631 local _obj_0 = _exp_0[3]
1632 if _obj_0 ~= nil then
1633 _val_4 = _obj_0.a
1634 end
1635 end
1636 local _val_5
1637 do
1638 local _obj_0 = _exp_0[3]
1639 if _obj_0 ~= nil then
1640 _val_5 = _obj_0.b
1641 end
1642 end
1643 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
1644 print("匹配成功", fourth)
1645 end
1646end
1647local segments = {
1648 "admin",
1649 "users",
1650 "logs",
1651 "view"
1652}
1653local _type_0 = type(segments)
1654local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1655if _tab_0 then
1656 local groups
1657 do
1658 local _accum_0 = { }
1659 local _len_0 = 1
1660 local _max_0 = #segments + -3 + 1
1661 for _index_0 = 1, _max_0 do
1662 local _item_0 = segments[_index_0]
1663 _accum_0[_len_0] = _item_0
1664 _len_0 = _len_0 + 1
1665 end
1666 groups = _accum_0
1667 end
1668 local resource = segments[#segments - 1]
1669 local action = segments[#segments]
1670 if resource ~= nil and action ~= nil then
1671 print("Group:", groups)
1672 print("Resource:", resource)
1673 print("Action:", action)
1674 end
1675end
1278local Inventory 1676local Inventory
1279local _class_0 1677local _class_0
1280local _base_0 = { 1678local _base_0 = {
@@ -1931,6 +2329,10 @@ do
1931 _with_1["key-name"] = value 2329 _with_1["key-name"] = value
1932end 2330end
1933_with_0[#_with_0 + 1] = "abc" 2331_with_0[#_with_0 + 1] = "abc"
2332local _with_0 = obj
2333if _with_0 ~= nil then
2334 print(obj.name)
2335end
1934do 2336do
1935 local var = "hello" 2337 local var = "hello"
1936 print(var) 2338 print(var)
@@ -2021,6 +2423,38 @@ local inventory = {
2021 } 2423 }
2022 } 2424 }
2023} 2425}
2426local map
2427map = function(arr, action)
2428 local _accum_0 = { }
2429 local _len_0 = 1
2430 for _index_0 = 1, #arr do
2431 local item = arr[_index_0]
2432 _accum_0[_len_0] = action(item)
2433 _len_0 = _len_0 + 1
2434 end
2435 return _accum_0
2436end
2437local filter
2438filter = function(arr, cond)
2439 local _accum_0 = { }
2440 local _len_0 = 1
2441 for _index_0 = 1, #arr do
2442 local item = arr[_index_0]
2443 if cond(item) then
2444 _accum_0[_len_0] = item
2445 _len_0 = _len_0 + 1
2446 end
2447 end
2448 return _accum_0
2449end
2450local reduce
2451reduce = function(arr, init, action)
2452 for _index_0 = 1, #arr do
2453 local item = arr[_index_0]
2454 init = action(init, item)
2455 end
2456 return init
2457end
2024print(reduce(filter(map({ 2458print(reduce(filter(map({
2025 1, 2459 1,
2026 2, 2460 2,
@@ -2078,6 +2512,12 @@ end
2078print("yuescript") 2512print("yuescript")
2079print(3) 2513print(3)
2080print("有效的枚举类型:", "Static") 2514print("有效的枚举类型:", "Static")
2515do
2516 print(123, "hello")
2517end
2518do
2519 print(123, "hello")
2520end
2081if tb ~= nil then 2521if tb ~= nil then
2082 tb:func() 2522 tb:func()
2083end 2523end
@@ -2178,6 +2618,16 @@ for _key_0, _value_0 in pairs(b) do
2178 end 2618 end
2179end 2619end
2180merge = _tab_0 2620merge = _tab_0
2621local last
2622do
2623 local _item_0 = data.items
2624 last = _item_0[#_item_0]
2625end
2626local second_last
2627do
2628 local _item_0 = data.items
2629 second_last = _item_0[#_item_0 - 1]
2630end
2181local mt = { } 2631local mt = { }
2182local add 2632local add
2183add = function(self, right) 2633add = function(self, right)
@@ -2308,6 +2758,14 @@ func({
2308 2, 2758 2,
2309 3 2759 3
2310}) 2760})
2761local f
2762f = function()
2763 return {
2764 1,
2765 2,
2766 3
2767 }
2768end
2311local tb = { 2769local tb = {
2312 name = "abc", 2770 name = "abc",
2313 values = { 2771 values = {
@@ -2548,6 +3006,59 @@ end
2548local two, four 3006local two, four
2549local _obj_0 = items 3007local _obj_0 = items
2550two, four = _obj_0[2], _obj_0[4] 3008two, four = _obj_0[2], _obj_0[4]
3009local orders = {
3010 "first",
3011 "second",
3012 "third",
3013 "fourth",
3014 "last"
3015}
3016local first, bulk, last = orders[1], (function()
3017 local _accum_0 = { }
3018 local _len_0 = 1
3019 local _max_0 = #orders + -2 + 1
3020 for _index_0 = 2, _max_0 do
3021 local _item_0 = orders[_index_0]
3022 _accum_0[_len_0] = _item_0
3023 _len_0 = _len_0 + 1
3024 end
3025 return _accum_0
3026end)(), orders[#orders]
3027print(first)
3028print(bulk)
3029print(last)
3030local first, rest
3031do
3032 local _obj_0 = orders
3033 first, rest = _obj_0[1], (function()
3034 local _accum_0 = { }
3035 local _len_0 = 1
3036 local _max_0 = #_obj_0
3037 for _index_0 = 2, _max_0 do
3038 local _item_0 = _obj_0[_index_0]
3039 _accum_0[_len_0] = _item_0
3040 _len_0 = _len_0 + 1
3041 end
3042 return _accum_0
3043 end)()
3044end
3045local start, last
3046do
3047 local _obj_0 = orders
3048 start, last = (function()
3049 local _accum_0 = { }
3050 local _len_0 = 1
3051 local _max_0 = #_obj_0 + -2 + 1
3052 for _index_0 = 1, _max_0 do
3053 local _item_0 = _obj_0[_index_0]
3054 _accum_0[_len_0] = _item_0
3055 _len_0 = _len_0 + 1
3056 end
3057 return _accum_0
3058 end)(), _obj_0[#_obj_0]
3059end
3060local _obj_0 = orders
3061first, last = _obj_0[1], _obj_0[#_obj_0]
2551local tuples = { 3062local tuples = {
2552 { 3063 {
2553 "hello", 3064 "hello",
@@ -2649,6 +3160,56 @@ end)
2649if success then 3160if success then
2650 print(result) 3161 print(result)
2651end 3162end
3163local a, b, c
3164do
3165 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3166 return func()
3167 end)
3168 if _ok_0 then
3169 a, b, c = _ret_0, _ret_1, _ret_2
3170 end
3171end
3172do
3173 local _exp_0 = ((function()
3174 return (function(_arg_0, ...)
3175 local _ok_0 = _arg_0
3176 if _ok_0 then
3177 return ...
3178 end
3179 end)(pcall(function()
3180 return func()
3181 end))
3182 end)())
3183 if _exp_0 ~= nil then
3184 a = _exp_0
3185 else
3186 a = "default"
3187 end
3188end
3189f((function()
3190 return (function(_arg_0, ...)
3191 local _ok_0 = _arg_0
3192 if _ok_0 then
3193 return ...
3194 end
3195 end)(pcall(function()
3196 return func()
3197 end))
3198end)())
3199f((function()
3200 return (function(_arg_0, ...)
3201 local _ok_0 = _arg_0
3202 if _ok_0 then
3203 return ...
3204 end
3205 end)(xpcall(function()
3206 print(123)
3207 return func()
3208 end, function(e)
3209 print(e)
3210 return e
3211 end))
3212end)())
2652local a <const> = 123 3213local a <const> = 123
2653local _ <close> = setmetatable({ }, { 3214local _ <close> = setmetatable({ }, {
2654 __close = function() 3215 __close = function()
@@ -2658,10 +3219,19 @@ local _ <close> = setmetatable({ }, {
2658local a, b, c, d 3219local a, b, c, d
2659local _obj_0 = tb 3220local _obj_0 = tb
2660a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3221a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3222Constant = 123
2661local some_string = "这是一个字符串\n 并包括一个换行。" 3223local some_string = "这是一个字符串\n 并包括一个换行。"
2662print("我有" .. tostring(math.random() * 100) .. "%的把握。") 3224print("我有" .. tostring(math.random() * 100) .. "%的把握。")
2663local integer = 1000000 3225local integer = 1000000
2664local hex = 0xEFBBBF 3226local hex = 0xEFBBBF
3227local binary = 19
3228local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3229local fn
3230fn = function()
3231 local str = "foo:\n bar: baz"
3232 return str
3233end
3234local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2665local my_function 3235local my_function
2666my_function = function() end 3236my_function = function() end
2667my_function() 3237my_function()
@@ -2855,11 +3425,10 @@ for i, item in ipairs(items) do
2855 _len_0 = _len_0 + 1 3425 _len_0 = _len_0 + 1
2856end 3426end
2857doubled = _accum_0 3427doubled = _accum_0
2858local iter = ipairs(items)
2859local slice 3428local slice
2860local _accum_0 = { } 3429local _accum_0 = { }
2861local _len_0 = 1 3430local _len_0 = 1
2862for i, item in iter do 3431for i, item in ipairs(items) do
2863 if i > 1 and i < 3 then 3432 if i > 1 and i < 3 then
2864 _accum_0[_len_0] = item 3433 _accum_0[_len_0] = item
2865 _len_0 = _len_0 + 1 3434 _len_0 = _len_0 + 1
@@ -2966,8 +3535,7 @@ local slice
2966local _accum_0 = { } 3535local _accum_0 = { }
2967local _len_0 = 1 3536local _len_0 = 1
2968local _list_0 = items 3537local _list_0 = items
2969local _max_0 = 5 3538for _index_0 = 1, 5 do
2970for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
2971 local item = _list_0[_index_0] 3539 local item = _list_0[_index_0]
2972 _accum_0[_len_0] = item 3540 _accum_0[_len_0] = item
2973 _len_0 = _len_0 + 1 3541 _len_0 = _len_0 + 1
@@ -2977,7 +3545,8 @@ local slice
2977local _accum_0 = { } 3545local _accum_0 = { }
2978local _len_0 = 1 3546local _len_0 = 1
2979local _list_0 = items 3547local _list_0 = items
2980for _index_0 = 2, #_list_0 do 3548local _max_0 = #_list_0
3549for _index_0 = 2, _max_0 do
2981 local item = _list_0[_index_0] 3550 local item = _list_0[_index_0]
2982 _accum_0[_len_0] = item 3551 _accum_0[_len_0] = item
2983 _len_0 = _len_0 + 1 3552 _len_0 = _len_0 + 1
@@ -2987,12 +3556,46 @@ local slice
2987local _accum_0 = { } 3556local _accum_0 = { }
2988local _len_0 = 1 3557local _len_0 = 1
2989local _list_0 = items 3558local _list_0 = items
2990for _index_0 = 1, #_list_0, 2 do 3559local _max_0 = #_list_0
3560for _index_0 = 1, _max_0, 2 do
2991 local item = _list_0[_index_0] 3561 local item = _list_0[_index_0]
2992 _accum_0[_len_0] = item 3562 _accum_0[_len_0] = item
2993 _len_0 = _len_0 + 1 3563 _len_0 = _len_0 + 1
2994end 3564end
2995slice = _accum_0 3565slice = _accum_0
3566local slice
3567local _accum_0 = { }
3568local _len_0 = 1
3569local _list_0 = items
3570local _min_0 = #_list_0 + -4 + 1
3571local _max_0 = #_list_0 + -1 + 1
3572for _index_0 = _min_0, _max_0 do
3573 local item = _list_0[_index_0]
3574 _accum_0[_len_0] = item
3575 _len_0 = _len_0 + 1
3576end
3577slice = _accum_0
3578local reverse_slice
3579local _accum_0 = { }
3580local _len_0 = 1
3581local _list_0 = items
3582local _min_0 = #_list_0 + -1 + 1
3583for _index_0 = _min_0, 1, -1 do
3584 local item = _list_0[_index_0]
3585 _accum_0[_len_0] = item
3586 _len_0 = _len_0 + 1
3587end
3588reverse_slice = _accum_0
3589local sub_list
3590local _accum_0 = { }
3591local _len_0 = 1
3592local _list_0 = items
3593for _index_0 = 2, 4 do
3594 local _item_0 = _list_0[_index_0]
3595 _accum_0[_len_0] = _item_0
3596 _len_0 = _len_0 + 1
3597end
3598sub_list = _accum_0
2996for i = 10, 20 do 3599for i = 10, 20 do
2997 print(i) 3600 print(i)
2998end 3601end
@@ -3003,8 +3606,7 @@ for key, value in pairs(object) do
3003 print(key, value) 3606 print(key, value)
3004end 3607end
3005local _list_0 = items 3608local _list_0 = items
3006local _max_0 = 4 3609for _index_0 = 2, 4 do
3007for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3008 local item = _list_0[_index_0] 3610 local item = _list_0[_index_0]
3009 print(item) 3611 print(item)
3010end 3612end
@@ -3022,12 +3624,24 @@ local _len_0 = 1
3022for i = 1, 20 do 3624for i = 1, 20 do
3023 if i % 2 == 0 then 3625 if i % 2 == 0 then
3024 _accum_0[_len_0] = i * 2 3626 _accum_0[_len_0] = i * 2
3627 _len_0 = _len_0 + 1
3025 else 3628 else
3026 _accum_0[_len_0] = i 3629 _accum_0[_len_0] = i
3630 _len_0 = _len_0 + 1
3027 end 3631 end
3028 _len_0 = _len_0 + 1
3029end 3632end
3030doubled_evens = _accum_0 3633doubled_evens = _accum_0
3634local first_large
3635local _accum_0
3636local _list_0 = numbers
3637for _index_0 = 1, #_list_0 do
3638 local n = _list_0[_index_0]
3639 if n > 10 then
3640 _accum_0 = n
3641 break
3642 end
3643end
3644first_large = _accum_0
3031local func_a 3645local func_a
3032func_a = function() 3646func_a = function()
3033 for i = 1, 10 do 3647 for i = 1, 10 do
@@ -3176,7 +3790,7 @@ if "Robert" == name then
3176elseif "Dan" == name or "Daniel" == name then 3790elseif "Dan" == name or "Daniel" == name then
3177 print("你的名字是Dan") 3791 print("你的名字是Dan")
3178else 3792else
3179 print("我不知道你的名字") 3793 print("我不认识,你的名字" .. tostring(name))
3180end 3794end
3181local b = 1 3795local b = 1
3182local next_number 3796local next_number
@@ -3276,6 +3890,192 @@ if _tab_0 then
3276 end 3890 end
3277 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3891 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3278end 3892end
3893local _exp_0 = tb
3894local _type_0 = type(_exp_0)
3895local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3896local _match_0 = false
3897if _tab_0 then
3898 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3899 _match_0 = true
3900 print("1, 2, 3")
3901 end
3902end
3903if not _match_0 then
3904 local _match_1 = false
3905 if _tab_0 then
3906 local b = _exp_0[2]
3907 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3908 _match_1 = true
3909 print("1, " .. tostring(b) .. ", 3")
3910 end
3911 end
3912 if not _match_1 then
3913 if _tab_0 then
3914 local b = _exp_0[3]
3915 if b == nil then
3916 b = 3
3917 end
3918 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3919 print("1, 2, " .. tostring(b))
3920 end
3921 end
3922 end
3923end
3924local _exp_0 = tb
3925local _type_0 = type(_exp_0)
3926local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3927local _match_0 = false
3928if _tab_0 then
3929 local result = _exp_0.result
3930 if true == _exp_0.success and result ~= nil then
3931 _match_0 = true
3932 print("成功", result)
3933 end
3934end
3935if not _match_0 then
3936 local _match_1 = false
3937 if _tab_0 then
3938 if false == _exp_0.success then
3939 _match_1 = true
3940 print("失败", result)
3941 end
3942 end
3943 if not _match_1 then
3944 print("无效值")
3945 end
3946end
3947local _exp_0 = tb
3948local _type_0 = type(_exp_0)
3949local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3950local _match_0 = false
3951if _tab_0 then
3952 local content
3953 do
3954 local _obj_0 = _exp_0.data
3955 local _type_1 = type(_obj_0)
3956 if "table" == _type_1 or "userdata" == _type_1 then
3957 content = _obj_0.content
3958 end
3959 end
3960 local _val_0
3961 do
3962 local _obj_0 = _exp_0.data
3963 if _obj_0 ~= nil then
3964 _val_0 = _obj_0.type
3965 end
3966 end
3967 if "success" == _val_0 and content ~= nil then
3968 _match_0 = true
3969 print("成功", content)
3970 end
3971end
3972if not _match_0 then
3973 local _match_1 = false
3974 if _tab_0 then
3975 local content
3976 do
3977 local _obj_0 = _exp_0.data
3978 local _type_1 = type(_obj_0)
3979 if "table" == _type_1 or "userdata" == _type_1 then
3980 content = _obj_0.content
3981 end
3982 end
3983 local _val_0
3984 do
3985 local _obj_0 = _exp_0.data
3986 if _obj_0 ~= nil then
3987 _val_0 = _obj_0.type
3988 end
3989 end
3990 if "error" == _val_0 and content ~= nil then
3991 _match_1 = true
3992 print("失败", content)
3993 end
3994 end
3995 if not _match_1 then
3996 print("无效值")
3997 end
3998end
3999local _exp_0 = tb
4000local _type_0 = type(_exp_0)
4001local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4002if _tab_0 then
4003 local fourth = _exp_0[4]
4004 local _val_0
4005 do
4006 local _obj_0 = _exp_0[1]
4007 if _obj_0 ~= nil then
4008 _val_0 = _obj_0.a
4009 end
4010 end
4011 local _val_1
4012 do
4013 local _obj_0 = _exp_0[1]
4014 if _obj_0 ~= nil then
4015 _val_1 = _obj_0.b
4016 end
4017 end
4018 local _val_2
4019 do
4020 local _obj_0 = _exp_0[2]
4021 if _obj_0 ~= nil then
4022 _val_2 = _obj_0.a
4023 end
4024 end
4025 local _val_3
4026 do
4027 local _obj_0 = _exp_0[2]
4028 if _obj_0 ~= nil then
4029 _val_3 = _obj_0.b
4030 end
4031 end
4032 local _val_4
4033 do
4034 local _obj_0 = _exp_0[3]
4035 if _obj_0 ~= nil then
4036 _val_4 = _obj_0.a
4037 end
4038 end
4039 local _val_5
4040 do
4041 local _obj_0 = _exp_0[3]
4042 if _obj_0 ~= nil then
4043 _val_5 = _obj_0.b
4044 end
4045 end
4046 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
4047 print("匹配成功", fourth)
4048 end
4049end
4050local segments = {
4051 "admin",
4052 "users",
4053 "logs",
4054 "view"
4055}
4056local _type_0 = type(segments)
4057local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4058if _tab_0 then
4059 local groups
4060 do
4061 local _accum_0 = { }
4062 local _len_0 = 1
4063 local _max_0 = #segments + -3 + 1
4064 for _index_0 = 1, _max_0 do
4065 local _item_0 = segments[_index_0]
4066 _accum_0[_len_0] = _item_0
4067 _len_0 = _len_0 + 1
4068 end
4069 groups = _accum_0
4070 end
4071 local resource = segments[#segments - 1]
4072 local action = segments[#segments]
4073 if resource ~= nil and action ~= nil then
4074 print("Group:", groups)
4075 print("Resource:", resource)
4076 print("Action:", action)
4077 end
4078end
3279local Inventory 4079local Inventory
3280local _class_0 4080local _class_0
3281local _base_0 = { 4081local _base_0 = {
@@ -3932,6 +4732,10 @@ do
3932 _with_1["key-name"] = value 4732 _with_1["key-name"] = value
3933end 4733end
3934_with_0[#_with_0 + 1] = "abc" 4734_with_0[#_with_0 + 1] = "abc"
4735local _with_0 = obj
4736if _with_0 ~= nil then
4737 print(obj.name)
4738end
3935do 4739do
3936 local var = "hello" 4740 local var = "hello"
3937 print(var) 4741 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/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/global.lua b/spec/outputs/global.lua
index 54a21a9..3918f85 100644
--- a/spec/outputs/global.lua
+++ b/spec/outputs/global.lua
@@ -93,3 +93,28 @@ do
93 FooBar = "pascal case" 93 FooBar = "pascal case"
94 FOOBAR = "all uppercase" 94 FOOBAR = "all uppercase"
95end 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 4d31574..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
@@ -213,6 +217,13 @@ function tb:func()
213end 217end
214end 218end
215print(x) 219print(x)
220local yue = require("yue")
221do
222local function f2(a)
223 return a + 1
224end
225x = x + f2(3)
226end
216local sel 227local sel
217sel = function(a, b, c) 228sel = function(a, b, c)
218 if a then 229 if a then
@@ -317,7 +328,7 @@ print((setmetatable({
317 return 998 328 return 998
318 end 329 end
319})) 330}))
320print("current line: " .. tostring(323)) 331print("current line: " .. tostring(349))
321do 332do
322 do 333 do
323-- TODO 334-- TODO
@@ -330,10 +341,8 @@ local _1
330_1 = function() 341_1 = function()
331 print(1) 342 print(1)
332 local _accum_0 = { } 343 local _accum_0 = { }
333 local _len_0 = 1
334 while false do 344 while false do
335 break 345 break
336 _len_0 = _len_0 + 1
337 end 346 end
338 return _accum_0 347 return _accum_0
339end 348end
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/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 099080f..b4e78cd 100644
--- a/spec/outputs/unicode/macro.lua
+++ b/spec/outputs/unicode/macro.lua
@@ -215,24 +215,8 @@ do
215-- 这有个注释 215-- 这有个注释
216end 216end
217local _ = require('下划线') 217local _ = require('下划线')
218local _call_0 = (_({ 218local _anon_func_0 = function(_)
219 1, 219 local _call_0 = (_({
220 2,
221 3,
222 4,
223 -2,
224 3
225}))
226_call_0 = _call_0["链"](_call_0)
227_call_0 = _call_0["映射"](_call_0, function(self)
228 return self * 2
229end)
230_call_0 = _call_0["过滤"](_call_0, function(self)
231 return self > 3
232end)
233local _u7ed3_u679ca = _call_0["取值"](_call_0)
234do
235 local _call_1 = (_({
236 1, 220 1,
237 2, 221 2,
238 3, 222 3,
@@ -240,27 +224,70 @@ do
240 -2, 224 -2,
241 3 225 3
242 })) 226 }))
243 _call_1 = _call_1["链"](_call_1) 227 return _call_0["链"](_call_0)
244 _call_1 = _call_1["映射"](_call_1, function(self) 228end
245 return self * 2 229local _call_0 = ((function()
246 end) 230 local _call_0 = ((function()
247 _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)
248 return self > 3 237 return self > 3
249 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)())
250 _call_1["每一个"](_call_1, function(self) 264 _call_1["每一个"](_call_1, function(self)
251 return _u6253_u5370(self) 265 return _u6253_u5370(self)
252 end) 266 end)
253end 267end
254local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] 268local _anon_func_2 = function(_u539f_u70b9)
255_call_1 = _call_1["父节点"](_call_1) 269 local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"]
256_call_1 = _call_1["后代"](_call_1) 270 return _call_1["父节点"](_call_1)
257_call_1 = _call_1["选择启用"](_call_1) 271end
258_call_1 = _call_1["选择可见"](_call_1) 272local _call_1 = ((function()
259_call_1 = _call_1["标签等于"](_call_1, "fx") 273 local _call_1 = ((function()
260_call_1 = _call_1["其中"](_call_1, function(x) 274 local _call_1 = ((function()
261 local _call_2 = x["名称"] 275 local _call_1 = ((function()
262 return _call_2["结尾为"](_call_2, "(克隆)") 276 local _call_1 = ((function()
263end) 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)())
264_u7ed3_u679c = _call_1["摧毁"](_call_1) 291_u7ed3_u679c = _call_1["摧毁"](_call_1)
265do 292do
266 do 293 do
@@ -332,10 +359,8 @@ local _1
332_1 = function() 359_1 = function()
333 _u6253_u5370(1) 360 _u6253_u5370(1)
334 local _accum_0 = { } 361 local _accum_0 = { }
335 local _len_0 = 1
336 while false do 362 while false do
337 break 363 break
338 _len_0 = _len_0 + 1
339 end 364 end
340 return _accum_0 365 return _accum_0
341end 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/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/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 1a795c1..530915e 100644
--- a/spec/outputs/with.lua
+++ b/spec/outputs/with.lua
@@ -187,4 +187,66 @@ do
187 return _with_0[123] 187 return _with_0[123]
188 end 188 end
189end 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
190return nil 252return nil