|
1 "{ Package: 'stx:goodies/petitparser/islands/tests' }" |
|
2 |
|
3 TestCase subclass:#FirstFollowNextTests |
|
4 instanceVariableNames:'' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'PetitIslands-Tests' |
|
8 ! |
|
9 |
|
10 FirstFollowNextTests comment:'' |
|
11 ! |
|
12 |
|
13 !FirstFollowNextTests methodsFor:'support'! |
|
14 |
|
15 assert: set allMatches: string |
|
16 self assert: (set allSatisfy: [:e | e end matches: string]) |
|
17 ! |
|
18 |
|
19 assert: set allSatisfy: aBlock |
|
20 self assert: (set allSatisfy: aBlock) |
|
21 ! |
|
22 |
|
23 assert: set anyMatches: string |
|
24 self assert: (set anySatisfy: [:e | e end matches: string]) |
|
25 ! |
|
26 |
|
27 assert: set anySatisfy: aBlock |
|
28 self assert: (set anySatisfy: aBlock) |
|
29 ! |
|
30 |
|
31 assert: set noneMatches: string |
|
32 self assert: (set noneSatisfy: [:e | e end matches: string]) |
|
33 ! |
|
34 |
|
35 assert: set noneSatisfy: aBlock |
|
36 self assert: (set noneSatisfy: aBlock) |
|
37 ! |
|
38 |
|
39 assert: set size: anInteger |
|
40 self assert: (set size = anInteger ) |
|
41 ! |
|
42 |
|
43 first: aParser |
|
44 ^ aParser firstSet |
|
45 ! |
|
46 |
|
47 first: aParser terminalPredicate: predicate |
|
48 ^ aParser firstSetPredicate: predicate |
|
49 ! |
|
50 |
|
51 follow: aParser in: rootParser |
|
52 ^ rootParser followSets at: aParser |
|
53 |
|
54 ! |
|
55 |
|
56 identifier |
|
57 ^ ((#letter asParser / $# asParser), (#letter asParser / #digit asParser) star) flatten |
|
58 ! |
|
59 |
|
60 next: aParser in: rootParser |
|
61 ^ rootParser nextSets at: aParser |
|
62 |
|
63 ! ! |
|
64 |
|
65 !FirstFollowNextTests methodsFor:'test first'! |
|
66 |
|
67 testFirst1 |
|
68 | p first | |
|
69 p := nil asParser / 'a' asParser. |
|
70 |
|
71 self assert: (self first: p) anyMatches: ''. |
|
72 self assert: (self first: p) anyMatches: 'a'. |
|
73 ! |
|
74 |
|
75 testFirst2 |
|
76 | p first | |
|
77 p := 'a' asParser optional, 'b' asParser. |
|
78 |
|
79 self assert: (self first: p) anyMatches: 'a'. |
|
80 self assert: (self first: p) anyMatches: 'b'. |
|
81 ! |
|
82 |
|
83 testFirst3 |
|
84 | p first | |
|
85 p := ('a' asParser optional, 'b' asParser asParser optional), 'c' asParser. |
|
86 |
|
87 self assert: (self first: p) anyMatches: 'a'. |
|
88 self assert: (self first: p) anyMatches: 'b'. |
|
89 ! |
|
90 |
|
91 testFirst4 |
|
92 | p first | |
|
93 p := ('a' asParser plus) optional, 'b' asParser. |
|
94 |
|
95 self assert: (self first: p) anyMatches: 'a'. |
|
96 self assert: (self first: p) anyMatches: 'b'. |
|
97 ! |
|
98 |
|
99 testFirstChoice1 |
|
100 | p first | |
|
101 p := nil asParser / '' asParser. |
|
102 |
|
103 self assert: (self first: p) anySatisfy: [:e | e matches: '']. |
|
104 ! |
|
105 |
|
106 testFirstChoice2 |
|
107 | p first | |
|
108 p := 'a' asParser / nil asParser. |
|
109 |
|
110 first := (self first: p). |
|
111 |
|
112 self assert: first anySatisfy: [:e | e matches: 'a']. |
|
113 self assert: first anySatisfy: [:e | e matches: '']. |
|
114 ! |
|
115 |
|
116 testFirstChoice3 |
|
117 | p first | |
|
118 p := 'a' asParser / nil asParser / 'b' asParser. |
|
119 |
|
120 first := (self first: p). |
|
121 |
|
122 self assert: first anySatisfy: [:e | e matches: 'a']. |
|
123 self assert: first anySatisfy: [:e | e matches: 'b']. |
|
124 self assert: first anySatisfy: [:e | e matches: '']. |
|
125 ! |
|
126 |
|
127 testFirstComplex1 |
|
128 | p first root | |
|
129 |
|
130 p := 'a' asParser / nil asParser. |
|
131 root := p, 'c' asParser. |
|
132 |
|
133 first := (self first: root). |
|
134 |
|
135 self assert: first size: 2. |
|
136 self assert: first anySatisfy: [:e | e matches: 'a']. |
|
137 self assert: first anySatisfy: [:e | e matches: 'c']. |
|
138 self assert: first noneSatisfy: [:e | e matches: '']. |
|
139 ! |
|
140 |
|
141 testFirstComplex2 |
|
142 | p first root | |
|
143 |
|
144 p := 'a' asParser / nil asParser / 'b' asParser. |
|
145 root := p, 'c' asParser. |
|
146 |
|
147 first := (self first: root). |
|
148 |
|
149 self assert: first size: 3. |
|
150 self assert: first anySatisfy: [:e | e matches: 'a']. |
|
151 self assert: first anySatisfy: [:e | e matches: 'b']. |
|
152 self assert: first anySatisfy: [:e | e matches: 'c']. |
|
153 ! |
|
154 |
|
155 testFirstComplex3 |
|
156 | p first root | |
|
157 |
|
158 p := 'a' asParser / nil asParser / 'b' asParser. |
|
159 root := p, 'c' asParser not. |
|
160 |
|
161 first := (self first: root). |
|
162 |
|
163 self assert: first anySatisfy: [:e | e matches: 'a']. |
|
164 self assert: first anySatisfy: [:e | e matches: 'b']. |
|
165 self assert: first anySatisfy: [:e | e matches: '']. |
|
166 self assert: first noneSatisfy: [:e | e end matches: 'c']. |
|
167 ! |
|
168 |
|
169 testFirstComplex4 |
|
170 | p first root | |
|
171 |
|
172 p := 'a' asParser / nil asParser / 'b' asParser. |
|
173 root := (p, 'c' asParser not) wrapped. |
|
174 |
|
175 first := (self first: root). |
|
176 |
|
177 self assert: first anySatisfy: [:e | e matches: 'a']. |
|
178 self assert: first anySatisfy: [:e | e matches: 'b']. |
|
179 self assert: first anySatisfy: [:e | e matches: '']. |
|
180 self assert: first noneSatisfy: [:e | e end matches: 'c']. |
|
181 ! |
|
182 |
|
183 testFirstNegate1 |
|
184 | p first | |
|
185 p := 'a' asParser negate, 'b' asParser. |
|
186 |
|
187 self assert: (p parse: 'bb') isPetitFailure not. |
|
188 self assert: (p parse: 'cb') isPetitFailure not. |
|
189 |
|
190 self assert: (self first: p) noneSatisfy: [:each | each matches: 'a' ]. |
|
191 self assert: (self first: p) anySatisfy: [:each | each matches: 'b' ]. |
|
192 self assert: (self first: p) anySatisfy: [:each | each matches: 'c' ]. |
|
193 ! |
|
194 |
|
195 testFirstNot |
|
196 | p | |
|
197 p := 'a' asParser not, 'b' asParser. |
|
198 |
|
199 self assert: (p parse: 'b') isPetitFailure not. |
|
200 |
|
201 self assert: (self first: p) noneSatisfy: [:each | each matches: 'a' ]. |
|
202 self assert: (self first: p) anySatisfy: [:each | each matches: 'b' ]. |
|
203 self assert: (self first: p) anySatisfy: [:each | each matches: 'c' ]. |
|
204 ! |
|
205 |
|
206 testFirstOptional |
|
207 | p first result | |
|
208 p := 'a' asParser optional. |
|
209 |
|
210 result := (self first: p). |
|
211 |
|
212 self assert: result anySatisfy: [:e | e matches: '' ]. |
|
213 self assert: result anySatisfy: [:e | e matches: 'a']. |
|
214 ! |
|
215 |
|
216 testFirstRepeat1 |
|
217 | p first | |
|
218 p := ('a' asParser / nil asParser) plus. |
|
219 |
|
220 first := self first: p. |
|
221 |
|
222 self assert: first anyMatches: 'a'. |
|
223 self assert: first anyMatches: ''. |
|
224 ! |
|
225 |
|
226 testFirstSequence1 |
|
227 | p first | |
|
228 p := 'a' asParser, 'b' asParser . |
|
229 |
|
230 first := self first: p. |
|
231 self assert: first size: 1. |
|
232 self assert: first allMatches: 'a'. |
|
233 self assert: first noneMatches: 'b'. |
|
234 ! |
|
235 |
|
236 testFirstSequence2 |
|
237 | p first | |
|
238 p := nil asParser, 'a' asParser, 'b' asParser . |
|
239 |
|
240 first := self first: p. |
|
241 self assert: first size: 1. |
|
242 self assert: first allMatches: 'a'. |
|
243 self assert: first noneMatches: 'b'. |
|
244 self assert: first noneMatches: ''. |
|
245 ! |
|
246 |
|
247 testFirstSequence3 |
|
248 | p first | |
|
249 p := nil asParser, nil asParser. |
|
250 |
|
251 self assert: (self first: p) anySatisfy: [:e | e end matches: '']. |
|
252 ! |
|
253 |
|
254 testFirstSequence4 |
|
255 | p first | |
|
256 p := ((nil asParser / 'a' asParser) plus), 'b' asParser. |
|
257 |
|
258 first := self first: p. |
|
259 self assert: first anyMatches: 'b'. |
|
260 self assert: first anyMatches: 'a'. |
|
261 self assert: first noneMatches: ''. |
|
262 ! |
|
263 |
|
264 testFirstSequence5 |
|
265 | p first | |
|
266 p := ((nil asParser / 'a' asParser) star), 'b' asParser. |
|
267 |
|
268 first := self first: p. |
|
269 self assert: first anyMatches: 'b'. |
|
270 self assert: first anyMatches: 'a'. |
|
271 self assert: first noneMatches: ''. |
|
272 ! |
|
273 |
|
274 testFirstTerminal2 |
|
275 | p | |
|
276 p := 'a' asParser not. |
|
277 |
|
278 self assert: (self first: p) noneMatches: 'a'. |
|
279 ! |
|
280 |
|
281 testFirstTerminal3 |
|
282 | p | |
|
283 p := 'a' asParser and. |
|
284 |
|
285 self assert: (self first: p) anyMatches: 'a' |
|
286 ! |
|
287 |
|
288 testFirstTerminal4 |
|
289 | p | |
|
290 p := nil asParser. |
|
291 |
|
292 self assert: (self first: p) anySatisfy: [:e | e end matches: '']. |
|
293 ! ! |
|
294 |
|
295 !FirstFollowNextTests methodsFor:'test follow'! |
|
296 |
|
297 testFollowNot1 |
|
298 | p followSet terminal | |
|
299 |
|
300 terminal := 'a' asParser. |
|
301 p := terminal, 'b' asParser not. |
|
302 followSet := self follow: terminal in: p. |
|
303 |
|
304 self assert: followSet anySatisfy: [:e | e matches: 'c' ]. |
|
305 self assert: followSet anySatisfy: [:e | (e matches: 'b') not ]. |
|
306 ! |
|
307 |
|
308 testFollowSet1 |
|
309 | result p root followSet | |
|
310 |
|
311 |
|
312 p := 'a' asParser. |
|
313 root := (p star, 'b' asParser). |
|
314 |
|
315 followSet := self follow: p in: root. |
|
316 |
|
317 self assert: followSet anySatisfy: [:e | e literal = 'a']. |
|
318 self assert: followSet anySatisfy: [:e | e literal = 'b']. |
|
319 ! |
|
320 |
|
321 testFollowSet10 |
|
322 | island1 followSet p root island2 block | |
|
323 |
|
324 island1 := ('class' asParser, self identifier) island. |
|
325 island2 := ('extends' asParser, self identifier) island. |
|
326 block := '{}' asParser island. |
|
327 |
|
328 root := (island1, island2 optional, block) star. |
|
329 |
|
330 followSet := self follow: block in: root. |
|
331 |
|
332 self assert: followSet anySatisfy: [:e | e end matches: 'class']. |
|
333 self assert: followSet anySatisfy: [:e | e end matches: '']. |
|
334 ! |
|
335 |
|
336 testFollowSet11 |
|
337 | island1 followSet p root island2 block | |
|
338 |
|
339 island1 := ('class' asParser, self identifier) island. |
|
340 island2 := ('extends' asParser, self identifier) island. |
|
341 block := '{}' asParser island. |
|
342 |
|
343 root := (island1, island2 optional, block) plus. |
|
344 |
|
345 followSet := self follow: block in: root. |
|
346 |
|
347 self assert: followSet anySatisfy: [:e | e end matches: 'class']. |
|
348 self assert: followSet anySatisfy: [:e | e end matches: '']. |
|
349 ! |
|
350 |
|
351 testFollowSet12 |
|
352 | parser followSet | |
|
353 |
|
354 |
|
355 |
|
356 parser := 'a' asParser. |
|
357 followSet := self follow: parser in: parser. |
|
358 |
|
359 self assert: followSet anySatisfy: [:e | e end matches: '' ]. |
|
360 ! |
|
361 |
|
362 testFollowSet13 |
|
363 | parser followSet a b c | |
|
364 |
|
365 a := 'a' asParser. |
|
366 b := 'b' asParser optional. |
|
367 c := 'c' asParser. |
|
368 |
|
369 |
|
370 parser := a, b, c. |
|
371 followSet := self follow: c in: parser. |
|
372 self assert: followSet anySatisfy: [:e | e end matches: '' ]. |
|
373 |
|
374 followSet := self follow: b in: parser. |
|
375 self assert: followSet anySatisfy: [:e | e end matches: 'c' ]. |
|
376 |
|
377 followSet := self follow: a in: parser. |
|
378 self assert: followSet anySatisfy: [:e | e end matches: 'b' ]. |
|
379 self assert: followSet anySatisfy: [:e | e end matches: 'c' ]. |
|
380 ! |
|
381 |
|
382 testFollowSet14 |
|
383 | parser followSet a b c | |
|
384 |
|
385 a := 'a' asParser. |
|
386 b := 'b' asParser optional. |
|
387 c := 'c' asParser. |
|
388 |
|
389 |
|
390 parser := a plus, b, c. |
|
391 |
|
392 followSet := self follow: a in: parser. |
|
393 self assert: followSet anySatisfy: [:e | e end matches: 'a' ]. |
|
394 self assert: followSet anySatisfy: [:e | e end matches: 'b' ]. |
|
395 self assert: followSet anySatisfy: [:e | e end matches: 'c' ]. |
|
396 self assert: followSet noneSatisfy: [:e | e end matches: '' ]. |
|
397 ! |
|
398 |
|
399 testFollowSet2 |
|
400 | result p follow root followSets followSet | |
|
401 |
|
402 p := 'a' asParser. |
|
403 follow := 'b' asParser, 'c' asParser. |
|
404 |
|
405 root := (p, follow). |
|
406 |
|
407 followSet := self follow: p in: root. |
|
408 |
|
409 self assert: followSet size: 1. |
|
410 self assert: followSet anySatisfy: [:e | e end matches: 'b']. |
|
411 self assert: followSet noneSatisfy: [:e | e matches: 'c']. |
|
412 ! |
|
413 |
|
414 testFollowSet3 |
|
415 | result p follow root followSets followSet | |
|
416 |
|
417 p := 'a' asParser. |
|
418 follow := ('b' asParser, 'c' asParser) / ('d' asParser). |
|
419 |
|
420 |
|
421 root := (p, follow). |
|
422 |
|
423 followSet := self follow: p in: root. |
|
424 |
|
425 self assert: followSet anySatisfy: [:e | e end matches: 'b' ]. |
|
426 self assert: followSet anySatisfy: [:e | e end matches: 'd' ]. |
|
427 ! |
|
428 |
|
429 testFollowSet4 |
|
430 | result p follow root followSets followSet | |
|
431 |
|
432 p := 'a' asParser. |
|
433 follow := ('b' asParser, 'c' asParser). |
|
434 |
|
435 |
|
436 root := (p star, follow). |
|
437 |
|
438 followSet := self follow: p in: root. |
|
439 |
|
440 self assert: followSet anySatisfy: [:e | e end matches: 'b' ]. |
|
441 self assert: followSet anySatisfy: [:e | e end matches: 'a' ]. |
|
442 ! |
|
443 |
|
444 testFollowSet5 |
|
445 | result p root followSets followSet follow1 follow2 | |
|
446 |
|
447 p := 'a' asParser. |
|
448 follow1 := ('b' asParser, 'c' asParser) / nil asParser. |
|
449 follow2 := 'd' asParser. |
|
450 |
|
451 |
|
452 root := (p, follow1, follow2). |
|
453 |
|
454 followSet := self follow: p in: root. |
|
455 |
|
456 self assert: followSet anySatisfy: [:e | e end matches: 'b' ]. |
|
457 self assert: followSet anySatisfy: [:e | e end matches: 'd' ]. |
|
458 ! |
|
459 |
|
460 testFollowSet6 |
|
461 | result p root followSets followSet follow follow1 follow2 | |
|
462 |
|
463 p := 'a' asParser. |
|
464 follow1 := ('b' asParser, 'c' asParser) / nil asParser. |
|
465 follow2 := 'd' asParser. |
|
466 |
|
467 follow := (follow1, follow2). |
|
468 |
|
469 root := (p, follow). |
|
470 |
|
471 followSet := self follow: p in: root. |
|
472 |
|
473 self assert: followSet anySatisfy: [:e | e end matches: 'b' ]. |
|
474 self assert: followSet anySatisfy: [:e | e end matches: 'd' ]. |
|
475 ! |
|
476 |
|
477 testFollowSet7 |
|
478 | result p root followSets followSet r1 r2 follow1 follow2 | |
|
479 |
|
480 p := 'a' asParser. |
|
481 follow1 := ('b' asParser, 'c' asParser) / nil asParser. |
|
482 follow2 := 'd' asParser / nil asParser . |
|
483 |
|
484 r1 := (p, follow1). |
|
485 r2 := (r1, follow2). |
|
486 |
|
487 root := r2. |
|
488 |
|
489 followSet := self follow: p in: root. |
|
490 |
|
491 self assert: followSet anySatisfy: [:e | e end matches: 'b' ]. |
|
492 self assert: followSet anySatisfy: [:e | e end matches: 'd' ]. |
|
493 ! |
|
494 |
|
495 testFollowSet8 |
|
496 | result p root followSets followSet follow | |
|
497 |
|
498 p := 'a' asParser. |
|
499 follow := PPInputEnds new. |
|
500 |
|
501 root := p, follow. |
|
502 |
|
503 followSet := self follow: p in: root. |
|
504 |
|
505 self assert: followSet anySatisfy: [:e | e end matches: '']. |
|
506 ! |
|
507 |
|
508 testFollowSet9 |
|
509 | island1 followSet p root island2 block | |
|
510 |
|
511 island1 := ('class' asParser, self identifier) island. |
|
512 island2 := (':' asParser, self identifier) island. |
|
513 block := '{' asParser, '}' asParser island. |
|
514 |
|
515 root := (island1, island2 optional, block) island. |
|
516 |
|
517 followSet := self follow: island1 in: root. |
|
518 |
|
519 self assert: followSet anySatisfy: [:e | e end matches: '{']. |
|
520 self assert: followSet anySatisfy: [:e | e end matches: ':']. |
|
521 ! |
|
522 |
|
523 testFollowSetChoice1 |
|
524 | result p root followSets followSet follow | |
|
525 |
|
526 p := 'a' asParser. |
|
527 follow := 'b' asParser / 'c' asParser . |
|
528 |
|
529 root := p, follow. |
|
530 |
|
531 followSet := self follow: p in: root. |
|
532 |
|
533 self assert: followSet anySatisfy: [:e | (e parse: 'b') isPetitFailure not]. |
|
534 self assert: followSet anySatisfy: [:e | (e parse: 'c') isPetitFailure not]. |
|
535 self assert: followSet noneSatisfy: [:e | (e parse: 'a') isPetitFailure not]. |
|
536 ! |
|
537 |
|
538 testFollowSetChoice2 |
|
539 | result p root followSet follow b c | |
|
540 |
|
541 follow := 'a' asParser / 'd' asParser. |
|
542 b := 'b' asParser. |
|
543 c := 'c' asParser. |
|
544 p := b / c. |
|
545 |
|
546 root := p, follow. |
|
547 |
|
548 followSet := self follow: p in: root. |
|
549 |
|
550 self assert: followSet anySatisfy: [:e | (e parse: 'a') isPetitFailure not]. |
|
551 self assert: followSet anySatisfy: [:e | (e parse: 'd') isPetitFailure not]. |
|
552 |
|
553 followSet := self follow: p in: root. |
|
554 |
|
555 self assert: followSet anySatisfy: [:e | (e parse: 'a') isPetitFailure not]. |
|
556 self assert: followSet noneSatisfy: [:e | (e parse: 'c') isPetitFailure not]. |
|
557 ! |
|
558 |
|
559 testFollowSetOptional1 |
|
560 | result p root followSets followSet follow follow1 follow2 | |
|
561 |
|
562 p := 'a' asParser. |
|
563 follow1 := 'b' asParser optional. |
|
564 follow2 := 'c' asParser. |
|
565 |
|
566 root := p, follow1, follow2. |
|
567 |
|
568 followSet := self follow: p in: root. |
|
569 |
|
570 self assert: followSet anySatisfy: [:e | e end matches: 'b']. |
|
571 self assert: followSet anySatisfy: [:e | e end matches: 'c']. |
|
572 self assert: followSet noneSatisfy: [:e | e end matches: '']. |
|
573 ! |
|
574 |
|
575 testFollowSetRepeat1 |
|
576 | p followSet terminal | |
|
577 |
|
578 terminal := 'a' asParser. |
|
579 p := terminal plus. |
|
580 |
|
581 followSet := self follow: terminal in: p. |
|
582 self assert: followSet anySatisfy: [:e | e end matches: 'a' ]. |
|
583 self assert: followSet anySatisfy: [:e | e end matches: '' ]. |
|
584 |
|
585 followSet := self follow: p in: p. |
|
586 self assert: followSet anySatisfy: [:e | e end matches: '' ]. |
|
587 ! |
|
588 |
|
589 testFollowSetStar1 |
|
590 | a b p followSet | |
|
591 |
|
592 a := 'a' asParser star. |
|
593 b := 'b' asParser. |
|
594 p := a, b. |
|
595 followSet := self follow: a in: p. |
|
596 |
|
597 self assert: followSet size: 1. |
|
598 self assert: followSet anySatisfy: [:e | e end matches: 'b']. |
|
599 self assert: followSet noneSatisfy: [:e | e end matches: '']. |
|
600 ! |
|
601 |
|
602 testFollowSetStar3 |
|
603 | a b p followSet n | |
|
604 |
|
605 a := 'a' asParser star. |
|
606 p := a. |
|
607 followSet := self follow: a in: p. |
|
608 |
|
609 self assert: followSet noneSatisfy: [:e | e end matches: 'a']. |
|
610 self assert: followSet anySatisfy: [:e | e end matches: '']. |
|
611 ! |
|
612 |
|
613 testFollowSetStar4 |
|
614 | a b p followSet | |
|
615 |
|
616 a := 'a' asParser. |
|
617 b := 'b' asParser. |
|
618 p := a star, b. |
|
619 followSet := self follow: a in: p. |
|
620 |
|
621 self assert: followSet size: 2. |
|
622 self assert: followSet anySatisfy: [:e | e end matches: 'a']. |
|
623 self assert: followSet anySatisfy: [:e | e end matches: 'b']. |
|
624 self assert: followSet noneSatisfy: [:e | e end matches: '']. |
|
625 ! |
|
626 |
|
627 testFollowSetStar5 |
|
628 | a b p followSet n | |
|
629 |
|
630 a := 'a' asParser. |
|
631 b := 'b' asParser. |
|
632 n := nil asParser. |
|
633 p := a star, (b / n). |
|
634 followSet := self follow: a in: p. |
|
635 |
|
636 |
|
637 self assert: followSet anySatisfy: [:e | e end matches: 'a']. |
|
638 self assert: followSet anySatisfy: [:e | e end matches: 'b']. |
|
639 self assert: followSet anySatisfy: [:e | e end matches: '']. |
|
640 ! |
|
641 |
|
642 testFollowSetStar6 |
|
643 | a b p followSet n | |
|
644 |
|
645 a := 'a' asParser. |
|
646 p := a star. |
|
647 followSet := self follow: a in: p. |
|
648 |
|
649 |
|
650 self assert: followSet anySatisfy: [:e | e end matches: 'a']. |
|
651 self assert: followSet anySatisfy: [:e | e end matches: '']. |
|
652 ! ! |
|
653 |
|
654 !FirstFollowNextTests methodsFor:'test isNullable'! |
|
655 |
|
656 testIsNullable01 |
|
657 self assert: 'a' asParser acceptsEpsilon not. |
|
658 ! |
|
659 |
|
660 testIsNullable02 |
|
661 self assert: 'a' asParser wrapped acceptsEpsilon not. |
|
662 ! |
|
663 |
|
664 testIsNullable03 |
|
665 self assert: nil asParser acceptsEpsilon. |
|
666 ! |
|
667 |
|
668 testIsNullable04 |
|
669 self assert: nil asParser wrapped acceptsEpsilon. |
|
670 ! |
|
671 |
|
672 testIsNullable05 |
|
673 self assert: 'a' asParser not acceptsEpsilon not. |
|
674 ! |
|
675 |
|
676 testIsNullable06 |
|
677 self assert: 'a' asParser and acceptsEpsilon not. |
|
678 ! |
|
679 |
|
680 testIsNullable07 |
|
681 self assert: 'a' asParser wrapped not acceptsEpsilon not. |
|
682 ! |
|
683 |
|
684 testIsNullable08 |
|
685 self assert: 'a' asParser wrapped and acceptsEpsilon not. |
|
686 ! |
|
687 |
|
688 testIsNullable09 |
|
689 self assert: 'a' asParser optional acceptsEpsilon. |
|
690 ! |
|
691 |
|
692 testIsNullable10 |
|
693 self assert: 'a' asParser wrapped optional acceptsEpsilon. |
|
694 ! |
|
695 |
|
696 testIsNullable11 |
|
697 self assert: 'a' asParser wrapped not optional acceptsEpsilon. |
|
698 ! |
|
699 |
|
700 testIsNullable12 |
|
701 self assert: 'a' asParser optional wrapped acceptsEpsilon. |
|
702 ! |
|
703 |
|
704 testIsNullableChoice1 |
|
705 | a b c p | |
|
706 a := 'a' asParser. |
|
707 b := 'b' asParser. |
|
708 c := 'c' asParser. |
|
709 |
|
710 p := a / b / c. |
|
711 |
|
712 self assert: p acceptsEpsilon not. |
|
713 ! |
|
714 |
|
715 testIsNullableChoice2 |
|
716 | a b c p | |
|
717 a := 'a' asParser. |
|
718 b := 'b' asParser optional. |
|
719 c := 'c' asParser. |
|
720 |
|
721 p := a / b / c. |
|
722 |
|
723 self assert: p acceptsEpsilon. |
|
724 ! |
|
725 |
|
726 testIsNullableChoice3 |
|
727 | a b c p | |
|
728 a := 'a' asParser optional. |
|
729 b := 'b' asParser optional. |
|
730 c := 'c' asParser optional. |
|
731 |
|
732 p := a / b / c. |
|
733 |
|
734 self assert: p acceptsEpsilon. |
|
735 ! |
|
736 |
|
737 testIsNullableChoice4 |
|
738 | a b c p | |
|
739 a := 'a' asParser optional wrapped. |
|
740 b := 'b' asParser optional wrapped. |
|
741 c := 'c' asParser optional wrapped. |
|
742 |
|
743 p := a / b / c. |
|
744 |
|
745 self assert: p acceptsEpsilon. |
|
746 ! |
|
747 |
|
748 testIsNullableCycle1 |
|
749 | a p | |
|
750 a := 'a' asParser. |
|
751 p := PPDelegateParser new. |
|
752 |
|
753 p setParser: a / p. |
|
754 self assert: p acceptsEpsilon not. |
|
755 ! |
|
756 |
|
757 testIsNullableCycle2 |
|
758 | a p e | |
|
759 a := 'a' asParser. |
|
760 e := nil asParser. |
|
761 p := PPDelegateParser new. |
|
762 |
|
763 p setParser: (a, p) / e. |
|
764 |
|
765 self assert: p acceptsEpsilon. |
|
766 ! |
|
767 |
|
768 testIsNullableCycle3 |
|
769 | a p e | |
|
770 a := 'a' asParser. |
|
771 e := nil asParser. |
|
772 p := PPDelegateParser new. |
|
773 |
|
774 p setParser: (a, p), e. |
|
775 |
|
776 self assert: p acceptsEpsilon not. |
|
777 ! |
|
778 |
|
779 testIsNullableSeq1 |
|
780 | a b c p | |
|
781 a := 'a' asParser. |
|
782 b := 'b' asParser. |
|
783 c := 'c' asParser. |
|
784 |
|
785 p := a, b, c. |
|
786 |
|
787 self assert: p acceptsEpsilon not. |
|
788 ! |
|
789 |
|
790 testIsNullableSeq2 |
|
791 | a b c p | |
|
792 a := 'a' asParser. |
|
793 b := 'b' asParser optional. |
|
794 c := 'c' asParser. |
|
795 |
|
796 p := a, b, c. |
|
797 |
|
798 self assert: p acceptsEpsilon not. |
|
799 ! |
|
800 |
|
801 testIsNullableSeq3 |
|
802 | a b c p | |
|
803 a := 'a' asParser optional. |
|
804 b := 'b' asParser optional. |
|
805 c := 'c' asParser optional. |
|
806 |
|
807 p := a, b, c. |
|
808 |
|
809 self assert: p acceptsEpsilon. |
|
810 ! |
|
811 |
|
812 testIsNullableSeq4 |
|
813 | a b c p | |
|
814 a := 'a' asParser optional wrapped. |
|
815 b := 'b' asParser optional wrapped. |
|
816 c := 'c' asParser wrapped optional. |
|
817 |
|
818 p := a, b, c. |
|
819 |
|
820 self assert: p acceptsEpsilon. |
|
821 ! ! |
|
822 |
|
823 !FirstFollowNextTests methodsFor:'test next'! |
|
824 |
|
825 testNext1 |
|
826 | p nextSet | |
|
827 p := 'a' asParser. |
|
828 |
|
829 nextSet := (self next: p in: p). |
|
830 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
831 ! |
|
832 |
|
833 testNext2 |
|
834 | p nextSet a b | |
|
835 a := 'a' asParser. |
|
836 b := 'b' asParser. |
|
837 |
|
838 p := a, b. |
|
839 |
|
840 nextSet := (self next: a in: p). |
|
841 self assert: nextSet size: 1. |
|
842 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
843 |
|
844 nextSet := (self next: b in: p). |
|
845 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
846 |
|
847 nextSet := (self next: p in: p). |
|
848 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
849 ! |
|
850 |
|
851 testNext3 |
|
852 | p nextSet a b | |
|
853 a := 'a' asParser. |
|
854 b := 'b' asParser. |
|
855 |
|
856 p := a / b. |
|
857 |
|
858 nextSet := (self next: a in: p). |
|
859 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
860 |
|
861 nextSet := (self next: b in: p). |
|
862 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
863 |
|
864 nextSet := (self next: p in: p). |
|
865 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
866 ! |
|
867 |
|
868 testNext4 |
|
869 | p nextSet a b n | |
|
870 a := 'a' asParser. |
|
871 b := 'b' asParser. |
|
872 n := nil asParser. |
|
873 |
|
874 p := a, n, b. |
|
875 |
|
876 nextSet := (self next: a in: p). |
|
877 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
878 |
|
879 nextSet := (self next: n in: p). |
|
880 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
881 |
|
882 nextSet := (self next: b in: p). |
|
883 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
884 ! |
|
885 |
|
886 testNext5 |
|
887 | p nextSet a b n a1 a2 | |
|
888 a1 := 'a1' asParser wrapped. |
|
889 a2 := 'a2' asParser wrapped. |
|
890 a := (a1 asParser, a2 asParser) wrapped. |
|
891 b := 'b' asParser. |
|
892 n := 'n' asParser optional. |
|
893 |
|
894 p := a, n, b. |
|
895 |
|
896 nextSet := (self next: a1 in: p). |
|
897 self assert: nextSet anySatisfy: [:e | e end matches: 'a2']. |
|
898 |
|
899 nextSet := (self next: a2 in: p). |
|
900 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
901 "Might be test to match nb -- not sure, what is better" |
|
902 self assert: nextSet anySatisfy: [:e | e end matches: 'n']. |
|
903 |
|
904 |
|
905 |
|
906 nextSet := (self next: a in: p). |
|
907 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
908 "Might be test to match nb -- not sure, what is better" |
|
909 self assert: nextSet anySatisfy: [:e | e end matches: 'n']. |
|
910 |
|
911 nextSet := (self next: n in: p). |
|
912 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
913 |
|
914 nextSet := (self next: b in: p). |
|
915 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
916 self assert: nextSet noneSatisfy: [:e | e end matches: 'b']. |
|
917 ! |
|
918 |
|
919 testNext6 |
|
920 | p nextSet a b n a1 a2 | |
|
921 a1 := 'a1' asParser wrapped. |
|
922 a2 := 'a2' asParser wrapped / nil asParser. |
|
923 a := (a1 asParser, a2 asParser) wrapped. |
|
924 b := 'b' asParser. |
|
925 n := 'nil' asParser optional. |
|
926 |
|
927 p := a, n, b. |
|
928 |
|
929 nextSet := (self next: a1 in: p). |
|
930 self assert: nextSet anySatisfy: [:e | e matches: 'a2']. |
|
931 self assert: nextSet anySatisfy: [:e | e matches: 'nilb']. |
|
932 self assert: nextSet anySatisfy: [:e | e matches: 'b']. |
|
933 |
|
934 nextSet := (self next: a2 in: p). |
|
935 self assert: nextSet anySatisfy: [:e | e matches: 'nilb']. |
|
936 self assert: nextSet anySatisfy: [:e | e matches: 'b']. |
|
937 |
|
938 |
|
939 nextSet := (self next: a in: p). |
|
940 self assert: nextSet anySatisfy: [:e | e matches: 'nilb']. |
|
941 self assert: nextSet anySatisfy: [:e | e matches: 'b']. |
|
942 |
|
943 nextSet := (self next: n in: p). |
|
944 self assert: nextSet anySatisfy: [:e | e matches: 'b']. |
|
945 |
|
946 nextSet := (self next: b in: p). |
|
947 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
948 ! |
|
949 |
|
950 testNext7 |
|
951 | p nextSet a b n c | |
|
952 a := 'a' asParser. |
|
953 b := 'b' asParser. |
|
954 c := 'c' asParser. |
|
955 n := nil asParser. |
|
956 |
|
957 p := a, b, a, n, c. |
|
958 |
|
959 nextSet := (self next: a in: p). |
|
960 |
|
961 self assert: nextSet anySatisfy: [:e | e matches: 'b']. |
|
962 self assert: nextSet anySatisfy: [:e | e matches: 'c']. |
|
963 |
|
964 ! |
|
965 |
|
966 testNext8 |
|
967 | p nextSet a b n c | |
|
968 a := 'a' asParser. |
|
969 b := 'b' asParser. |
|
970 c := 'c' asParser. |
|
971 n := nil asParser. |
|
972 |
|
973 p := a, n, a, b, c. |
|
974 |
|
975 nextSet := (self next: a in: p). |
|
976 self assert: nextSet anySatisfy: [:e | e matches: 'a']. |
|
977 self assert: nextSet anySatisfy: [:e | e matches: 'b']. |
|
978 |
|
979 ! |
|
980 |
|
981 testNext9 |
|
982 | a nextSet | |
|
983 a := 'a' asParser. |
|
984 |
|
985 nextSet := (self next: a in: a). |
|
986 self assert: nextSet anySatisfy: [:e | e end matches: '']. |
|
987 |
|
988 |
|
989 ! |
|
990 |
|
991 testNextDelegate1 |
|
992 |
|
993 | a nextSet b c p | |
|
994 a := 'a' asParser optional wrapped. |
|
995 b := 'b' asParser optional wrapped. |
|
996 c := 'c' asParser optional wrapped. |
|
997 p := a, b, c. |
|
998 |
|
999 nextSet := (self next: a in: p). |
|
1000 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
1001 self assert: nextSet anySatisfy: [:e | e end matches: 'c']. |
|
1002 |
|
1003 |
|
1004 ! |
|
1005 |
|
1006 testNextRepeat1 |
|
1007 | p nextSet a b n c | |
|
1008 a := 'a' asParser star. |
|
1009 |
|
1010 nextSet := (self next: a in: a). |
|
1011 self assert: nextSet size: 1. |
|
1012 self assert: nextSet anySatisfy: [:e | e end matches: ''] |
|
1013 ! |
|
1014 |
|
1015 testNextRepeat2 |
|
1016 | p nextSet a b astar | |
|
1017 a := 'a' asParser. |
|
1018 b := 'b' asParser. |
|
1019 astar := a star. |
|
1020 |
|
1021 p := astar, b. |
|
1022 |
|
1023 nextSet := (self next: astar in: p). |
|
1024 |
|
1025 self assert: nextSet size: 1. |
|
1026 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
1027 |
|
1028 |
|
1029 ! |
|
1030 |
|
1031 testNextRepeat3 |
|
1032 | p nextSet a b astar | |
|
1033 a := 'a' asParser. |
|
1034 b := 'b' asParser. |
|
1035 |
|
1036 p := a star, b. |
|
1037 |
|
1038 nextSet := (self next: a in: p). |
|
1039 |
|
1040 self assert: nextSet size: 2. |
|
1041 self assert: nextSet anySatisfy: [:e | e end matches: 'b']. |
|
1042 self assert: nextSet anySatisfy: [:e | e end matches: 'a']. |
|
1043 ! |
|
1044 |
|
1045 testNextRepeat4 |
|
1046 | a nextSet b p root | |
|
1047 a := 'a' asParser. |
|
1048 b := 'b' asParser optional. |
|
1049 |
|
1050 p := a, b. |
|
1051 root := p plus. |
|
1052 |
|
1053 nextSet := (self next: a in: root). |
|
1054 self assert: nextSet anySatisfy: [:e | e end matches: 'a']. |
|
1055 |
|
1056 |
|
1057 ! ! |
|
1058 |