diff options
author | Li Jin <dragon-fly@qq.com> | 2022-07-14 02:48:49 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-07-14 02:48:49 +0800 |
commit | 3159a45de9e691ad758dcbc933446f61b7ae1940 (patch) | |
tree | b695f8356986accc84c82ece09eb427a2b1db230 /spec | |
parent | a1d341085eed96d567329a30f2cf57c95fe6f071 (diff) | |
download | yuescript-3159a45de9e691ad758dcbc933446f61b7ae1940.tar.gz yuescript-3159a45de9e691ad758dcbc933446f61b7ae1940.tar.bz2 yuescript-3159a45de9e691ad758dcbc933446f61b7ae1940.zip |
fix table matching issue and update doc.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/switch.yue | 6 | ||||
-rw-r--r-- | spec/outputs/switch.lua | 28 |
2 files changed, 15 insertions, 19 deletions
diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue index 36f9be6..04bb02e 100644 --- a/spec/inputs/switch.yue +++ b/spec/inputs/switch.yue | |||
@@ -139,10 +139,10 @@ do | |||
139 | "#{a + b}" | 139 | "#{a + b}" |
140 | when 1, 2, 3, 4, 5 | 140 | when 1, 2, 3, 4, 5 |
141 | "number 1 - 5" | 141 | "number 1 - 5" |
142 | when {:alwaysMatch = "fallback"} | 142 | when {:matchAnyTable = "fallback"} |
143 | alwaysMatch | 143 | matchAnyTable |
144 | else | 144 | else |
145 | "should not reach here" | 145 | "should not reach here unless it is not a table" |
146 | 146 | ||
147 | nil | 147 | nil |
148 | 148 | ||
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index 03a0d37..7b413f8 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua | |||
@@ -182,8 +182,8 @@ do | |||
182 | local x = item.x | 182 | local x = item.x |
183 | local y = item.y | 183 | local y = item.y |
184 | if x ~= nil and y ~= nil then | 184 | if x ~= nil and y ~= nil then |
185 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
186 | _match_0 = true | 185 | _match_0 = true |
186 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
187 | end | 187 | end |
188 | end | 188 | end |
189 | if not _match_0 then | 189 | if not _match_0 then |
@@ -192,8 +192,8 @@ do | |||
192 | local width = item.width | 192 | local width = item.width |
193 | local height = item.height | 193 | local height = item.height |
194 | if width ~= nil and height ~= nil then | 194 | if width ~= nil and height ~= nil then |
195 | print("Size " .. tostring(width) .. ", " .. tostring(height)) | ||
196 | _match_1 = true | 195 | _match_1 = true |
196 | print("Size " .. tostring(width) .. ", " .. tostring(height)) | ||
197 | end | 197 | end |
198 | end | 198 | end |
199 | if not _match_1 then | 199 | if not _match_1 then |
@@ -204,12 +204,12 @@ do | |||
204 | if _tab_0 then | 204 | if _tab_0 then |
205 | local cls = item.__class | 205 | local cls = item.__class |
206 | if cls ~= nil then | 206 | if cls ~= nil then |
207 | _match_2 = true | ||
207 | if ClassA == cls then | 208 | if ClassA == cls then |
208 | print("Object A") | 209 | print("Object A") |
209 | elseif ClassB == cls then | 210 | elseif ClassB == cls then |
210 | print("Object B") | 211 | print("Object B") |
211 | end | 212 | end |
212 | _match_2 = true | ||
213 | end | 213 | end |
214 | end | 214 | end |
215 | if not _match_2 then | 215 | if not _match_2 then |
@@ -241,9 +241,7 @@ do | |||
241 | if b == nil then | 241 | if b == nil then |
242 | b = 2 | 242 | b = 2 |
243 | end | 243 | end |
244 | if a ~= nil and b ~= nil then | 244 | print(a, b) |
245 | print(a, b) | ||
246 | end | ||
247 | end | 245 | end |
248 | end | 246 | end |
249 | end | 247 | end |
@@ -258,8 +256,8 @@ do | |||
258 | local x = tb.x | 256 | local x = tb.x |
259 | local y = tb.y | 257 | local y = tb.y |
260 | if x ~= nil and y ~= nil then | 258 | if x ~= nil and y ~= nil then |
261 | print("x: " .. tostring(x) .. " with y: " .. tostring(y)) | ||
262 | _match_0 = true | 259 | _match_0 = true |
260 | print("x: " .. tostring(x) .. " with y: " .. tostring(y)) | ||
263 | end | 261 | end |
264 | end | 262 | end |
265 | if not _match_0 then | 263 | if not _match_0 then |
@@ -284,8 +282,8 @@ do | |||
284 | if _tab_0 then | 282 | if _tab_0 then |
285 | local x = _exp_0.x | 283 | local x = _exp_0.x |
286 | if x ~= nil then | 284 | if x ~= nil then |
287 | matched = x | ||
288 | _match_0 = true | 285 | _match_0 = true |
286 | matched = x | ||
289 | end | 287 | end |
290 | end | 288 | end |
291 | if not _match_0 then | 289 | if not _match_0 then |
@@ -310,8 +308,8 @@ do | |||
310 | local a = _exp_0.a | 308 | local a = _exp_0.a |
311 | local b = _exp_0.b | 309 | local b = _exp_0.b |
312 | if a ~= nil and b ~= nil then | 310 | if a ~= nil and b ~= nil then |
313 | return tostring(a + b) | ||
314 | _match_0 = true | 311 | _match_0 = true |
312 | return tostring(a + b) | ||
315 | end | 313 | end |
316 | end | 314 | end |
317 | if not _match_0 then | 315 | if not _match_0 then |
@@ -319,15 +317,13 @@ do | |||
319 | return "number 1 - 5" | 317 | return "number 1 - 5" |
320 | else | 318 | else |
321 | if _tab_0 then | 319 | if _tab_0 then |
322 | local alwaysMatch = _exp_0.alwaysMatch | 320 | local matchAnyTable = _exp_0.matchAnyTable |
323 | if alwaysMatch == nil then | 321 | if matchAnyTable == nil then |
324 | alwaysMatch = "fallback" | 322 | matchAnyTable = "fallback" |
325 | end | ||
326 | if alwaysMatch ~= nil then | ||
327 | return alwaysMatch | ||
328 | end | 323 | end |
324 | return matchAnyTable | ||
329 | else | 325 | else |
330 | return "should not reach here" | 326 | return "should not reach here unless it is not a table" |
331 | end | 327 | end |
332 | end | 328 | end |
333 | end | 329 | end |