From 652a8839f885b73fff57942a9db8b26e9cb5233b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sun, 22 Oct 2023 00:55:02 +0800 Subject: fixing issues from #152. --- spec/inputs/cond.yue | 11 +++++ spec/inputs/in_expression.yue | 25 +++------- spec/inputs/lists.yue | 24 ++++++++-- spec/inputs/tables.yue | 20 ++++++++ spec/inputs/unicode/cond.yue | 11 +++++ spec/inputs/unicode/in_expression.yue | 21 +-------- spec/outputs/cond.lua | 17 +++++++ spec/outputs/in_expression.lua | 31 ++----------- spec/outputs/lists.lua | 65 +++++++++++++++++++++++++- spec/outputs/tables.lua | 83 ++++++++++++++++++++++++++++++++++ spec/outputs/unicode/cond.lua | 17 +++++++ spec/outputs/unicode/in_expression.lua | 31 ++----------- 12 files changed, 257 insertions(+), 99 deletions(-) (limited to 'spec') diff --git a/spec/inputs/cond.yue b/spec/inputs/cond.yue index 638b5c3..df7d78e 100644 --- a/spec/inputs/cond.yue +++ b/spec/inputs/cond.yue @@ -226,6 +226,17 @@ do else 2 +do + condChain = 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 + + v = (x)-> + print x + x + + evaluation = v(1) < v(2) <= v(3) + + evaluation = v(1) > v(2) <= v(3) + nil diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue index 6e923e1..6faff4e 100644 --- a/spec/inputs/in_expression.yue +++ b/spec/inputs/in_expression.yue @@ -1,28 +1,13 @@ -a^2 in {1, 2, 3} |> f - -a, b = x(...) not in [1, 3], 2 - -d = (tb.x.y ...) not in [1, 3] +-a^2 in [1, 2, 3] |> f has = "foo" in { "bar", "foo" } -if a in {1} and b in {2, 3, 4} or c in [1, 10] +if a in {1} and b in {2, 3, 4} print a, b, c -switch val - when 1, 2, 3 - print "1, 2, 3" - - when not in (0, 100] - print "not (0 < val <= 100)" - - when in [200, 300) - print "200 <= val < 300)" - - when not in {333, 444, 555} - print "not 333, 444 or 555" - -do return y not in (a, b) +if a in [1,] and b in [2, 3, 4] + print a, b, c do exist = item in list @@ -36,9 +21,11 @@ do do item = get! list = {1, 2, 3} + list = [1, 2, 3] not_exist = item not in list check item in list check item in {1, 2, 3} + check item in [1, 2, 3] check item(...) in {[1]: 1, [2]: 2, [3]: 3} do diff --git a/spec/inputs/lists.yue b/spec/inputs/lists.yue index 15eb9ab..921cae0 100644 --- a/spec/inputs/lists.yue +++ b/spec/inputs/lists.yue @@ -67,6 +67,24 @@ normal = (hello) -> test = x 1,2,3,4,5 print thing for thing in *test --> a = b for row in *rows - - +_ = -> a = b for row in *rows + +with tb + f [a] -- indexing + f [a,] -- list with one element + print v for v in *f[a,] -- table slicing in for-loop + f [] -- empty list + f[] = x -- table appending to f + [a] = x -- assign to tb[a] + [a,] = x -- list destructuring for x + [] = x -- table appending to tb + c = a in [1] -- check if a in tb[1] + c = a in [1,] -- check if a == 1 + c = a in {1} -- check if a == 1 + c = a in {1,} -- check if a == 1 + +do + [a, b] = hello + [name = "nameless", job = "jobless"] = person + +nil diff --git a/spec/inputs/tables.yue b/spec/inputs/tables.yue index 0b5af46..53a53ae 100644 --- a/spec/inputs/tables.yue +++ b/spec/inputs/tables.yue @@ -40,6 +40,8 @@ ya = { 1,2,3, key: 100, 343, "hello", umm: 232 } x = { 1,2, 4343, 343 ,343 } +x = [ 1,2, + 4343, 343 ,343 ] g, p = { 1,2, nowy: "yes", 3,4, @@ -52,6 +54,12 @@ annother = { 6,7,8 } +annother = [ + 1,2,3 + 3,4,5 + 6,7,8 +] + yeah = { [232]: 3434, "helo" ice: "cake" @@ -255,6 +263,11 @@ tbMixA = { 11 } +tbMixA = [ + ...[i for i = 1, 10] + 11 +] + tbMixB = { ... ... -- only the first item in vararg been accessed here ... {...} @@ -262,6 +275,13 @@ tbMixB = { 1, 2, 3 } +tbMixB = [ + ... ... -- only the first item in vararg been accessed here + ... {...} + ... {......} + 1, 2, 3 +] + const template = { foo: "Hello" bar: "World" diff --git a/spec/inputs/unicode/cond.yue b/spec/inputs/unicode/cond.yue index 362408c..fca6d60 100644 --- a/spec/inputs/unicode/cond.yue +++ b/spec/inputs/unicode/cond.yue @@ -226,6 +226,17 @@ do else 2 +do + 链式比较 = 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5 + + 值 = (输入)-> + 打印 输入 + 输入 + + 求值 = 值(1) < 值(2) <= 值(3) + + 求值 = 值(1) > 值(2) <= 值(3) + nil diff --git a/spec/inputs/unicode/in_expression.yue b/spec/inputs/unicode/in_expression.yue index efaca47..e068cbf 100644 --- a/spec/inputs/unicode/in_expression.yue +++ b/spec/inputs/unicode/in_expression.yue @@ -1,29 +1,10 @@ -变量a^2 in {1, 2, 3} |> 函数 -变量a, 变量b = 函数x(...) not in [1, 3], 2 - -变量d = (对象.字段x.字段y ...) not in [1, 3] - 在的 = "东" in { "东", "西" } -if 变量a in {1} and 变量b in {2, 3, 4} or 变量c in [1, 10] +if 变量a in {1} and 变量b in {2, 3, 4} 打印 变量a, 变量b, 变量c -switch 值 - when 1, 2, 3 - 打印 "1, 2, 3" - - when not in (0, 100] - 打印 "非 (0 < 值 <= 100)" - - when in [200, 300) - 打印 "200 <= 值 < 300)" - - when not in {333, 444, 555} - 打印 "非 333, 444 或 555" - -do return 变量y not in (开始, 结束) - do 存在 = 元素 in 表 检查 元素 in 表 diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua index 1f6aa63..651c14a 100644 --- a/spec/outputs/cond.lua +++ b/spec/outputs/cond.lua @@ -345,4 +345,21 @@ do v = 2 end end +do + local condChain = 1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5 + local v + v = function(x) + print(x) + return x + end + local evaluation + do + local _cond_0 = v(2) + evaluation = v(1) < _cond_0 and _cond_0 <= v(3) + end + do + local _cond_0 = v(2) + evaluation = v(1) > _cond_0 and _cond_0 <= v(3) + end +end return nil diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua index ddba69a..60802c9 100644 --- a/spec/outputs/in_expression.lua +++ b/spec/outputs/in_expression.lua @@ -2,42 +2,17 @@ f((function() local _val_0 = -a ^ 2 return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 end)()) -local a, b = (function(...) - local _val_0 = x(...) - return not (1 <= _val_0 and _val_0 <= 3) -end)(...), 2 -local d -do - local _val_0 = (tb.x.y(...)) - d = not (1 <= _val_0 and _val_0 <= 3) -end local has do local _val_0 = "foo" has = "bar" == _val_0 or "foo" == _val_0 end -if (1 == a) and (2 == b or 3 == b or 4 == b) or (function() - local _val_0 = c - return 1 <= _val_0 and _val_0 <= 10 +if (1 == a) and (function() + local _val_0 = b + return 2 == _val_0 or 3 == _val_0 or 4 == _val_0 end)() then print(a, b, c) end -do - local _exp_0 = val - if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 then - print("1, 2, 3") - elseif not (0 < _exp_0 and _exp_0 <= 100) then - print("not (0 < val <= 100)") - elseif (200 <= _exp_0 and _exp_0 < 300) then - print("200 <= val < 300)") - elseif not (333 == _exp_0 or 444 == _exp_0 or 555 == _exp_0) then - print("not 333, 444 or 555") - end -end -do - local _val_0 = y - return not (a < _val_0 and _val_0 < b) -end do local exist do diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua index 581cc23..e6f306d 100644 --- a/spec/outputs/lists.lua +++ b/spec/outputs/lists.lua @@ -273,10 +273,73 @@ for _index_0 = 1, #test do local thing = test[_index_0] print(thing) end -return function() +_ = function() local _list_0 = rows for _index_0 = 1, #_list_0 do local row = _list_0[_index_0] a = b end end +do + local _with_0 = tb + f(_with_0[a]) + f({ + a + }) + local _list_0 = f + for _index_0 = a, #_list_0 do + local v = _list_0[_index_0] + print(v) + end + f({ }) + do + local _obj_0 = f + _obj_0[#_obj_0 + 1] = x + end + _with_0[a] = x + a = x[1] + _with_0[#_with_0 + 1] = x + do + local _check_0 = _with_0[1] + local _find_0 = false + for _index_0 = 1, #_check_0 do + local _item_0 = _check_0[_index_0] + if _item_0 == a then + _find_0 = true + break + end + end + c = _find_0 + end + c = (1 == a) + c = (1 == a) + do + local _check_0 = { + 1 + } + local _find_0 = false + for _index_0 = 1, #_check_0 do + local _item_0 = _check_0[_index_0] + if _item_0 == a then + _find_0 = true + break + end + end + c = _find_0 + end +end +do + a, b = hello[1], hello[2] + local name, job + do + local _obj_0 = person + name, job = _obj_0[1], _obj_0[2] + if name == nil then + name = "nameless" + end + if job == nil then + job = "jobless" + end + end +end +return nil diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua index e9df1c4..f836d58 100644 --- a/spec/outputs/tables.lua +++ b/spec/outputs/tables.lua @@ -52,6 +52,13 @@ local x = { 343, 343 } +x = { + 1, + 2, + 4343, + 343, + 343 +} local g, p = { 1, 2, @@ -72,6 +79,17 @@ local annother = { 7, 8 } +annother = { + 1, + 2, + 3, + 3, + 4, + 5, + 6, + 7, + 8 +} local yeah = { [232] = 3434, "helo", @@ -435,6 +453,27 @@ do _tab_0[#_tab_0 + 1] = 11 tbMixA = _tab_0 end +do + local _tab_0 = { } + local _obj_0 + do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + _obj_0 = _accum_0 + end + local _idx_0 = #_tab_0 + 1 + for _index_0 = 1, #_obj_0 do + local _value_0 = _obj_0[_index_0] + _tab_0[_idx_0] = _value_0 + _idx_0 = _idx_0 + 1 + end + _tab_0[#_tab_0 + 1] = 11 + tbMixA = _tab_0 +end local tbMixB do local _tab_0 = { } @@ -489,6 +528,50 @@ do _tab_0[#_tab_0 + 1] = 3 tbMixB = _tab_0 end +do + local _tab_0 = { } + local _obj_0 = ... + local _idx_0 = #_tab_0 + 1 + for _index_0 = 1, #_obj_0 do + local _value_0 = _obj_0[_index_0] + _tab_0[_idx_0] = _value_0 + _idx_0 = _idx_0 + 1 + end + local _obj_1 = { + ... + } + local _idx_1 = #_tab_0 + 1 + for _index_0 = 1, #_obj_1 do + local _value_0 = _obj_1[_index_0] + _tab_0[_idx_1] = _value_0 + _idx_1 = _idx_1 + 1 + end + local _obj_2 + do + local _tab_1 = { } + local _obj_3 = ... + local _idx_2 = 1 + for _key_0, _value_0 in pairs(_obj_3) do + if _idx_2 == _key_0 then + _tab_1[#_tab_1 + 1] = _value_0 + _idx_2 = _idx_2 + 1 + else + _tab_1[_key_0] = _value_0 + end + end + _obj_2 = _tab_1 + end + local _idx_2 = #_tab_0 + 1 + for _index_0 = 1, #_obj_2 do + local _value_0 = _obj_2[_index_0] + _tab_0[_idx_2] = _value_0 + _idx_2 = _idx_2 + 1 + end + _tab_0[#_tab_0 + 1] = 1 + _tab_0[#_tab_0 + 1] = 2 + _tab_0[#_tab_0 + 1] = 3 + tbMixB = _tab_0 +end local template = { foo = "Hello", bar = "World", diff --git a/spec/outputs/unicode/cond.lua b/spec/outputs/unicode/cond.lua index f972dea..9a4ccb9 100644 --- a/spec/outputs/unicode/cond.lua +++ b/spec/outputs/unicode/cond.lua @@ -351,4 +351,21 @@ do _u53d8_u91cfv = 2 end end +do + local _u94fe_u5f0f_u6bd4_u8f83 = 1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5 + local _u503c + _u503c = function(_u8f93_u5165) + _u6253_u5370(_u8f93_u5165) + return _u8f93_u5165 + end + local _u6c42_u503c + do + local _cond_0 = _u503c(2) + _u6c42_u503c = _u503c(1) < _cond_0 and _cond_0 <= _u503c(3) + end + do + local _cond_0 = _u503c(2) + _u6c42_u503c = _u503c(1) > _cond_0 and _cond_0 <= _u503c(3) + end +end return nil diff --git a/spec/outputs/unicode/in_expression.lua b/spec/outputs/unicode/in_expression.lua index 62aad05..7c584f3 100644 --- a/spec/outputs/unicode/in_expression.lua +++ b/spec/outputs/unicode/in_expression.lua @@ -2,42 +2,17 @@ _u51fd_u6570((function() local _val_0 = -_u53d8_u91cfa ^ 2 return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 end)()) -local _u53d8_u91cfa, _u53d8_u91cfb = (function(...) - local _val_0 = _u51fd_u6570x(...) - return not (1 <= _val_0 and _val_0 <= 3) -end)(...), 2 -local _u53d8_u91cfd -do - local _val_0 = (_u5bf9_u8c61["字段x"]["字段y"](...)) - _u53d8_u91cfd = not (1 <= _val_0 and _val_0 <= 3) -end local _u5728_u7684 do local _val_0 = "东" _u5728_u7684 = "东" == _val_0 or "西" == _val_0 end -if (1 == _u53d8_u91cfa) and (2 == _u53d8_u91cfb or 3 == _u53d8_u91cfb or 4 == _u53d8_u91cfb) or (function() - local _val_0 = _u53d8_u91cfc - return 1 <= _val_0 and _val_0 <= 10 +if (1 == _u53d8_u91cfa) and (function() + local _val_0 = _u53d8_u91cfb + return 2 == _val_0 or 3 == _val_0 or 4 == _val_0 end)() then _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc) end -do - local _exp_0 = _u503c - if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 then - _u6253_u5370("1, 2, 3") - elseif not (0 < _exp_0 and _exp_0 <= 100) then - _u6253_u5370("非 (0 < 值 <= 100)") - elseif (200 <= _exp_0 and _exp_0 < 300) then - _u6253_u5370("200 <= 值 < 300)") - elseif not (333 == _exp_0 or 444 == _exp_0 or 555 == _exp_0) then - _u6253_u5370("非 333, 444 或 555") - end -end -do - local _val_0 = _u53d8_u91cfy - return not (_u5f00_u59cb < _val_0 and _val_0 < _u7ed3_u675f) -end do local _u5b58_u5728 do -- cgit v1.2.3-55-g6feb