diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-06-04 11:38:34 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-06-04 11:38:34 +0800 |
| commit | 548ab1d9ff5b831050f14f1355a3314a41163ad6 (patch) | |
| tree | d84b6b64b4e547070c7c43db53821b83b819ab8e /spec | |
| parent | 98be64dd52df92f7fdd40bae225c279db1676cab (diff) | |
| download | yuescript-548ab1d9ff5b831050f14f1355a3314a41163ad6.tar.gz yuescript-548ab1d9ff5b831050f14f1355a3314a41163ad6.tar.bz2 yuescript-548ab1d9ff5b831050f14f1355a3314a41163ad6.zip | |
Added new syntax.
- Slice Expression.
- Reversed Indexing,.
- Range Destructuring.
- Table Range Matching.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/destructure.yue | 38 | ||||
| -rw-r--r-- | spec/inputs/lists.yue | 47 | ||||
| -rw-r--r-- | spec/inputs/switch.yue | 17 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 8 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 8 | ||||
| -rw-r--r-- | spec/outputs/comprehension.lua | 4 | ||||
| -rw-r--r-- | spec/outputs/destructure.lua | 90 | ||||
| -rw-r--r-- | spec/outputs/lists.lua | 192 | ||||
| -rw-r--r-- | spec/outputs/switch.lua | 50 | ||||
| -rw-r--r-- | spec/outputs/unicode/comprehension.lua | 4 | ||||
| -rw-r--r-- | spec/outputs/unicode/lists.lua | 6 |
11 files changed, 446 insertions, 18 deletions
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index 9f01a20..b6250d0 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue | |||
| @@ -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 | |||
| 244 | do | ||
| 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 | |||
| 251 | do | ||
| 252 | setupMeeting = (participants) -> | ||
| 253 | [chair, ..._, secretary] = participants | ||
| 254 | print chair, secretary | ||
| 255 | |||
| 256 | setupMeeting ["Alice", "Bob", "Charlie", "David"] | ||
| 257 | -- Output: Alice David | ||
| 258 | |||
| 259 | do | ||
| 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 | |||
| 271 | do | ||
| 272 | [ | ||
| 273 | _ | ||
| 274 | ...middle | ||
| 275 | _ | ||
| 276 | ] = tb | ||
| 277 | |||
| 278 | do | ||
| 279 | {a, :abc, b, :def, ...sub, d, e} = tb | ||
| 280 | |||
| 243 | nil | 281 | nil |
| 244 | 282 | ||
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 | ||
| 90 | do | ||
| 91 | transactions = ["T001", "T002", "T003", "T004", "T005"] | ||
| 92 | middleTransactions = transactions[2, -2] | ||
| 93 | print middleTransactions -- => {"T002", "T003", "T004"} | ||
| 94 | |||
| 95 | do | ||
| 96 | logs = | ||
| 97 | - start: 0, end: 100 | ||
| 98 | - start: 100, end: 200 | ||
| 99 | - start: 200, end: 123 | ||
| 100 | print logs[#].end -- => 123 | ||
| 101 | |||
| 102 | do | ||
| 103 | pendingOrders = ["O001", "O002", "O003", "O004"] | ||
| 104 | print pendingOrders[# - 1] -- => "O003" | ||
| 105 | |||
| 106 | do | ||
| 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 | |||
| 117 | do | ||
| 118 | cloneList1 = (list) -> list[,] | ||
| 119 | cloneList2 = (list) -> [...list,] | ||
| 120 | cloneTable = (tb) -> {...tb} | ||
| 121 | |||
| 122 | do | ||
| 123 | print( | ||
| 124 | globalTB[#] | ||
| 125 | a.b.c[# - 2] | ||
| 126 | x?\y?!.z?[# - 3] | ||
| 127 | ) | ||
| 128 | |||
| 129 | do | ||
| 130 | f = -> | ||
| 131 | print( | ||
| 132 | globalTB[#]\end 123 | ||
| 133 | a.b.c[5,-5][# - 2] | ||
| 134 | x?\y?!.z?[# - 3]?[, -3] | ||
| 135 | ) | ||
| 136 | |||
| 90 | nil | 137 | nil |
diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue index 5097db3..2b0669c 100644 --- a/spec/inputs/switch.yue +++ b/spec/inputs/switch.yue | |||
| @@ -272,4 +272,21 @@ do | |||
| 272 | else | 272 | else |
| 273 | print "not matched" | 273 | print "not matched" |
| 274 | 274 | ||
| 275 | do | ||
| 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 | |||
| 283 | do | ||
| 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 | |||
| 275 | nil | 292 | nil |
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index cce0516..b8dd9b7 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -1063,7 +1063,7 @@ local _accum_0 = { } | |||
| 1063 | local _len_0 = 1 | 1063 | local _len_0 = 1 |
| 1064 | local _list_0 = items | 1064 | local _list_0 = items |
| 1065 | local _max_0 = 5 | 1065 | local _max_0 = 5 |
| 1066 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 1066 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 1067 | local item = _list_0[_index_0] | 1067 | local item = _list_0[_index_0] |
| 1068 | _accum_0[_len_0] = item | 1068 | _accum_0[_len_0] = item |
| 1069 | _len_0 = _len_0 + 1 | 1069 | _len_0 = _len_0 + 1 |
| @@ -1100,7 +1100,7 @@ for key, value in pairs(object) do | |||
| 1100 | end | 1100 | end |
| 1101 | local _list_0 = items | 1101 | local _list_0 = items |
| 1102 | local _max_0 = 4 | 1102 | local _max_0 = 4 |
| 1103 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 1103 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 1104 | local item = _list_0[_index_0] | 1104 | local item = _list_0[_index_0] |
| 1105 | print(item) | 1105 | print(item) |
| 1106 | end | 1106 | end |
| @@ -3333,7 +3333,7 @@ local _accum_0 = { } | |||
| 3333 | local _len_0 = 1 | 3333 | local _len_0 = 1 |
| 3334 | local _list_0 = items | 3334 | local _list_0 = items |
| 3335 | local _max_0 = 5 | 3335 | local _max_0 = 5 |
| 3336 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 3336 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 3337 | local item = _list_0[_index_0] | 3337 | local item = _list_0[_index_0] |
| 3338 | _accum_0[_len_0] = item | 3338 | _accum_0[_len_0] = item |
| 3339 | _len_0 = _len_0 + 1 | 3339 | _len_0 = _len_0 + 1 |
| @@ -3370,7 +3370,7 @@ for key, value in pairs(object) do | |||
| 3370 | end | 3370 | end |
| 3371 | local _list_0 = items | 3371 | local _list_0 = items |
| 3372 | local _max_0 = 4 | 3372 | local _max_0 = 4 |
| 3373 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 3373 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 3374 | local item = _list_0[_index_0] | 3374 | local item = _list_0[_index_0] |
| 3375 | print(item) | 3375 | print(item) |
| 3376 | end | 3376 | end |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index e267709..80644a5 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -1057,7 +1057,7 @@ local _accum_0 = { } | |||
| 1057 | local _len_0 = 1 | 1057 | local _len_0 = 1 |
| 1058 | local _list_0 = items | 1058 | local _list_0 = items |
| 1059 | local _max_0 = 5 | 1059 | local _max_0 = 5 |
| 1060 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 1060 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 1061 | local item = _list_0[_index_0] | 1061 | local item = _list_0[_index_0] |
| 1062 | _accum_0[_len_0] = item | 1062 | _accum_0[_len_0] = item |
| 1063 | _len_0 = _len_0 + 1 | 1063 | _len_0 = _len_0 + 1 |
| @@ -1094,7 +1094,7 @@ for key, value in pairs(object) do | |||
| 1094 | end | 1094 | end |
| 1095 | local _list_0 = items | 1095 | local _list_0 = items |
| 1096 | local _max_0 = 4 | 1096 | local _max_0 = 4 |
| 1097 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 1097 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 1098 | local item = _list_0[_index_0] | 1098 | local item = _list_0[_index_0] |
| 1099 | print(item) | 1099 | print(item) |
| 1100 | end | 1100 | end |
| @@ -3321,7 +3321,7 @@ local _accum_0 = { } | |||
| 3321 | local _len_0 = 1 | 3321 | local _len_0 = 1 |
| 3322 | local _list_0 = items | 3322 | local _list_0 = items |
| 3323 | local _max_0 = 5 | 3323 | local _max_0 = 5 |
| 3324 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 3324 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 3325 | local item = _list_0[_index_0] | 3325 | local item = _list_0[_index_0] |
| 3326 | _accum_0[_len_0] = item | 3326 | _accum_0[_len_0] = item |
| 3327 | _len_0 = _len_0 + 1 | 3327 | _len_0 = _len_0 + 1 |
| @@ -3358,7 +3358,7 @@ for key, value in pairs(object) do | |||
| 3358 | end | 3358 | end |
| 3359 | local _list_0 = items | 3359 | local _list_0 = items |
| 3360 | local _max_0 = 4 | 3360 | local _max_0 = 4 |
| 3361 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 3361 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do |
| 3362 | local item = _list_0[_index_0] | 3362 | local item = _list_0[_index_0] |
| 3363 | print(item) | 3363 | print(item) |
| 3364 | end | 3364 | end |
diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua index 9a7c478..ac4f9d8 100644 --- a/spec/outputs/comprehension.lua +++ b/spec/outputs/comprehension.lua | |||
| @@ -244,7 +244,7 @@ do | |||
| 244 | local _accum_0 = { } | 244 | local _accum_0 = { } |
| 245 | local _len_0 = 1 | 245 | local _len_0 = 1 |
| 246 | local _max_0 = 3 + 4 | 246 | local _max_0 = 3 + 4 |
| 247 | for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do | 247 | for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 + 1 or _max_0 do |
| 248 | local item = items[_index_0] | 248 | local item = items[_index_0] |
| 249 | _accum_0[_len_0] = item | 249 | _accum_0[_len_0] = item |
| 250 | _len_0 = _len_0 + 1 | 250 | _len_0 = _len_0 + 1 |
| @@ -255,7 +255,7 @@ do | |||
| 255 | local _accum_0 = { } | 255 | local _accum_0 = { } |
| 256 | local _len_0 = 1 | 256 | local _len_0 = 1 |
| 257 | local _max_0 = 2 - thing[4] | 257 | local _max_0 = 2 - thing[4] |
| 258 | for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 or _max_0 do | 258 | for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 + 1 or _max_0 do |
| 259 | local item = items[_index_0] | 259 | local item = items[_index_0] |
| 260 | _accum_0[_len_0] = item | 260 | _accum_0[_len_0] = item |
| 261 | _len_0 = _len_0 + 1 | 261 | _len_0 = _len_0 + 1 |
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 44da58b..216d921 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 |
| 623 | end | 623 | end |
| 624 | do | ||
| 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 = -2 | ||
| 635 | for _index_0 = 2, _max_0 < 0 and #clients + _max_0 + 1 or _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) | ||
| 645 | end | ||
| 646 | do | ||
| 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 | }) | ||
| 658 | end | ||
| 659 | do | ||
| 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) | ||
| 685 | end | ||
| 686 | do | ||
| 687 | local middle | ||
| 688 | local _accum_0 = { } | ||
| 689 | local _len_0 = 1 | ||
| 690 | local _list_0 = tb | ||
| 691 | local _max_0 = -2 | ||
| 692 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 + 1 or _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 | ||
| 698 | end | ||
| 699 | do | ||
| 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 = -3 | ||
| 706 | for _index_0 = 3, _max_0 < 0 and #_obj_0 + _max_0 + 1 or _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] | ||
| 713 | end | ||
| 624 | return nil | 714 | return nil |
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua index 48ec9c8..1bdfa3e 100644 --- a/spec/outputs/lists.lua +++ b/spec/outputs/lists.lua | |||
| @@ -231,12 +231,12 @@ x = { | |||
| 231 | 7 | 231 | 7 |
| 232 | } | 232 | } |
| 233 | local _max_0 = -5 | 233 | local _max_0 = -5 |
| 234 | for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do | 234 | for _index_0 = 2, _max_0 < 0 and #x + _max_0 + 1 or _max_0, 2 do |
| 235 | local y = x[_index_0] | 235 | local y = x[_index_0] |
| 236 | print(y) | 236 | print(y) |
| 237 | end | 237 | end |
| 238 | local _max_1 = 3 | 238 | local _max_1 = 3 |
| 239 | for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do | 239 | for _index_0 = 1, _max_1 < 0 and #x + _max_1 + 1 or _max_1 do |
| 240 | local y = x[_index_0] | 240 | local y = x[_index_0] |
| 241 | print(y) | 241 | print(y) |
| 242 | end | 242 | end |
| @@ -254,7 +254,7 @@ for _index_0 = 2, #x, 2 do | |||
| 254 | end | 254 | end |
| 255 | local a, b, c = 1, 5, 2 | 255 | local a, b, c = 1, 5, 2 |
| 256 | local _max_2 = b | 256 | local _max_2 = b |
| 257 | for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do | 257 | for _index_0 = a, _max_2 < 0 and #x + _max_2 + 1 or _max_2, c do |
| 258 | local y = x[_index_0] | 258 | local y = x[_index_0] |
| 259 | print(y) | 259 | print(y) |
| 260 | end | 260 | end |
| @@ -327,4 +327,190 @@ do | |||
| 327 | job = "jobless" | 327 | job = "jobless" |
| 328 | end | 328 | end |
| 329 | end | 329 | end |
| 330 | do | ||
| 331 | local transactions = { | ||
| 332 | "T001", | ||
| 333 | "T002", | ||
| 334 | "T003", | ||
| 335 | "T004", | ||
| 336 | "T005" | ||
| 337 | } | ||
| 338 | local middleTransactions | ||
| 339 | do | ||
| 340 | local _accum_0 = { } | ||
| 341 | local _len_0 = 1 | ||
| 342 | local _max_3 = -2 | ||
| 343 | for _index_0 = 2, _max_3 < 0 and #transactions + _max_3 + 1 or _max_3 do | ||
| 344 | local _item_0 = transactions[_index_0] | ||
| 345 | _accum_0[_len_0] = _item_0 | ||
| 346 | _len_0 = _len_0 + 1 | ||
| 347 | end | ||
| 348 | middleTransactions = _accum_0 | ||
| 349 | end | ||
| 350 | print(middleTransactions) | ||
| 351 | end | ||
| 352 | do | ||
| 353 | local logs = { | ||
| 354 | { | ||
| 355 | start = 0, | ||
| 356 | ["end"] = 100 | ||
| 357 | }, | ||
| 358 | { | ||
| 359 | start = 100, | ||
| 360 | ["end"] = 200 | ||
| 361 | }, | ||
| 362 | { | ||
| 363 | start = 200, | ||
| 364 | ["end"] = 123 | ||
| 365 | } | ||
| 366 | } | ||
| 367 | print(logs[#logs]["end"]) | ||
| 368 | end | ||
| 369 | do | ||
| 370 | local pendingOrders = { | ||
| 371 | "O001", | ||
| 372 | "O002", | ||
| 373 | "O003", | ||
| 374 | "O004" | ||
| 375 | } | ||
| 376 | print(pendingOrders[#pendingOrders - 1]) | ||
| 377 | end | ||
| 378 | do | ||
| 379 | local getOrders | ||
| 380 | getOrders = function() | ||
| 381 | return { | ||
| 382 | { | ||
| 383 | id = "O1001", | ||
| 384 | status = "pending" | ||
| 385 | }, | ||
| 386 | { | ||
| 387 | id = "O1002", | ||
| 388 | status = "processing" | ||
| 389 | }, | ||
| 390 | { | ||
| 391 | id = "O1003", | ||
| 392 | status = "done" | ||
| 393 | } | ||
| 394 | } | ||
| 395 | end | ||
| 396 | local lastStatus | ||
| 397 | do | ||
| 398 | local _item_0 = getOrders() | ||
| 399 | lastStatus = _item_0[#_item_0].status | ||
| 400 | end | ||
| 401 | assert(lastStatus == "done") | ||
| 402 | end | ||
| 403 | do | ||
| 404 | local cloneList1 | ||
| 405 | cloneList1 = function(list) | ||
| 406 | local _accum_0 = { } | ||
| 407 | local _len_0 = 1 | ||
| 408 | for _index_0 = 1, #list do | ||
| 409 | local _item_0 = list[_index_0] | ||
| 410 | _accum_0[_len_0] = _item_0 | ||
| 411 | _len_0 = _len_0 + 1 | ||
| 412 | end | ||
| 413 | return _accum_0 | ||
| 414 | end | ||
| 415 | local cloneList2 | ||
| 416 | cloneList2 = function(list) | ||
| 417 | local _tab_0 = { } | ||
| 418 | local _idx_0 = #_tab_0 + 1 | ||
| 419 | for _index_0 = 1, #list do | ||
| 420 | local _value_0 = list[_index_0] | ||
| 421 | _tab_0[_idx_0] = _value_0 | ||
| 422 | _idx_0 = _idx_0 + 1 | ||
| 423 | end | ||
| 424 | return _tab_0 | ||
| 425 | end | ||
| 426 | local cloneTable | ||
| 427 | cloneTable = function(tb) | ||
| 428 | local _tab_0 = { } | ||
| 429 | local _idx_0 = 1 | ||
| 430 | for _key_0, _value_0 in pairs(tb) do | ||
| 431 | if _idx_0 == _key_0 then | ||
| 432 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 433 | _idx_0 = _idx_0 + 1 | ||
| 434 | else | ||
| 435 | _tab_0[_key_0] = _value_0 | ||
| 436 | end | ||
| 437 | end | ||
| 438 | return _tab_0 | ||
| 439 | end | ||
| 440 | end | ||
| 441 | do | ||
| 442 | print((function() | ||
| 443 | local _item_0 = globalTB | ||
| 444 | return _item_0[#_item_0] | ||
| 445 | end)(), (function() | ||
| 446 | local _item_0 = a.b.c | ||
| 447 | return _item_0[#_item_0 - 2] | ||
| 448 | end)(), (function() | ||
| 449 | if x ~= nil then | ||
| 450 | local _obj_0 = x.y | ||
| 451 | if _obj_0 ~= nil then | ||
| 452 | local _obj_1 = _obj_0(x).z | ||
| 453 | if _obj_1 ~= nil then | ||
| 454 | return _obj_1[#_obj_1 - 3] | ||
| 455 | end | ||
| 456 | return nil | ||
| 457 | end | ||
| 458 | return nil | ||
| 459 | end | ||
| 460 | return nil | ||
| 461 | end)()) | ||
| 462 | end | ||
| 463 | local _anon_func_0 = function(globalTB) | ||
| 464 | local _item_0 = globalTB | ||
| 465 | local _call_0 = _item_0[#_item_0] | ||
| 466 | return _call_0["end"](_call_0, 123) | ||
| 467 | end | ||
| 468 | local _anon_func_1 = function(a) | ||
| 469 | local _item_0 | ||
| 470 | do | ||
| 471 | local _accum_0 = { } | ||
| 472 | local _len_0 = 1 | ||
| 473 | local _list_0 = a.b.c | ||
| 474 | local _max_3 = -5 | ||
| 475 | for _index_0 = 5, _max_3 < 0 and #_list_0 + _max_3 + 1 or _max_3 do | ||
| 476 | local _item_1 = _list_0[_index_0] | ||
| 477 | _accum_0[_len_0] = _item_1 | ||
| 478 | _len_0 = _len_0 + 1 | ||
| 479 | end | ||
| 480 | _item_0 = _accum_0 | ||
| 481 | end | ||
| 482 | return _item_0[#_item_0 - 2] | ||
| 483 | end | ||
| 484 | local _anon_func_2 = function(x) | ||
| 485 | if x ~= nil then | ||
| 486 | local _obj_0 = x.y | ||
| 487 | if _obj_0 ~= nil then | ||
| 488 | local _obj_1 = _obj_0(x).z | ||
| 489 | if _obj_1 ~= nil then | ||
| 490 | local _obj_2 = _obj_1[#_obj_1 - 3] | ||
| 491 | if _obj_2 ~= nil then | ||
| 492 | local _accum_0 = { } | ||
| 493 | local _len_0 = 1 | ||
| 494 | local _max_3 = -3 | ||
| 495 | for _index_0 = 1, _max_3 < 0 and #_obj_2 + _max_3 + 1 or _max_3 do | ||
| 496 | local _item_0 = _obj_2[_index_0] | ||
| 497 | _accum_0[_len_0] = _item_0 | ||
| 498 | _len_0 = _len_0 + 1 | ||
| 499 | end | ||
| 500 | return _accum_0 | ||
| 501 | end | ||
| 502 | return nil | ||
| 503 | end | ||
| 504 | return nil | ||
| 505 | end | ||
| 506 | return nil | ||
| 507 | end | ||
| 508 | return nil | ||
| 509 | end | ||
| 510 | do | ||
| 511 | local f | ||
| 512 | f = function() | ||
| 513 | return print(_anon_func_0(globalTB), _anon_func_1(a), _anon_func_2(x)) | ||
| 514 | end | ||
| 515 | end | ||
| 330 | return nil | 516 | return nil |
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index 204b816..7a11bac 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua | |||
| @@ -727,4 +727,54 @@ do | |||
| 727 | print("not matched") | 727 | print("not matched") |
| 728 | end | 728 | end |
| 729 | end | 729 | end |
| 730 | do | ||
| 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 = -3 | ||
| 744 | for _index_0 = 1, _max_0 < 0 and #clientData + _max_0 + 1 or _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 | ||
| 759 | end | ||
| 760 | do | ||
| 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 | }) | ||
| 779 | end | ||
| 730 | return nil | 780 | return nil |
diff --git a/spec/outputs/unicode/comprehension.lua b/spec/outputs/unicode/comprehension.lua index 60e490f..894e78f 100644 --- a/spec/outputs/unicode/comprehension.lua +++ b/spec/outputs/unicode/comprehension.lua | |||
| @@ -244,7 +244,7 @@ do | |||
| 244 | local _accum_0 = { } | 244 | local _accum_0 = { } |
| 245 | local _len_0 = 1 | 245 | local _len_0 = 1 |
| 246 | local _max_0 = 3 + 4 | 246 | local _max_0 = 3 + 4 |
| 247 | for _index_0 = 1 + 2, _max_0 < 0 and #_u5217_u8868 + _max_0 or _max_0 do | 247 | for _index_0 = 1 + 2, _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0 do |
| 248 | local _u9879_u76ee = _u5217_u8868[_index_0] | 248 | local _u9879_u76ee = _u5217_u8868[_index_0] |
| 249 | _accum_0[_len_0] = _u9879_u76ee | 249 | _accum_0[_len_0] = _u9879_u76ee |
| 250 | _len_0 = _len_0 + 1 | 250 | _len_0 = _len_0 + 1 |
| @@ -255,7 +255,7 @@ do | |||
| 255 | local _accum_0 = { } | 255 | local _accum_0 = { } |
| 256 | local _len_0 = 1 | 256 | local _len_0 = 1 |
| 257 | local _max_0 = 2 - _u4e1c_u897f[4] | 257 | 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 | 258 | for _index_0 = _u4f60_u597d() * 4, _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0 do |
| 259 | local _u9879_u76ee = _u5217_u8868[_index_0] | 259 | local _u9879_u76ee = _u5217_u8868[_index_0] |
| 260 | _accum_0[_len_0] = _u9879_u76ee | 260 | _accum_0[_len_0] = _u9879_u76ee |
| 261 | _len_0 = _len_0 + 1 | 261 | _len_0 = _len_0 + 1 |
diff --git a/spec/outputs/unicode/lists.lua b/spec/outputs/unicode/lists.lua index aafd516..a3c329b 100644 --- a/spec/outputs/unicode/lists.lua +++ b/spec/outputs/unicode/lists.lua | |||
| @@ -230,12 +230,12 @@ _u53d8_u91cfx = { | |||
| 230 | 7 | 230 | 7 |
| 231 | } | 231 | } |
| 232 | local _max_0 = -5 | 232 | local _max_0 = -5 |
| 233 | for _index_0 = 2, _max_0 < 0 and #_u53d8_u91cfx + _max_0 or _max_0, 2 do | 233 | for _index_0 = 2, _max_0 < 0 and #_u53d8_u91cfx + _max_0 + 1 or _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) |
| 236 | end | 236 | end |
| 237 | local _max_1 = 3 | 237 | local _max_1 = 3 |
| 238 | for _index_0 = 1, _max_1 < 0 and #_u53d8_u91cfx + _max_1 or _max_1 do | 238 | for _index_0 = 1, _max_1 < 0 and #_u53d8_u91cfx + _max_1 + 1 or _max_1 do |
| 239 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 239 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
| 240 | _u6253_u5370(_u53d8_u91cfy) | 240 | _u6253_u5370(_u53d8_u91cfy) |
| 241 | end | 241 | end |
| @@ -253,7 +253,7 @@ for _index_0 = 2, #_u53d8_u91cfx, 2 do | |||
| 253 | end | 253 | end |
| 254 | local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2 | 254 | local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2 |
| 255 | local _max_2 = _u53d8_u91cfb | 255 | local _max_2 = _u53d8_u91cfb |
| 256 | for _index_0 = _u53d8_u91cfa, _max_2 < 0 and #_u53d8_u91cfx + _max_2 or _max_2, _u53d8_u91cfc do | 256 | for _index_0 = _u53d8_u91cfa, _max_2 < 0 and #_u53d8_u91cfx + _max_2 + 1 or _max_2, _u53d8_u91cfc do |
| 257 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 257 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
| 258 | _u6253_u5370(_u53d8_u91cfy) | 258 | _u6253_u5370(_u53d8_u91cfy) |
| 259 | end | 259 | end |
