Skip to content

Commit 43dde2f

Browse files
committed
Updated syntax.
* Added error check for mixed use of tabs and spaces. * Supported SimpleTable destructuring for ForEach syntax.
1 parent b462de9 commit 43dde2f

13 files changed

Lines changed: 89 additions & 40 deletions

File tree

spec/inputs/destructure.yue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,15 @@ do
278278
do
279279
{a, :abc, b, :def, ...sub, d, e} = tb
280280

281+
do
282+
for {:a, :b} in *items
283+
print a, b
284+
285+
for :a, :b in *items
286+
print a, b
287+
288+
for :body in pairs data
289+
print body if body
290+
281291
nil
282292

spec/inputs/funcs.yue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ f(
9898

9999
x = (a,
100100
b) ->
101-
print "what"
101+
print "what"
102102

103103

104104
y = (a="hi",
@@ -211,7 +211,7 @@ do
211211
print "kv:", k, v
212212
print "rest count:", select "#", ...
213213
macro gen = (fname) -> |
214-
#{fname} = ({:a, :b = 0}) -> print a, b
214+
#{fname} = ({:a, :b = 0}) -> print a, b
215215
$gen foo
216216
t1 = (:a, x) -> print a, x
217217
t2 = (:a) -> print a

spec/inputs/string.yue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ do
100100
next: 123
101101
str = |
102102
list:
103-
- "one"
104-
- "two"
103+
- "one"
104+
- "two"
105105
str = |
106106
-- comment
107107
content text

spec/inputs/unicode/funcs.yue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ _无效变量 = -> 真名 if 某物
9898

9999
变量x = (参数a,
100100
参数b) ->
101-
打印 "什么"
101+
打印 "什么"
102102

103103

104104
变量y = (参数a="hi",

spec/inputs/unicode/vararg.yue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
_ = ->
5656
列表 = {1, 2, 3, 4, 5}
5757
函数名 = (确定) ->
58-
确定, table.unpack 列表
58+
确定, table.unpack 列表
5959
确定, ... = 函数名 true
6060
打印 确定, ...
6161

6262
多参数函数 = ->
63-
10, nil, 20, nil, 30
63+
10, nil, 20, nil, 30
6464

6565
... = 多参数函数!
6666
打印 select "#", ...

spec/inputs/vararg.yue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ join = (...) ->
5555
_ = ->
5656
list = {1, 2, 3, 4, 5}
5757
fn = (ok) ->
58-
ok, table.unpack list
58+
ok, table.unpack list
5959
ok, ... = fn true
6060
print ok, ...
6161

6262
fn_many_args = ->
63-
10, nil, 20, nil, 30
63+
10, nil, 20, nil, 30
6464

6565
... = fn_many_args!
6666
print select "#", ...

spec/inputs/with.yue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ do
167167

168168
do
169169
a = for i = 1, 100
170-
with? x := tb[i]
171-
break x if .id := 1
170+
with? x := tb[i]
171+
break x if .id := 1
172172

173173
nil

spec/outputs/destructure.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,24 @@ do
711711
return _accum_0
712712
end)(), _obj_0[#_obj_0 - 1], _obj_0[#_obj_0]
713713
end
714+
do
715+
local _list_0 = items
716+
for _index_0 = 1, #_list_0 do
717+
local _des_0 = _list_0[_index_0]
718+
local a, b = _des_0.a, _des_0.b
719+
print(a, b)
720+
end
721+
local _list_1 = items
722+
for _index_0 = 1, #_list_1 do
723+
local _des_0 = _list_1[_index_0]
724+
local a, b = _des_0.a, _des_0.b
725+
print(a, b)
726+
end
727+
for _des_0 in pairs(data) do
728+
local body = _des_0.body
729+
if body then
730+
print(body)
731+
end
732+
end
733+
end
714734
return nil

spec/outputs/string.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ do
5252
str = "user: " .. tostring(name) .. "\nid: " .. tostring(id)
5353
str = "path: \"C:\\\\Program Files\\\\App\"\ndesc: 'single \"quote\" test'"
5454
str = "key: value \nnext: 123 "
55-
str = "list:\n - \"one\"\n - \"two\""
55+
str = "list:\n\t- \"one\"\n\t- \"two\""
5656
str = "-- comment\ncontent text\n-- comment"
5757
str = tostring(1 + 2) .. '\n' .. tostring(2 + 3) .. '\n' .. tostring("a" .. "b")
5858
local obj = {

src/yuescript/yue_ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ AST_NODE(Macro)
848848
AST_END(Macro)
849849

850850
AST_NODE(NameOrDestructure)
851-
ast_sel<true, Variable_t, TableLit_t, Comprehension_t> item;
851+
ast_sel<true, Variable_t, SimpleTable_t, TableLit_t, Comprehension_t> item;
852852
AST_MEMBER(NameOrDestructure, &item)
853853
AST_END(NameOrDestructure)
854854

0 commit comments

Comments
 (0)