diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua | 761 |
1 files changed, 761 insertions, 0 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua new file mode 100644 index 0000000..b563ed3 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua | |||
@@ -0,0 +1,761 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_parser-5.0.lua | ||
4 | Lua 5.0.x parser test cases | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net> | ||
8 | The COPYRIGHT file describes the conditions | ||
9 | under which this software may be distributed. | ||
10 | |||
11 | See the ChangeLog for more information. | ||
12 | |||
13 | ----------------------------------------------------------------------]] | ||
14 | |||
15 | --[[-------------------------------------------------------------------- | ||
16 | -- Notes: | ||
17 | -- * there is no intention of properly specifying a grammar; the notes | ||
18 | -- are meant to reflect the structure of lparser so that it is easy | ||
19 | -- to locate and modify lparser if so desired | ||
20 | -- * some test may have invalid expressions but will compile, this | ||
21 | -- is because the chunk hasn't been executed yet | ||
22 | ----------------------------------------------------------------------]] | ||
23 | |||
24 | --[[-------------------------------------------------------------------- | ||
25 | -- lparser parsing structure, the Lua 5.0.x version... | ||
26 | ----------------------------------------------------------------------]] | ||
27 | -------------------------------------------------------------------- | ||
28 | -- chunk -> { stat [';'] } | ||
29 | -------------------------------------------------------------------- | ||
30 | -- stat -> DO block END | ||
31 | -- block -> chunk | ||
32 | -------------------------------------------------------------------- | ||
33 | -- stat -> breakstat | ||
34 | -- breakstat -> BREAK | ||
35 | -- * must have a loop to break | ||
36 | -- * must be last statement in a block | ||
37 | -------------------------------------------------------------------- | ||
38 | -- stat -> retstat | ||
39 | -- retstat -> RETURN explist | ||
40 | -- * must be last statement in a block | ||
41 | -------------------------------------------------------------------- | ||
42 | -- stat -> exprstat | ||
43 | -- exprstat -> primaryexp | ||
44 | -- (-> func | assignment) | ||
45 | -- * if LHS is VCALL then func, otherwise assignment | ||
46 | -- * for func, LHS is VCALL if funcargs in expression | ||
47 | -------------------------------------------------------------------- | ||
48 | -- stat -> funcstat | ||
49 | -- funcstat -> FUNCTION funcname body | ||
50 | -- funcname -> NAME {'.' NAME} [':' NAME] | ||
51 | -------------------------------------------------------------------- | ||
52 | -- body -> '(' parlist ')' chunk END | ||
53 | -- parlist -> [ param { ',' param } ] | ||
54 | -- param -> NAME | ||
55 | -- * DOTS must be the last parameter in a parlist | ||
56 | -------------------------------------------------------------------- | ||
57 | -- stat -> LOCAL localstat | ||
58 | -- LOCAL localstat -> LOCAL NAME {',' NAME} ['=' explist1] | ||
59 | -- explist1 -> expr { ',' expr } | ||
60 | -------------------------------------------------------------------- | ||
61 | -- stat -> LOCAL FUNCTION localfunc | ||
62 | -- LOCAL FUNCTION localfunc -> LOCAL FUNCTION NAME body | ||
63 | -------------------------------------------------------------------- | ||
64 | -- stat -> ifstat | ||
65 | -- ifstat -> IF cond THEN block | ||
66 | -- {ELSEIF cond THEN block} | ||
67 | -- [ELSE block] END | ||
68 | -- block -> chunk | ||
69 | -- cond -> expr | ||
70 | -------------------------------------------------------------------- | ||
71 | -- stat -> forstat | ||
72 | -- forstat -> fornum | forlist | ||
73 | -- forlist -> NAME {,NAME} IN explist1 forbody END | ||
74 | -- fornum -> NAME = exp1,exp1[,exp1] forbody END | ||
75 | -- forbody -> DO block | ||
76 | -- block -> chunk | ||
77 | -------------------------------------------------------------------- | ||
78 | -- stat -> whilestat | ||
79 | -- whilestat -> WHILE cond DO block END | ||
80 | -- block -> chunk | ||
81 | -- cond -> expr | ||
82 | -------------------------------------------------------------------- | ||
83 | -- stat -> repeatstat | ||
84 | -- repeatstat -> REPEAT block UNTIL cond | ||
85 | -- block -> chunk | ||
86 | -- cond -> expr | ||
87 | -------------------------------------------------------------------- | ||
88 | -- assignment -> ',' primaryexp assignment | ||
89 | -- | '=' explist1 | ||
90 | -- explist1 -> expr { ',' expr } | ||
91 | -- * for assignment, LHS must be LOCAL, UPVAL, GLOBAL or INDEXED | ||
92 | -------------------------------------------------------------------- | ||
93 | -- primaryexp -> prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } | ||
94 | -- prefixexp -> NAME | '(' expr ')' | ||
95 | -- funcargs -> '(' [ explist1 ] ')' | constructor | STRING | ||
96 | -- * funcargs turn an expr into a function call | ||
97 | -------------------------------------------------------------------- | ||
98 | -- expr -> subexpr | ||
99 | -- subexpr -> (UNOPR subexpr | simpleexp) { BINOPR subexpr } | ||
100 | -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ||
101 | -- | constructor | FUNCTION body | primaryexp | ||
102 | -------------------------------------------------------------------- | ||
103 | -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}' | ||
104 | -- fieldsep -> ',' | ';' | ||
105 | -- field -> recfield | listfield | ||
106 | -- recfield -> ( NAME | '[' exp1 ']' ) = exp1 | ||
107 | -- listfield -> expr | ||
108 | -------------------------------------------------------------------- | ||
109 | |||
110 | --[[-------------------------------------------------------------------- | ||
111 | -- parser test cases, Lua 5.0.x | ||
112 | -- * uncomment string delimiter to enable syntax highlighting... | ||
113 | -- * anything that matches "^%s*%-%-" is a comment | ||
114 | -- * headings to display are "^%s*TESTS:%s*(.*)$" | ||
115 | -- * FAIL test cases should match "%s*%-%-%s*FAIL%s*$" | ||
116 | ----------------------------------------------------------------------]] | ||
117 | tests_source = [[ | ||
118 | -------------------------------------------------------------------- | ||
119 | TESTS: empty chunks | ||
120 | -------------------------------------------------------------------- | ||
121 | -- chunk -> { stat [';'] } | ||
122 | -------------------------------------------------------------------- | ||
123 | |||
124 | ; -- FAIL | ||
125 | -------------------------------------------------------------------- | ||
126 | TESTS: optional semicolon, simple local statements | ||
127 | -------------------------------------------------------------------- | ||
128 | -- stat -> LOCAL localstat | ||
129 | -- LOCAL localstat -> LOCAL NAME {',' NAME} ['=' explist1] | ||
130 | -- explist1 -> expr { ',' expr } | ||
131 | -------------------------------------------------------------------- | ||
132 | local -- FAIL | ||
133 | local; -- FAIL | ||
134 | local = -- FAIL | ||
135 | local end -- FAIL | ||
136 | local a | ||
137 | local a; | ||
138 | local a, b, c | ||
139 | local a; local b local c; | ||
140 | local a = 1 | ||
141 | local a local b = a | ||
142 | local a, b = 1, 2 | ||
143 | local a, b, c = 1, 2, 3 | ||
144 | local a, b, c = 1 | ||
145 | local a = 1, 2, 3 | ||
146 | local a, local -- FAIL | ||
147 | local 1 -- FAIL | ||
148 | local "foo" -- FAIL | ||
149 | local a = local -- FAIL | ||
150 | local a, b, = -- FAIL | ||
151 | local a, b = 1, local -- FAIL | ||
152 | local a, b = , local -- FAIL | ||
153 | -------------------------------------------------------------------- | ||
154 | TESTS: simple DO blocks | ||
155 | -------------------------------------------------------------------- | ||
156 | -- stat -> DO block END | ||
157 | -- block -> chunk | ||
158 | -------------------------------------------------------------------- | ||
159 | do -- FAIL | ||
160 | end -- FAIL | ||
161 | do end | ||
162 | do ; end -- FAIL | ||
163 | do 1 end -- FAIL | ||
164 | do "foo" end -- FAIL | ||
165 | do local a, b end | ||
166 | do local a local b end | ||
167 | do local a; local b; end | ||
168 | do local a = 1 end | ||
169 | do do end end | ||
170 | do do end; end | ||
171 | do do do end end end | ||
172 | do do do end; end; end | ||
173 | do do do return end end end | ||
174 | do end do -- FAIL | ||
175 | do end end -- FAIL | ||
176 | do return end | ||
177 | do return return end -- FAIL | ||
178 | do break end -- FAIL | ||
179 | -------------------------------------------------------------------- | ||
180 | TESTS: simple WHILE loops | ||
181 | -------------------------------------------------------------------- | ||
182 | -- stat -> whilestat | ||
183 | -- whilestat -> WHILE cond DO block END | ||
184 | -- block -> chunk | ||
185 | -- cond -> expr | ||
186 | -------------------------------------------------------------------- | ||
187 | while -- FAIL | ||
188 | while do -- FAIL | ||
189 | while = -- FAIL | ||
190 | while 1 do -- FAIL | ||
191 | while 1 do end | ||
192 | while 1 do local a end | ||
193 | while 1 do local a local b end | ||
194 | while 1 do local a; local b; end | ||
195 | while 1 do 2 end -- FAIL | ||
196 | while 1 do "foo" end -- FAIL | ||
197 | while true do end | ||
198 | while 1 do ; end -- FAIL | ||
199 | while 1 do while -- FAIL | ||
200 | while 1 end -- FAIL | ||
201 | while 1 2 do -- FAIL | ||
202 | while 1 = 2 do -- FAIL | ||
203 | while 1 do return end | ||
204 | while 1 do return return end -- FAIL | ||
205 | while 1 do do end end | ||
206 | while 1 do do return end end | ||
207 | while 1 do break end | ||
208 | while 1 do break break end -- FAIL | ||
209 | while 1 do do break end end | ||
210 | -------------------------------------------------------------------- | ||
211 | TESTS: simple REPEAT loops | ||
212 | -------------------------------------------------------------------- | ||
213 | -- stat -> repeatstat | ||
214 | -- repeatstat -> REPEAT block UNTIL cond | ||
215 | -- block -> chunk | ||
216 | -- cond -> expr | ||
217 | -------------------------------------------------------------------- | ||
218 | repeat -- FAIL | ||
219 | repeat until -- FAIL | ||
220 | repeat until 0 | ||
221 | repeat until false | ||
222 | repeat until local -- FAIL | ||
223 | repeat end -- FAIL | ||
224 | repeat 1 -- FAIL | ||
225 | repeat = -- FAIL | ||
226 | repeat local a until 1 | ||
227 | repeat local a local b until 0 | ||
228 | repeat local a; local b; until 0 | ||
229 | repeat ; until 1 -- FAIL | ||
230 | repeat 2 until 1 -- FAIL | ||
231 | repeat "foo" until 1 -- FAIL | ||
232 | repeat return until 0 | ||
233 | repeat return return until 0 -- FAIL | ||
234 | repeat break until 0 | ||
235 | repeat break break until 0 -- FAIL | ||
236 | repeat do end until 0 | ||
237 | repeat do return end until 0 | ||
238 | repeat do break end until 0 | ||
239 | -------------------------------------------------------------------- | ||
240 | TESTS: simple FOR loops | ||
241 | -------------------------------------------------------------------- | ||
242 | -- stat -> forstat | ||
243 | -- forstat -> fornum | forlist | ||
244 | -- forlist -> NAME {,NAME} IN explist1 forbody END | ||
245 | -- fornum -> NAME = exp1,exp1[,exp1] forbody END | ||
246 | -- forbody -> DO block | ||
247 | -- block -> chunk | ||
248 | -------------------------------------------------------------------- | ||
249 | for -- FAIL | ||
250 | for do -- FAIL | ||
251 | for end -- FAIL | ||
252 | for 1 -- FAIL | ||
253 | for a -- FAIL | ||
254 | for true -- FAIL | ||
255 | for a, in -- FAIL | ||
256 | for a in -- FAIL | ||
257 | for a do -- FAIL | ||
258 | for a in do -- FAIL | ||
259 | for a in b do -- FAIL | ||
260 | for a in b end -- FAIL | ||
261 | for a in b, do -- FAIL | ||
262 | for a in b do end | ||
263 | for a in b do local a local b end | ||
264 | for a in b do local a; local b; end | ||
265 | for a in b do 1 end -- FAIL | ||
266 | for a in b do "foo" end -- FAIL | ||
267 | for a b in -- FAIL | ||
268 | for a, b, c in p do end | ||
269 | for a, b, c in p, q, r do end | ||
270 | for a in 1 do end | ||
271 | for a in true do end | ||
272 | for a in "foo" do end | ||
273 | for a in b do break end | ||
274 | for a in b do break break end -- FAIL | ||
275 | for a in b do return end | ||
276 | for a in b do return return end -- FAIL | ||
277 | for a in b do do end end | ||
278 | for a in b do do break end end | ||
279 | for a in b do do return end end | ||
280 | for = -- FAIL | ||
281 | for a = -- FAIL | ||
282 | for a, b = -- FAIL | ||
283 | for a = do -- FAIL | ||
284 | for a = 1, do -- FAIL | ||
285 | for a = p, q, do -- FAIL | ||
286 | for a = p q do -- FAIL | ||
287 | for a = b do end -- FAIL | ||
288 | for a = 1, 2, 3, 4 do end -- FAIL | ||
289 | for a = p, q do end | ||
290 | for a = 1, 2 do end | ||
291 | for a = 1, 2 do local a local b end | ||
292 | for a = 1, 2 do local a; local b; end | ||
293 | for a = 1, 2 do 3 end -- FAIL | ||
294 | for a = 1, 2 do "foo" end -- FAIL | ||
295 | for a = p, q, r do end | ||
296 | for a = 1, 2, 3 do end | ||
297 | for a = p, q do break end | ||
298 | for a = p, q do break break end -- FAIL | ||
299 | for a = 1, 2 do return end | ||
300 | for a = 1, 2 do return return end -- FAIL | ||
301 | for a = p, q do do end end | ||
302 | for a = p, q do do break end end | ||
303 | for a = p, q do do return end end | ||
304 | -------------------------------------------------------------------- | ||
305 | TESTS: break statement | ||
306 | -------------------------------------------------------------------- | ||
307 | -- stat -> breakstat | ||
308 | -- breakstat -> BREAK | ||
309 | -- * must have a loop to break | ||
310 | -- * must be last statement in a block | ||
311 | -------------------------------------------------------------------- | ||
312 | break -- FAIL | ||
313 | -------------------------------------------------------------------- | ||
314 | TESTS: return statement | ||
315 | -------------------------------------------------------------------- | ||
316 | -- stat -> retstat | ||
317 | -- retstat -> RETURN explist | ||
318 | -- * must be last statement in a block | ||
319 | -------------------------------------------------------------------- | ||
320 | return | ||
321 | return; | ||
322 | return return -- FAIL | ||
323 | return 1 | ||
324 | return local -- FAIL | ||
325 | return "foo" | ||
326 | return 1, -- FAIL | ||
327 | return 1,2,3 | ||
328 | return a,b,c,d | ||
329 | return 1,2; | ||
330 | -------------------------------------------------------------------- | ||
331 | TESTS: conditional statements | ||
332 | -------------------------------------------------------------------- | ||
333 | -- stat -> ifstat | ||
334 | -- ifstat -> IF cond THEN block | ||
335 | -- {ELSEIF cond THEN block} | ||
336 | -- [ELSE block] END | ||
337 | -- block -> chunk | ||
338 | -- cond -> expr | ||
339 | -------------------------------------------------------------------- | ||
340 | if -- FAIL | ||
341 | elseif -- FAIL | ||
342 | else -- FAIL | ||
343 | then -- FAIL | ||
344 | if then -- FAIL | ||
345 | if 1 -- FAIL | ||
346 | if 1 then -- FAIL | ||
347 | if 1 else -- FAIL | ||
348 | if 1 then else -- FAIL | ||
349 | if 1 then elseif -- FAIL | ||
350 | if 1 then end | ||
351 | if 1 then local a end | ||
352 | if 1 then local a local b end | ||
353 | if 1 then local a; local b; end | ||
354 | if 1 then else end | ||
355 | if 1 then local a else local b end | ||
356 | if 1 then local a; else local b; end | ||
357 | if 1 then elseif 2 -- FAIL | ||
358 | if 1 then elseif 2 then -- FAIL | ||
359 | if 1 then elseif 2 then end | ||
360 | if 1 then local a elseif 2 then local b end | ||
361 | if 1 then local a; elseif 2 then local b; end | ||
362 | if 1 then elseif 2 then else end | ||
363 | if 1 then else if 2 then end end | ||
364 | if 1 then else if 2 then end -- FAIL | ||
365 | if 1 then break end -- FAIL | ||
366 | if 1 then return end | ||
367 | if 1 then return return end -- FAIL | ||
368 | if 1 then end; if 1 then end; | ||
369 | -------------------------------------------------------------------- | ||
370 | TESTS: function statements | ||
371 | -------------------------------------------------------------------- | ||
372 | -- stat -> funcstat | ||
373 | -- funcstat -> FUNCTION funcname body | ||
374 | -- funcname -> NAME {'.' NAME} [':' NAME] | ||
375 | -------------------------------------------------------------------- | ||
376 | -- body -> '(' parlist ')' chunk END | ||
377 | -- parlist -> [ param { ',' param } ] | ||
378 | -- param -> NAME | ||
379 | -- * DOTS must be the last parameter in a parlist | ||
380 | -------------------------------------------------------------------- | ||
381 | function -- FAIL | ||
382 | function 1 -- FAIL | ||
383 | function end -- FAIL | ||
384 | function a -- FAIL | ||
385 | function a end -- FAIL | ||
386 | function a( end -- FAIL | ||
387 | function a() end | ||
388 | function a(1 -- FAIL | ||
389 | function a("foo" -- FAIL | ||
390 | function a(p -- FAIL | ||
391 | function a(p,) -- FAIL | ||
392 | function a(p q -- FAIL | ||
393 | function a(p) end | ||
394 | function a(p,q,) end -- FAIL | ||
395 | function a(p,q,r) end | ||
396 | function a(p,q,1 -- FAIL | ||
397 | function a(p) do -- FAIL | ||
398 | function a(p) 1 end -- FAIL | ||
399 | function a(p) return end | ||
400 | function a(p) break end -- FAIL | ||
401 | function a(p) return return end -- FAIL | ||
402 | function a(p) do end end | ||
403 | function a.( -- FAIL | ||
404 | function a.1 -- FAIL | ||
405 | function a.b() end | ||
406 | function a.b, -- FAIL | ||
407 | function a.b.( -- FAIL | ||
408 | function a.b.c.d() end | ||
409 | function a: -- FAIL | ||
410 | function a:1 -- FAIL | ||
411 | function a:b() end | ||
412 | function a:b: -- FAIL | ||
413 | function a:b. -- FAIL | ||
414 | function a.b.c:d() end | ||
415 | function a(...) end | ||
416 | function a(..., -- FAIL | ||
417 | function a(p,...) end | ||
418 | function a(p,q,r,...) end | ||
419 | function a() local a local b end | ||
420 | function a() local a; local b; end | ||
421 | function a() end; function a() end; | ||
422 | -------------------------------------------------------------------- | ||
423 | TESTS: local function statements | ||
424 | -------------------------------------------------------------------- | ||
425 | -- stat -> LOCAL FUNCTION localfunc | ||
426 | -- LOCAL FUNCTION localfunc -> LOCAL FUNCTION NAME body | ||
427 | -------------------------------------------------------------------- | ||
428 | local function -- FAIL | ||
429 | local function 1 -- FAIL | ||
430 | local function end -- FAIL | ||
431 | local function a -- FAIL | ||
432 | local function a end -- FAIL | ||
433 | local function a( end -- FAIL | ||
434 | local function a() end | ||
435 | local function a(1 -- FAIL | ||
436 | local function a("foo" -- FAIL | ||
437 | local function a(p -- FAIL | ||
438 | local function a(p,) -- FAIL | ||
439 | local function a(p q -- FAIL | ||
440 | local function a(p) end | ||
441 | local function a(p,q,) end -- FAIL | ||
442 | local function a(p,q,r) end | ||
443 | local function a(p,q,1 -- FAIL | ||
444 | local function a(p) do -- FAIL | ||
445 | local function a(p) 1 end -- FAIL | ||
446 | local function a(p) return end | ||
447 | local function a(p) break end -- FAIL | ||
448 | local function a(p) return return end -- FAIL | ||
449 | local function a(p) do end end | ||
450 | local function a. -- FAIL | ||
451 | local function a: -- FAIL | ||
452 | local function a(...) end | ||
453 | local function a(..., -- FAIL | ||
454 | local function a(p,...) end | ||
455 | local function a(p,q,r,...) end | ||
456 | local function a() local a local b end | ||
457 | local function a() local a; local b; end | ||
458 | local function a() end; local function a() end; | ||
459 | -------------------------------------------------------------------- | ||
460 | -- stat -> exprstat | ||
461 | -- exprstat -> primaryexp | ||
462 | -- (-> func | assignment) | ||
463 | -- * if LHS is VCALL then func, otherwise assignment | ||
464 | -- * for func, LHS is VCALL if funcargs in expression | ||
465 | -------------------------------------------------------------------- | ||
466 | TESTS: assignments | ||
467 | -------------------------------------------------------------------- | ||
468 | -- assignment -> ',' primaryexp assignment | ||
469 | -- | '=' explist1 | ||
470 | -- explist1 -> expr { ',' expr } | ||
471 | -- * for assignment, LHS must be LOCAL, UPVAL, GLOBAL or INDEXED | ||
472 | -------------------------------------------------------------------- | ||
473 | a -- FAIL | ||
474 | a, -- FAIL | ||
475 | a,b,c -- FAIL | ||
476 | a,b = -- FAIL | ||
477 | a = 1 | ||
478 | a = 1,2,3 | ||
479 | a,b,c = 1 | ||
480 | a,b,c = 1,2,3 | ||
481 | a.b = 1 | ||
482 | a.b.c = 1 | ||
483 | a[b] = 1 | ||
484 | a[b][c] = 1 | ||
485 | a.b[c] = 1 | ||
486 | a[b].c = 1 | ||
487 | 0 = -- FAIL | ||
488 | "foo" = -- FAIL | ||
489 | true = -- FAIL | ||
490 | (a) = -- FAIL | ||
491 | {} = -- FAIL | ||
492 | a:b() = -- FAIL | ||
493 | a() = -- FAIL | ||
494 | a.b:c() = -- FAIL | ||
495 | a[b]() = -- FAIL | ||
496 | a = a b -- FAIL | ||
497 | a = 1 2 -- FAIL | ||
498 | a = a = 1 -- FAIL | ||
499 | -------------------------------------------------------------------- | ||
500 | TESTS: function calls | ||
501 | -------------------------------------------------------------------- | ||
502 | -- primaryexp -> prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } | ||
503 | -- prefixexp -> NAME | '(' expr ')' | ||
504 | -- funcargs -> '(' [ explist1 ] ')' | constructor | STRING | ||
505 | -- * funcargs turn an expr into a function call | ||
506 | -------------------------------------------------------------------- | ||
507 | a( -- FAIL | ||
508 | a() | ||
509 | a(1) | ||
510 | a(1,) -- FAIL | ||
511 | a(1,2,3) | ||
512 | 1() -- FAIL | ||
513 | a()() | ||
514 | a.b() | ||
515 | a[b]() | ||
516 | a.1 -- FAIL | ||
517 | a.b -- FAIL | ||
518 | a[b] -- FAIL | ||
519 | a.b.( -- FAIL | ||
520 | a.b.c() | ||
521 | a[b][c]() | ||
522 | a[b].c() | ||
523 | a.b[c]() | ||
524 | a:b() | ||
525 | a:b -- FAIL | ||
526 | a:1 -- FAIL | ||
527 | a.b:c() | ||
528 | a[b]:c() | ||
529 | a:b: -- FAIL | ||
530 | a:b():c() | ||
531 | a:b().c[d]:e() | ||
532 | a:b()[c].d:e() | ||
533 | (a)() | ||
534 | ()() -- FAIL | ||
535 | (1)() | ||
536 | ("foo")() | ||
537 | (true)() | ||
538 | (a)()() | ||
539 | (a.b)() | ||
540 | (a[b])() | ||
541 | (a).b() | ||
542 | (a)[b]() | ||
543 | (a):b() | ||
544 | (a).b[c]:d() | ||
545 | (a)[b].c:d() | ||
546 | (a):b():c() | ||
547 | (a):b().c[d]:e() | ||
548 | (a):b()[c].d:e() | ||
549 | -------------------------------------------------------------------- | ||
550 | TESTS: more function calls | ||
551 | -------------------------------------------------------------------- | ||
552 | a"foo" | ||
553 | a[[foo]] | ||
554 | a.b"foo" | ||
555 | a[b]"foo" | ||
556 | a:b"foo" | ||
557 | a{} | ||
558 | a.b{} | ||
559 | a[b]{} | ||
560 | a:b{} | ||
561 | a()"foo" | ||
562 | a"foo"() | ||
563 | a"foo".b() | ||
564 | a"foo"[b]() | ||
565 | a"foo":c() | ||
566 | a"foo""bar" | ||
567 | a"foo"{} | ||
568 | (a):b"foo".c[d]:e"bar" | ||
569 | (a):b"foo"[c].d:e"bar" | ||
570 | a(){} | ||
571 | a{}() | ||
572 | a{}.b() | ||
573 | a{}[b]() | ||
574 | a{}:c() | ||
575 | a{}"foo" | ||
576 | a{}{} | ||
577 | (a):b{}.c[d]:e{} | ||
578 | (a):b{}[c].d:e{} | ||
579 | -------------------------------------------------------------------- | ||
580 | TESTS: simple expressions | ||
581 | -------------------------------------------------------------------- | ||
582 | -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ||
583 | -- | constructor | FUNCTION body | primaryexp | ||
584 | -------------------------------------------------------------------- | ||
585 | a = -- FAIL | ||
586 | a = a | ||
587 | a = nil | ||
588 | a = false | ||
589 | a = 1 | ||
590 | a = "foo" | ||
591 | a = [[foo]] | ||
592 | a = {} | ||
593 | a = (a) | ||
594 | a = (nil) | ||
595 | a = (true) | ||
596 | a = (1) | ||
597 | a = ("foo") | ||
598 | a = ([[foo]]) | ||
599 | a = ({}) | ||
600 | a = a.b | ||
601 | a = a.b. -- FAIL | ||
602 | a = a.b.c | ||
603 | a = a:b -- FAIL | ||
604 | a = a[b] | ||
605 | a = a[1] | ||
606 | a = a["foo"] | ||
607 | a = a[b][c] | ||
608 | a = a.b[c] | ||
609 | a = a[b].c | ||
610 | a = (a)[b] | ||
611 | a = (a).c | ||
612 | a = () -- FAIL | ||
613 | a = a() | ||
614 | a = a.b() | ||
615 | a = a[b]() | ||
616 | a = a:b() | ||
617 | a = (a)() | ||
618 | a = (a).b() | ||
619 | a = (a)[b]() | ||
620 | a = (a):b() | ||
621 | a = a"foo" | ||
622 | a = a{} | ||
623 | a = function -- FAIL | ||
624 | a = function 1 -- FAIL | ||
625 | a = function a -- FAIL | ||
626 | a = function end -- FAIL | ||
627 | a = function( -- FAIL | ||
628 | a = function() end | ||
629 | a = function(1 -- FAIL | ||
630 | a = function(p) end | ||
631 | a = function(p,) -- FAIL | ||
632 | a = function(p q -- FAIL | ||
633 | a = function(p,q,r) end | ||
634 | a = function(p,q,1 -- FAIL | ||
635 | a = function(...) end | ||
636 | a = function(..., -- FAIL | ||
637 | a = function(p,...) end | ||
638 | a = function(p,q,r,...) end | ||
639 | -------------------------------------------------------------------- | ||
640 | TESTS: operators | ||
641 | -------------------------------------------------------------------- | ||
642 | -- expr -> subexpr | ||
643 | -- subexpr -> (UNOPR subexpr | simpleexp) { BINOPR subexpr } | ||
644 | -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ||
645 | -- | constructor | FUNCTION body | primaryexp | ||
646 | -------------------------------------------------------------------- | ||
647 | a = -10 | ||
648 | a = -"foo" | ||
649 | a = -a | ||
650 | a = -nil | ||
651 | a = -true | ||
652 | a = -{} | ||
653 | a = -function() end | ||
654 | a = -a() | ||
655 | a = -(a) | ||
656 | a = - -- FAIL | ||
657 | a = not 10 | ||
658 | a = not "foo" | ||
659 | a = not a | ||
660 | a = not nil | ||
661 | a = not true | ||
662 | a = not {} | ||
663 | a = not function() end | ||
664 | a = not a() | ||
665 | a = not (a) | ||
666 | a = not -- FAIL | ||
667 | a = 1 + 2; a = 1 - 2 | ||
668 | a = 1 * 2; a = 1 / 2 | ||
669 | a = 1 ^ 2; a = 1 .. 2 | ||
670 | a = 1 + -- FAIL | ||
671 | a = 1 .. -- FAIL | ||
672 | a = 1 * / -- FAIL | ||
673 | a = 1 + -2; a = 1 - -2 | ||
674 | a = 1 * - -- FAIL | ||
675 | a = 1 * not 2; a = 1 / not 2 | ||
676 | a = 1 / not -- FAIL | ||
677 | a = 1 + 2 - 3 * 4 / 5 ^ 6 | ||
678 | a = ((1 + 2) - 3) * (4 / (5 ^ 6)) | ||
679 | a = (1 + (2 - (3 * (4 / (5 ^ ((6))))))) | ||
680 | a = ((1 -- FAIL | ||
681 | a = ((1 + 2) -- FAIL | ||
682 | a = 1) -- FAIL | ||
683 | a = a + b - c | ||
684 | a = "foo" + "bar" | ||
685 | a = "foo".."bar".."baz" | ||
686 | a = true + false - nil | ||
687 | a = {} * {} | ||
688 | a = function() end / function() end | ||
689 | a = a() ^ b() | ||
690 | -------------------------------------------------------------------- | ||
691 | TESTS: more operators | ||
692 | -------------------------------------------------------------------- | ||
693 | a = 1 == 2; a = 1 ~= 2 | ||
694 | a = 1 < 2; a = 1 <= 2 | ||
695 | a = 1 > 2; a = 1 >= 2 | ||
696 | a = 1 < 2 < 3 | ||
697 | a = 1 >= 2 >= 3 | ||
698 | a = 1 == -- FAIL | ||
699 | a = ~= 2 -- FAIL | ||
700 | a = "foo" == "bar" | ||
701 | a = "foo" > "bar" | ||
702 | a = a ~= b | ||
703 | a = true == false | ||
704 | a = 1 and 2; a = 1 or 2 | ||
705 | a = 1 and -- FAIL | ||
706 | a = or 1 -- FAIL | ||
707 | a = 1 and 2 and 3 | ||
708 | a = 1 or 2 or 3 | ||
709 | a = 1 and 2 or 3 | ||
710 | a = a and b or c | ||
711 | a = a() and (b)() or c.d | ||
712 | a = "foo" and "bar" | ||
713 | a = true or false | ||
714 | a = {} and {} or {} | ||
715 | a = (1) and ("foo") or (nil) | ||
716 | a = function() end == function() end | ||
717 | a = function() end or function() end | ||
718 | -------------------------------------------------------------------- | ||
719 | TESTS: constructors | ||
720 | -------------------------------------------------------------------- | ||
721 | -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}' | ||
722 | -- fieldsep -> ',' | ';' | ||
723 | -- field -> recfield | listfield | ||
724 | -- recfield -> ( NAME | '[' exp1 ']' ) = exp1 | ||
725 | -- listfield -> expr | ||
726 | -------------------------------------------------------------------- | ||
727 | a = { -- FAIL | ||
728 | a = {} | ||
729 | a = {,} -- FAIL | ||
730 | a = {;} | ||
731 | a = {,,} -- FAIL | ||
732 | a = {;;} -- FAIL | ||
733 | a = {{ -- FAIL | ||
734 | a = {{{}}} | ||
735 | a = {{},{},{{}},} | ||
736 | a = { 1 } | ||
737 | a = { 1, } | ||
738 | a = { 1; } | ||
739 | a = { 1, 2 } | ||
740 | a = { a, b, c, } | ||
741 | a = { true; false, nil; } | ||
742 | a = { a.b, a[b]; a:c(), } | ||
743 | a = { 1 + 2, a > b, "a" or "b" } | ||
744 | a = { a=1, } | ||
745 | a = { a=1, b="foo", c=nil } | ||
746 | a = { a -- FAIL | ||
747 | a = { a= -- FAIL | ||
748 | a = { a=, -- FAIL | ||
749 | a = { a=; -- FAIL | ||
750 | a = { 1, a="foo" -- FAIL | ||
751 | a = { 1, a="foo"; b={}, d=true; } | ||
752 | a = { [ -- FAIL | ||
753 | a = { [1 -- FAIL | ||
754 | a = { [1] -- FAIL | ||
755 | a = { [a]= -- FAIL | ||
756 | a = { ["foo"]="bar" } | ||
757 | a = { [1]=a, [2]=b, } | ||
758 | a = { true, a=1; ["foo"]="bar", } | ||
759 | ]] | ||
760 | |||
761 | -- end of script | ||