diff options
author | Li Jin <dragon-fly@qq.com> | 2022-02-11 10:37:35 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-02-11 10:37:35 +0800 |
commit | 09fc831f540ce3966aeff679164f37e7d40457c9 (patch) | |
tree | ea56f0fa897af3089e1289bdfa7676a62198dc13 /spec | |
parent | a66ec0d18eba6b38fad25cc88c82f7532d689670 (diff) | |
download | yuescript-09fc831f540ce3966aeff679164f37e7d40457c9.tar.gz yuescript-09fc831f540ce3966aeff679164f37e7d40457c9.tar.bz2 yuescript-09fc831f540ce3966aeff679164f37e7d40457c9.zip |
add Lua table appending idiom: tb #= 123
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/syntax.yue | 13 | ||||
-rw-r--r-- | spec/outputs/syntax.lua | 18 |
2 files changed, 30 insertions, 1 deletions
diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue index cb947e1..67d3a27 100644 --- a/spec/inputs/syntax.yue +++ b/spec/inputs/syntax.yue | |||
@@ -184,10 +184,21 @@ a["hello#{tostring ff}"] += 10 | |||
184 | a[four].x += 10 | 184 | a[four].x += 10 |
185 | 185 | ||
186 | a.b += 1 | 186 | a.b += 1 |
187 | a.b[1].c[2+3] += 1 | 187 | a.b[1].c[2 + 3] += 1 |
188 | with tb | 188 | with tb |
189 | .a.c += 1 | 189 | .a.c += 1 |
190 | 190 | ||
191 | tb #= 10 | ||
192 | a.b.c #= 1 | ||
193 | x #= if v | ||
194 | 1 | ||
195 | else | ||
196 | 2 | ||
197 | with tb | ||
198 | .b.c #= with vec | ||
199 | .x = 1 | ||
200 | .y = 2 | ||
201 | |||
191 | x = 0 | 202 | x = 0 |
192 | _ = (if ntype(v) == "fndef" then x += 1) for v in *values | 203 | _ = (if ntype(v) == "fndef" then x += 1) for v in *values |
193 | 204 | ||
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua index ed8ed39..4596a29 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua | |||
@@ -195,6 +195,24 @@ do | |||
195 | local _obj_2 = _with_0.a | 195 | local _obj_2 = _with_0.a |
196 | _obj_2.c = _obj_2.c + 1 | 196 | _obj_2.c = _obj_2.c + 1 |
197 | end | 197 | end |
198 | tb[#tb + 1] = 10 | ||
199 | local _obj_2 = a.b.c | ||
200 | _obj_2[#_obj_2 + 1] = 1 | ||
201 | if v then | ||
202 | x[#x + 1] = 1 | ||
203 | else | ||
204 | x[#x + 1] = 2 | ||
205 | end | ||
206 | do | ||
207 | local _with_0 = tb | ||
208 | local _obj_3 = _with_0.b.c | ||
209 | do | ||
210 | local _with_1 = vec | ||
211 | _with_1.x = 1 | ||
212 | _with_1.y = 2 | ||
213 | _obj_3[#_obj_3 + 1] = _with_1 | ||
214 | end | ||
215 | end | ||
198 | x = 0 | 216 | x = 0 |
199 | local _list_0 = values | 217 | local _list_0 = values |
200 | for _index_0 = 1, #_list_0 do | 218 | for _index_0 = 1, #_list_0 do |