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