From 2a3e50752ade96c3b5d6b1103937bef0f6b31157 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 7 Jun 2023 09:42:50 +0800 Subject: add new syntax of in-expression. --- spec/inputs/in_expression.yue | 26 ++++++++++++++++++++++++++ spec/outputs/in_expression.lua | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 spec/inputs/in_expression.yue create mode 100644 spec/outputs/in_expression.lua (limited to 'spec') diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue new file mode 100644 index 0000000..2756fe8 --- /dev/null +++ b/spec/inputs/in_expression.yue @@ -0,0 +1,26 @@ +-a^2 in {1, 2, 3} |> f + +a, b = x(...) not in [1, 3], 2 + +d = (tb.x.y ...) not in [1, 3] + +if a in {1} and b in {2, 3, 4} or c in [1, 10] + 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) + +nil + diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua new file mode 100644 index 0000000..061431f --- /dev/null +++ b/spec/outputs/in_expression.lua @@ -0,0 +1,36 @@ +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 +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 +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 +return nil -- cgit v1.2.3-55-g6feb