1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 '''
31 Tests for the lepl.matchers.core module.
32 '''
33
34
35 from unittest import TestCase
36
37 from lepl._test.base import BaseTest, assert_str
38 from lepl.matchers.combine import And, Or
39 from lepl.matchers.core import Any, Literal, Eof, Regexp, Delayed, Lookahead, \
40 Consumer
41 from lepl.matchers.complex import Columns, PostMatch
42 from lepl.matchers.derived import Word, Digit, Integer, Drop, Space, AnyBut, \
43 Newline
44 from lepl.support.node import Node
45
46
47
48
49
50
51 -class AnyTest(TestCase):
57
60
66
68 matcher = Delayed()
69 try:
70 matcher.parse('abc')
71 assert False, 'expected error'
72 except ValueError as e:
73 assert 'unbound' in str(e)
74
77
79
80 self.assert_join([1], Any(), [[[1]]])
81 self.assert_join([1,2], And(Any(), Any()), [[[1],[2]]])
82 self.assert_join([1,2,3], And(Any(), Any()), [[[1],[2]]])
83 self.assert_join([1], And(Any(), Any()), [])
84
86
87 self.assert_join([1,2], Any() & Any(), [[[1],[2]]])
88 self.assert_join([1,2,3], Any() & Any(), [[[1],[2]]])
89 self.assert_join([1,2,3], Any() & Any() & Any(), [[[1],[2],[3]]])
90 self.assert_join([1], Any() & Any(), [])
91
96
98
99 self.assert_list([1,2], Any() + Any(), [[[1,2]]])
100 self.assert_list([1,2,3], Any() + Any(), [[[1,2]]])
101 self.assert_list([1,2,3], Any() + Any() + Any(), [[[1,2,3]]])
102 self.assert_list([1], Any() + Any(), [])
103
114
123
139
150
159
162
164
165 self.assert_direct('andrew, 3333253', Word() / ',' / Integer() / Eof(),
166 [['andrew', ',', ' ', '3333253']])
167
173
179
200
203
206
207
209 depth = 0
210 result = ''
211 for c in text:
212 if c == '<':
213 depth += 1
214 elif c == '>':
215 depth -= 1
216 elif depth == 0:
217 result += c
218 return result
219
221 class Term(Node): pass
222 class Factor(Node): pass
223 class Expression(Node): pass
224
225 expression = Delayed()
226 number = Digit()[1:,...] > 'number'
227 term = (number | '(' / expression / ')') > Term
228 muldiv = Any('*/') > 'operator'
229 factor = (term / (muldiv / term)[0::]) > Factor
230 addsub = Any('+-') > 'operator'
231 expression += (factor / (addsub / factor)[0::]) > Expression
232
233 description = repr(expression)
234 self.assert_same(description, r'''Delayed(matcher=Transform:<apply>(
235 And(
236 Transform:<apply>(
237 And(
238 Transform:<apply>(
239 Or(
240 Transform:<apply>(
241 Transform:<add>(
242 DepthFirst(
243 generator_manager_queue_len=None,
244 stop=None,
245 reduce=([], <built-in function __add__>),
246 rest=FunctionWrapper<Any:<>>('0123456789'),
247 start=1,
248 first=FunctionWrapper<Any:<>>('0123456789')),
249 TransformationWrapper(<add>)),
250 TransformationWrapper(<apply>)),
251 And(
252 And(
253 FunctionWrapper<Literal:<>>('('),
254 Transform:<add>(
255 DepthFirst(
256 generator_manager_queue_len=None,
257 stop=None,
258 reduce=([], <built-in function __add__>),
259 rest=FunctionWrapper<Any:<>>(' \t'),
260 start=0,
261 first=FunctionWrapper<Any:<>>(' \t')),
262 TransformationWrapper(<add>)),
263 [Delayed]),
264 Transform:<add>(
265 DepthFirst(
266 generator_manager_queue_len=None,
267 stop=None,
268 reduce=([], <built-in function __add__>),
269 rest=FunctionWrapper<Any:<>>(' \t'),
270 start=0,
271 first=FunctionWrapper<Any:<>>(' \t')),
272 TransformationWrapper(<add>)),
273 FunctionWrapper<Literal:<>>(')'))),
274 TransformationWrapper(<apply>)),
275 Transform:<add>(
276 DepthFirst(
277 generator_manager_queue_len=None,
278 stop=None,
279 reduce=([], <built-in function __add__>),
280 rest=FunctionWrapper<Any:<>>(' \t'),
281 start=0,
282 first=FunctionWrapper<Any:<>>(' \t')),
283 TransformationWrapper(<add>)),
284 DepthFirst(
285 generator_manager_queue_len=None,
286 stop=None,
287 reduce=([], <built-in function __add__>),
288 rest=And(
289 Transform:<apply>(
290 FunctionWrapper<Any:<>>('*/'),
291 TransformationWrapper(<apply>)),
292 Transform:<add>(
293 DepthFirst(
294 generator_manager_queue_len=None,
295 stop=None,
296 reduce=([], <built-in function __add__>),
297 rest=FunctionWrapper<Any:<>>(' \t'),
298 start=0,
299 first=FunctionWrapper<Any:<>>(' \t')),
300 TransformationWrapper(<add>)),
301 Transform:<apply>(
302 Or(
303 Transform:<apply>(
304 Transform:<add>(
305 DepthFirst(
306 generator_manager_queue_len=None,
307 stop=None,
308 reduce=([], <built-in function __add__>),
309 rest=FunctionWrapper<Any:<>>('0123456789'),
310 start=1,
311 first=FunctionWrapper<Any:<>>('0123456789')),
312 TransformationWrapper(<add>)),
313 TransformationWrapper(<apply>)),
314 And(
315 And(
316 FunctionWrapper<Literal:<>>('('),
317 Transform:<add>(
318 DepthFirst(
319 generator_manager_queue_len=None,
320 stop=None,
321 reduce=([], <built-in function __add__>),
322 rest=FunctionWrapper<Any:<>>(' \t'),
323 start=0,
324 first=FunctionWrapper<Any:<>>(' \t')),
325 TransformationWrapper(<add>)),
326 [Delayed]),
327 Transform:<add>(
328 DepthFirst(
329 generator_manager_queue_len=None,
330 stop=None,
331 reduce=([], <built-in function __add__>),
332 rest=FunctionWrapper<Any:<>>(' \t'),
333 start=0,
334 first=FunctionWrapper<Any:<>>(' \t')),
335 TransformationWrapper(<add>)),
336 FunctionWrapper<Literal:<>>(')'))),
337 TransformationWrapper(<apply>))),
338 start=0,
339 first=And(
340 Transform:<apply>(
341 FunctionWrapper<Any:<>>('*/'),
342 TransformationWrapper(<apply>)),
343 Transform:<add>(
344 DepthFirst(
345 generator_manager_queue_len=None,
346 stop=None,
347 reduce=([], <built-in function __add__>),
348 rest=FunctionWrapper<Any:<>>(' \t'),
349 start=0,
350 first=FunctionWrapper<Any:<>>(' \t')),
351 TransformationWrapper(<add>)),
352 Transform:<apply>(
353 Or(
354 Transform:<apply>(
355 Transform:<add>(
356 DepthFirst(
357 generator_manager_queue_len=None,
358 stop=None,
359 reduce=([], <built-in function __add__>),
360 rest=FunctionWrapper<Any:<>>('0123456789'),
361 start=1,
362 first=FunctionWrapper<Any:<>>('0123456789')),
363 TransformationWrapper(<add>)),
364 TransformationWrapper(<apply>)),
365 And(
366 And(
367 FunctionWrapper<Literal:<>>('('),
368 Transform:<add>(
369 DepthFirst(
370 generator_manager_queue_len=None,
371 stop=None,
372 reduce=([], <built-in function __add__>),
373 rest=FunctionWrapper<Any:<>>(' \t'),
374 start=0,
375 first=FunctionWrapper<Any:<>>(' \t')),
376 TransformationWrapper(<add>)),
377 [Delayed]),
378 Transform:<add>(
379 DepthFirst(
380 generator_manager_queue_len=None,
381 stop=None,
382 reduce=([], <built-in function __add__>),
383 rest=FunctionWrapper<Any:<>>(' \t'),
384 start=0,
385 first=FunctionWrapper<Any:<>>(' \t')),
386 TransformationWrapper(<add>)),
387 FunctionWrapper<Literal:<>>(')'))),
388 TransformationWrapper(<apply>))))),
389 TransformationWrapper(<apply>)),
390 Transform:<add>(
391 DepthFirst(
392 generator_manager_queue_len=None,
393 stop=None,
394 reduce=([], <built-in function __add__>),
395 rest=FunctionWrapper<Any:<>>(' \t'),
396 start=0,
397 first=FunctionWrapper<Any:<>>(' \t')),
398 TransformationWrapper(<add>)),
399 DepthFirst(
400 generator_manager_queue_len=None,
401 stop=None,
402 reduce=([], <built-in function __add__>),
403 rest=And(
404 Transform:<apply>(
405 FunctionWrapper<Any:<>>('+-'),
406 TransformationWrapper(<apply>)),
407 Transform:<add>(
408 DepthFirst(
409 generator_manager_queue_len=None,
410 stop=None,
411 reduce=([], <built-in function __add__>),
412 rest=FunctionWrapper<Any:<>>(' \t'),
413 start=0,
414 first=FunctionWrapper<Any:<>>(' \t')),
415 TransformationWrapper(<add>)),
416 Transform:<apply>(
417 And(
418 Transform:<apply>(
419 Or(
420 Transform:<apply>(
421 Transform:<add>(
422 DepthFirst(
423 generator_manager_queue_len=None,
424 stop=None,
425 reduce=([], <built-in function __add__>),
426 rest=FunctionWrapper<Any:<>>('0123456789'),
427 start=1,
428 first=FunctionWrapper<Any:<>>('0123456789')),
429 TransformationWrapper(<add>)),
430 TransformationWrapper(<apply>)),
431 And(
432 And(
433 FunctionWrapper<Literal:<>>('('),
434 Transform:<add>(
435 DepthFirst(
436 generator_manager_queue_len=None,
437 stop=None,
438 reduce=([], <built-in function __add__>),
439 rest=FunctionWrapper<Any:<>>(' \t'),
440 start=0,
441 first=FunctionWrapper<Any:<>>(' \t')),
442 TransformationWrapper(<add>)),
443 [Delayed]),
444 Transform:<add>(
445 DepthFirst(
446 generator_manager_queue_len=None,
447 stop=None,
448 reduce=([], <built-in function __add__>),
449 rest=FunctionWrapper<Any:<>>(' \t'),
450 start=0,
451 first=FunctionWrapper<Any:<>>(' \t')),
452 TransformationWrapper(<add>)),
453 FunctionWrapper<Literal:<>>(')'))),
454 TransformationWrapper(<apply>)),
455 Transform:<add>(
456 DepthFirst(
457 generator_manager_queue_len=None,
458 stop=None,
459 reduce=([], <built-in function __add__>),
460 rest=FunctionWrapper<Any:<>>(' \t'),
461 start=0,
462 first=FunctionWrapper<Any:<>>(' \t')),
463 TransformationWrapper(<add>)),
464 DepthFirst(
465 generator_manager_queue_len=None,
466 stop=None,
467 reduce=([], <built-in function __add__>),
468 rest=And(
469 Transform:<apply>(
470 FunctionWrapper<Any:<>>('*/'),
471 TransformationWrapper(<apply>)),
472 Transform:<add>(
473 DepthFirst(
474 generator_manager_queue_len=None,
475 stop=None,
476 reduce=([], <built-in function __add__>),
477 rest=FunctionWrapper<Any:<>>(' \t'),
478 start=0,
479 first=FunctionWrapper<Any:<>>(' \t')),
480 TransformationWrapper(<add>)),
481 Transform:<apply>(
482 Or(
483 Transform:<apply>(
484 Transform:<add>(
485 DepthFirst(
486 generator_manager_queue_len=None,
487 stop=None,
488 reduce=([], <built-in function __add__>),
489 rest=FunctionWrapper<Any:<>>('0123456789'),
490 start=1,
491 first=FunctionWrapper<Any:<>>('0123456789')),
492 TransformationWrapper(<add>)),
493 TransformationWrapper(<apply>)),
494 And(
495 And(
496 FunctionWrapper<Literal:<>>('('),
497 Transform:<add>(
498 DepthFirst(
499 generator_manager_queue_len=None,
500 stop=None,
501 reduce=([], <built-in function __add__>),
502 rest=FunctionWrapper<Any:<>>(' \t'),
503 start=0,
504 first=FunctionWrapper<Any:<>>(' \t')),
505 TransformationWrapper(<add>)),
506 [Delayed]),
507 Transform:<add>(
508 DepthFirst(
509 generator_manager_queue_len=None,
510 stop=None,
511 reduce=([], <built-in function __add__>),
512 rest=FunctionWrapper<Any:<>>(' \t'),
513 start=0,
514 first=FunctionWrapper<Any:<>>(' \t')),
515 TransformationWrapper(<add>)),
516 FunctionWrapper<Literal:<>>(')'))),
517 TransformationWrapper(<apply>))),
518 start=0,
519 first=And(
520 Transform:<apply>(
521 FunctionWrapper<Any:<>>('*/'),
522 TransformationWrapper(<apply>)),
523 Transform:<add>(
524 DepthFirst(
525 generator_manager_queue_len=None,
526 stop=None,
527 reduce=([], <built-in function __add__>),
528 rest=FunctionWrapper<Any:<>>(' \t'),
529 start=0,
530 first=FunctionWrapper<Any:<>>(' \t')),
531 TransformationWrapper(<add>)),
532 Transform:<apply>(
533 Or(
534 Transform:<apply>(
535 Transform:<add>(
536 DepthFirst(
537 generator_manager_queue_len=None,
538 stop=None,
539 reduce=([], <built-in function __add__>),
540 rest=FunctionWrapper<Any:<>>('0123456789'),
541 start=1,
542 first=FunctionWrapper<Any:<>>('0123456789')),
543 TransformationWrapper(<add>)),
544 TransformationWrapper(<apply>)),
545 And(
546 And(
547 FunctionWrapper<Literal:<>>('('),
548 Transform:<add>(
549 DepthFirst(
550 generator_manager_queue_len=None,
551 stop=None,
552 reduce=([], <built-in function __add__>),
553 rest=FunctionWrapper<Any:<>>(' \t'),
554 start=0,
555 first=FunctionWrapper<Any:<>>(' \t')),
556 TransformationWrapper(<add>)),
557 [Delayed]),
558 Transform:<add>(
559 DepthFirst(
560 generator_manager_queue_len=None,
561 stop=None,
562 reduce=([], <built-in function __add__>),
563 rest=FunctionWrapper<Any:<>>(' \t'),
564 start=0,
565 first=FunctionWrapper<Any:<>>(' \t')),
566 TransformationWrapper(<add>)),
567 FunctionWrapper<Literal:<>>(')'))),
568 TransformationWrapper(<apply>))))),
569 TransformationWrapper(<apply>))),
570 start=0,
571 first=And(
572 Transform:<apply>(
573 FunctionWrapper<Any:<>>('+-'),
574 TransformationWrapper(<apply>)),
575 Transform:<add>(
576 DepthFirst(
577 generator_manager_queue_len=None,
578 stop=None,
579 reduce=([], <built-in function __add__>),
580 rest=FunctionWrapper<Any:<>>(' \t'),
581 start=0,
582 first=FunctionWrapper<Any:<>>(' \t')),
583 TransformationWrapper(<add>)),
584 Transform:<apply>(
585 And(
586 Transform:<apply>(
587 Or(
588 Transform:<apply>(
589 Transform:<add>(
590 DepthFirst(
591 generator_manager_queue_len=None,
592 stop=None,
593 reduce=([], <built-in function __add__>),
594 rest=FunctionWrapper<Any:<>>('0123456789'),
595 start=1,
596 first=FunctionWrapper<Any:<>>('0123456789')),
597 TransformationWrapper(<add>)),
598 TransformationWrapper(<apply>)),
599 And(
600 And(
601 FunctionWrapper<Literal:<>>('('),
602 Transform:<add>(
603 DepthFirst(
604 generator_manager_queue_len=None,
605 stop=None,
606 reduce=([], <built-in function __add__>),
607 rest=FunctionWrapper<Any:<>>(' \t'),
608 start=0,
609 first=FunctionWrapper<Any:<>>(' \t')),
610 TransformationWrapper(<add>)),
611 [Delayed]),
612 Transform:<add>(
613 DepthFirst(
614 generator_manager_queue_len=None,
615 stop=None,
616 reduce=([], <built-in function __add__>),
617 rest=FunctionWrapper<Any:<>>(' \t'),
618 start=0,
619 first=FunctionWrapper<Any:<>>(' \t')),
620 TransformationWrapper(<add>)),
621 FunctionWrapper<Literal:<>>(')'))),
622 TransformationWrapper(<apply>)),
623 Transform:<add>(
624 DepthFirst(
625 generator_manager_queue_len=None,
626 stop=None,
627 reduce=([], <built-in function __add__>),
628 rest=FunctionWrapper<Any:<>>(' \t'),
629 start=0,
630 first=FunctionWrapper<Any:<>>(' \t')),
631 TransformationWrapper(<add>)),
632 DepthFirst(
633 generator_manager_queue_len=None,
634 stop=None,
635 reduce=([], <built-in function __add__>),
636 rest=And(
637 Transform:<apply>(
638 FunctionWrapper<Any:<>>('*/'),
639 TransformationWrapper(<apply>)),
640 Transform:<add>(
641 DepthFirst(
642 generator_manager_queue_len=None,
643 stop=None,
644 reduce=([], <built-in function __add__>),
645 rest=FunctionWrapper<Any:<>>(' \t'),
646 start=0,
647 first=FunctionWrapper<Any:<>>(' \t')),
648 TransformationWrapper(<add>)),
649 Transform:<apply>(
650 Or(
651 Transform:<apply>(
652 Transform:<add>(
653 DepthFirst(
654 generator_manager_queue_len=None,
655 stop=None,
656 reduce=([], <built-in function __add__>),
657 rest=FunctionWrapper<Any:<>>('0123456789'),
658 start=1,
659 first=FunctionWrapper<Any:<>>('0123456789')),
660 TransformationWrapper(<add>)),
661 TransformationWrapper(<apply>)),
662 And(
663 And(
664 FunctionWrapper<Literal:<>>('('),
665 Transform:<add>(
666 DepthFirst(
667 generator_manager_queue_len=None,
668 stop=None,
669 reduce=([], <built-in function __add__>),
670 rest=FunctionWrapper<Any:<>>(' \t'),
671 start=0,
672 first=FunctionWrapper<Any:<>>(' \t')),
673 TransformationWrapper(<add>)),
674 [Delayed]),
675 Transform:<add>(
676 DepthFirst(
677 generator_manager_queue_len=None,
678 stop=None,
679 reduce=([], <built-in function __add__>),
680 rest=FunctionWrapper<Any:<>>(' \t'),
681 start=0,
682 first=FunctionWrapper<Any:<>>(' \t')),
683 TransformationWrapper(<add>)),
684 FunctionWrapper<Literal:<>>(')'))),
685 TransformationWrapper(<apply>))),
686 start=0,
687 first=And(
688 Transform:<apply>(
689 FunctionWrapper<Any:<>>('*/'),
690 TransformationWrapper(<apply>)),
691 Transform:<add>(
692 DepthFirst(
693 generator_manager_queue_len=None,
694 stop=None,
695 reduce=([], <built-in function __add__>),
696 rest=FunctionWrapper<Any:<>>(' \t'),
697 start=0,
698 first=FunctionWrapper<Any:<>>(' \t')),
699 TransformationWrapper(<add>)),
700 Transform:<apply>(
701 Or(
702 Transform:<apply>(
703 Transform:<add>(
704 DepthFirst(
705 generator_manager_queue_len=None,
706 stop=None,
707 reduce=([], <built-in function __add__>),
708 rest=FunctionWrapper<Any:<>>('0123456789'),
709 start=1,
710 first=FunctionWrapper<Any:<>>('0123456789')),
711 TransformationWrapper(<add>)),
712 TransformationWrapper(<apply>)),
713 And(
714 And(
715 FunctionWrapper<Literal:<>>('('),
716 Transform:<add>(
717 DepthFirst(
718 generator_manager_queue_len=None,
719 stop=None,
720 reduce=([], <built-in function __add__>),
721 rest=FunctionWrapper<Any:<>>(' \t'),
722 start=0,
723 first=FunctionWrapper<Any:<>>(' \t')),
724 TransformationWrapper(<add>)),
725 [Delayed]),
726 Transform:<add>(
727 DepthFirst(
728 generator_manager_queue_len=None,
729 stop=None,
730 reduce=([], <built-in function __add__>),
731 rest=FunctionWrapper<Any:<>>(' \t'),
732 start=0,
733 first=FunctionWrapper<Any:<>>(' \t')),
734 TransformationWrapper(<add>)),
735 FunctionWrapper<Literal:<>>(')'))),
736 TransformationWrapper(<apply>))))),
737 TransformationWrapper(<apply>))))),
738 TransformationWrapper(<apply>)))''')
739 parser = expression.get_parse()
740 description = parser.matcher.tree()
741 self.assert_same(description, r"""TrampolineWrapper<FullFirstMatch>
742 +- Delayed
743 | `- matcher Transform:<apply>
744 | +- _RMemo
745 | | `- TrampolineWrapper<And>
746 | | +- Transform:<apply>
747 | | | +- _RMemo
748 | | | | `- TrampolineWrapper<And>
749 | | | | +- Transform:<apply>
750 | | | | | +- _RMemo
751 | | | | | | `- TrampolineWrapper<Or>
752 | | | | | | +- _RMemo
753 | | | | | | | `- NfaRegexp:<empty_adapter,apply>
754 | | | | | | | +- Sequence(...)
755 | | | | | | | `- alphabet <Unicode>
756 | | | | | | `- _RMemo
757 | | | | | | `- TrampolineWrapper<And>
758 | | | | | | +- _RMemo
759 | | | | | | | `- FunctionWrapper<Literal:<>>
760 | | | | | | | `- '('
761 | | | | | | +- _RMemo
762 | | | | | | | `- NfaRegexp:<empty_adapter>
763 | | | | | | | +- Sequence(...)
764 | | | | | | | `- alphabet <Unicode>
765 | | | | | | +- Delayed
766 | | | | | | | `- matcher <loop>
767 | | | | | | +- _RMemo
768 | | | | | | | `- NfaRegexp:<empty_adapter>
769 | | | | | | | +- Sequence(...)
770 | | | | | | | `- alphabet <Unicode>
771 | | | | | | `- _RMemo
772 | | | | | | `- FunctionWrapper<Literal:<>>
773 | | | | | | `- ')'
774 | | | | | `- TransformationWrapper(<apply>)
775 | | | | +- _RMemo
776 | | | | | `- NfaRegexp:<empty_adapter>
777 | | | | | +- Sequence(...)
778 | | | | | `- alphabet <Unicode>
779 | | | | `- _RMemo
780 | | | | `- TrampolineWrapper<DepthFirst>
781 | | | | +- generator_manager_queue_len None
782 | | | | +- stop None
783 | | | | +- reduce ([], <built-in function __add__>)
784 | | | | +- rest _RMemo
785 | | | | | `- TrampolineWrapper<And>
786 | | | | | +- _RMemo
787 | | | | | | `- FunctionWrapper<Any:<apply>>
788 | | | | | | `- '*/'
789 | | | | | +- _RMemo
790 | | | | | | `- NfaRegexp:<empty_adapter>
791 | | | | | | +- Sequence(...)
792 | | | | | | `- alphabet <Unicode>
793 | | | | | `- Transform:<apply>
794 | | | | | +- _RMemo
795 | | | | | | `- TrampolineWrapper<Or>
796 | | | | | | +- _RMemo
797 | | | | | | | `- NfaRegexp:<empty_adapter,apply>
798 | | | | | | | +- Sequence(...)
799 | | | | | | | `- alphabet <Unicode>
800 | | | | | | `- _RMemo
801 | | | | | | `- TrampolineWrapper<And>
802 | | | | | | +- _RMemo
803 | | | | | | | `- FunctionWrapper<Literal:<>>
804 | | | | | | | `- '('
805 | | | | | | +- _RMemo
806 | | | | | | | `- NfaRegexp:<empty_adapter>
807 | | | | | | | +- Sequence(...)
808 | | | | | | | `- alphabet <Unicode>
809 | | | | | | +- Delayed
810 | | | | | | | `- matcher <loop>
811 | | | | | | +- _RMemo
812 | | | | | | | `- NfaRegexp:<empty_adapter>
813 | | | | | | | +- Sequence(...)
814 | | | | | | | `- alphabet <Unicode>
815 | | | | | | `- _RMemo
816 | | | | | | `- FunctionWrapper<Literal:<>>
817 | | | | | | `- ')'
818 | | | | | `- TransformationWrapper(<apply>)
819 | | | | +- start 0
820 | | | | `- first _RMemo
821 | | | | `- TrampolineWrapper<And>
822 | | | | +- _RMemo
823 | | | | | `- FunctionWrapper<Any:<apply>>
824 | | | | | `- '*/'
825 | | | | +- _RMemo
826 | | | | | `- NfaRegexp:<empty_adapter>
827 | | | | | +- Sequence(...)
828 | | | | | `- alphabet <Unicode>
829 | | | | `- Transform:<apply>
830 | | | | +- _RMemo
831 | | | | | `- TrampolineWrapper<Or>
832 | | | | | +- _RMemo
833 | | | | | | `- NfaRegexp:<empty_adapter,apply>
834 | | | | | | +- Sequence(...)
835 | | | | | | `- alphabet <Unicode>
836 | | | | | `- _RMemo
837 | | | | | `- TrampolineWrapper<And>
838 | | | | | +- _RMemo
839 | | | | | | `- FunctionWrapper<Literal:<>>
840 | | | | | | `- '('
841 | | | | | +- _RMemo
842 | | | | | | `- NfaRegexp:<empty_adapter>
843 | | | | | | +- Sequence(...)
844 | | | | | | `- alphabet <Unicode>
845 | | | | | +- Delayed
846 | | | | | | `- matcher <loop>
847 | | | | | +- _RMemo
848 | | | | | | `- NfaRegexp:<empty_adapter>
849 | | | | | | +- Sequence(...)
850 | | | | | | `- alphabet <Unicode>
851 | | | | | `- _RMemo
852 | | | | | `- FunctionWrapper<Literal:<>>
853 | | | | | `- ')'
854 | | | | `- TransformationWrapper(<apply>)
855 | | | `- TransformationWrapper(<apply>)
856 | | +- _RMemo
857 | | | `- NfaRegexp:<empty_adapter>
858 | | | +- Sequence(...)
859 | | | `- alphabet <Unicode>
860 | | `- _RMemo
861 | | `- TrampolineWrapper<DepthFirst>
862 | | +- generator_manager_queue_len None
863 | | +- stop None
864 | | +- reduce ([], <built-in function __add__>)
865 | | +- rest _RMemo
866 | | | `- TrampolineWrapper<And>
867 | | | +- _RMemo
868 | | | | `- FunctionWrapper<Any:<apply>>
869 | | | | `- '+-'
870 | | | +- _RMemo
871 | | | | `- NfaRegexp:<empty_adapter>
872 | | | | +- Sequence(...)
873 | | | | `- alphabet <Unicode>
874 | | | `- Transform:<apply>
875 | | | +- _RMemo
876 | | | | `- TrampolineWrapper<And>
877 | | | | +- Transform:<apply>
878 | | | | | +- _RMemo
879 | | | | | | `- TrampolineWrapper<Or>
880 | | | | | | +- _RMemo
881 | | | | | | | `- NfaRegexp:<empty_adapter,apply>
882 | | | | | | | +- Sequence(...)
883 | | | | | | | `- alphabet <Unicode>
884 | | | | | | `- _RMemo
885 | | | | | | `- TrampolineWrapper<And>
886 | | | | | | +- _RMemo
887 | | | | | | | `- FunctionWrapper<Literal:<>>
888 | | | | | | | `- '('
889 | | | | | | +- _RMemo
890 | | | | | | | `- NfaRegexp:<empty_adapter>
891 | | | | | | | +- Sequence(...)
892 | | | | | | | `- alphabet <Unicode>
893 | | | | | | +- Delayed
894 | | | | | | | `- matcher <loop>
895 | | | | | | +- _RMemo
896 | | | | | | | `- NfaRegexp:<empty_adapter>
897 | | | | | | | +- Sequence(...)
898 | | | | | | | `- alphabet <Unicode>
899 | | | | | | `- _RMemo
900 | | | | | | `- FunctionWrapper<Literal:<>>
901 | | | | | | `- ')'
902 | | | | | `- TransformationWrapper(<apply>)
903 | | | | +- _RMemo
904 | | | | | `- NfaRegexp:<empty_adapter>
905 | | | | | +- Sequence(...)
906 | | | | | `- alphabet <Unicode>
907 | | | | `- _RMemo
908 | | | | `- TrampolineWrapper<DepthFirst>
909 | | | | +- generator_manager_queue_len None
910 | | | | +- stop None
911 | | | | +- reduce ([], <built-in function __add__>)
912 | | | | +- rest _RMemo
913 | | | | | `- TrampolineWrapper<And>
914 | | | | | +- _RMemo
915 | | | | | | `- FunctionWrapper<Any:<apply>>
916 | | | | | | `- '*/'
917 | | | | | +- _RMemo
918 | | | | | | `- NfaRegexp:<empty_adapter>
919 | | | | | | +- Sequence(...)
920 | | | | | | `- alphabet <Unicode>
921 | | | | | `- Transform:<apply>
922 | | | | | +- _RMemo
923 | | | | | | `- TrampolineWrapper<Or>
924 | | | | | | +- _RMemo
925 | | | | | | | `- NfaRegexp:<empty_adapter,apply>
926 | | | | | | | +- Sequence(...)
927 | | | | | | | `- alphabet <Unicode>
928 | | | | | | `- _RMemo
929 | | | | | | `- TrampolineWrapper<And>
930 | | | | | | +- _RMemo
931 | | | | | | | `- FunctionWrapper<Literal:<>>
932 | | | | | | | `- '('
933 | | | | | | +- _RMemo
934 | | | | | | | `- NfaRegexp:<empty_adapter>
935 | | | | | | | +- Sequence(...)
936 | | | | | | | `- alphabet <Unicode>
937 | | | | | | +- Delayed
938 | | | | | | | `- matcher <loop>
939 | | | | | | +- _RMemo
940 | | | | | | | `- NfaRegexp:<empty_adapter>
941 | | | | | | | +- Sequence(...)
942 | | | | | | | `- alphabet <Unicode>
943 | | | | | | `- _RMemo
944 | | | | | | `- FunctionWrapper<Literal:<>>
945 | | | | | | `- ')'
946 | | | | | `- TransformationWrapper(<apply>)
947 | | | | +- start 0
948 | | | | `- first _RMemo
949 | | | | `- TrampolineWrapper<And>
950 | | | | +- _RMemo
951 | | | | | `- FunctionWrapper<Any:<apply>>
952 | | | | | `- '*/'
953 | | | | +- _RMemo
954 | | | | | `- NfaRegexp:<empty_adapter>
955 | | | | | +- Sequence(...)
956 | | | | | `- alphabet <Unicode>
957 | | | | `- Transform:<apply>
958 | | | | +- _RMemo
959 | | | | | `- TrampolineWrapper<Or>
960 | | | | | +- _RMemo
961 | | | | | | `- NfaRegexp:<empty_adapter,apply>
962 | | | | | | +- Sequence(...)
963 | | | | | | `- alphabet <Unicode>
964 | | | | | `- _RMemo
965 | | | | | `- TrampolineWrapper<And>
966 | | | | | +- _RMemo
967 | | | | | | `- FunctionWrapper<Literal:<>>
968 | | | | | | `- '('
969 | | | | | +- _RMemo
970 | | | | | | `- NfaRegexp:<empty_adapter>
971 | | | | | | +- Sequence(...)
972 | | | | | | `- alphabet <Unicode>
973 | | | | | +- Delayed
974 | | | | | | `- matcher <loop>
975 | | | | | +- _RMemo
976 | | | | | | `- NfaRegexp:<empty_adapter>
977 | | | | | | +- Sequence(...)
978 | | | | | | `- alphabet <Unicode>
979 | | | | | `- _RMemo
980 | | | | | `- FunctionWrapper<Literal:<>>
981 | | | | | `- ')'
982 | | | | `- TransformationWrapper(<apply>)
983 | | | `- TransformationWrapper(<apply>)
984 | | +- start 0
985 | | `- first _RMemo
986 | | `- TrampolineWrapper<And>
987 | | +- _RMemo
988 | | | `- FunctionWrapper<Any:<apply>>
989 | | | `- '+-'
990 | | +- _RMemo
991 | | | `- NfaRegexp:<empty_adapter>
992 | | | +- Sequence(...)
993 | | | `- alphabet <Unicode>
994 | | `- Transform:<apply>
995 | | +- _RMemo
996 | | | `- TrampolineWrapper<And>
997 | | | +- Transform:<apply>
998 | | | | +- _RMemo
999 | | | | | `- TrampolineWrapper<Or>
1000 | | | | | +- _RMemo
1001 | | | | | | `- NfaRegexp:<empty_adapter,apply>
1002 | | | | | | +- Sequence(...)
1003 | | | | | | `- alphabet <Unicode>
1004 | | | | | `- _RMemo
1005 | | | | | `- TrampolineWrapper<And>
1006 | | | | | +- _RMemo
1007 | | | | | | `- FunctionWrapper<Literal:<>>
1008 | | | | | | `- '('
1009 | | | | | +- _RMemo
1010 | | | | | | `- NfaRegexp:<empty_adapter>
1011 | | | | | | +- Sequence(...)
1012 | | | | | | `- alphabet <Unicode>
1013 | | | | | +- Delayed
1014 | | | | | | `- matcher <loop>
1015 | | | | | +- _RMemo
1016 | | | | | | `- NfaRegexp:<empty_adapter>
1017 | | | | | | +- Sequence(...)
1018 | | | | | | `- alphabet <Unicode>
1019 | | | | | `- _RMemo
1020 | | | | | `- FunctionWrapper<Literal:<>>
1021 | | | | | `- ')'
1022 | | | | `- TransformationWrapper(<apply>)
1023 | | | +- _RMemo
1024 | | | | `- NfaRegexp:<empty_adapter>
1025 | | | | +- Sequence(...)
1026 | | | | `- alphabet <Unicode>
1027 | | | `- _RMemo
1028 | | | `- TrampolineWrapper<DepthFirst>
1029 | | | +- generator_manager_queue_len None
1030 | | | +- stop None
1031 | | | +- reduce ([], <built-in function __add__>)
1032 | | | +- rest _RMemo
1033 | | | | `- TrampolineWrapper<And>
1034 | | | | +- _RMemo
1035 | | | | | `- FunctionWrapper<Any:<apply>>
1036 | | | | | `- '*/'
1037 | | | | +- _RMemo
1038 | | | | | `- NfaRegexp:<empty_adapter>
1039 | | | | | +- Sequence(...)
1040 | | | | | `- alphabet <Unicode>
1041 | | | | `- Transform:<apply>
1042 | | | | +- _RMemo
1043 | | | | | `- TrampolineWrapper<Or>
1044 | | | | | +- _RMemo
1045 | | | | | | `- NfaRegexp:<empty_adapter,apply>
1046 | | | | | | +- Sequence(...)
1047 | | | | | | `- alphabet <Unicode>
1048 | | | | | `- _RMemo
1049 | | | | | `- TrampolineWrapper<And>
1050 | | | | | +- _RMemo
1051 | | | | | | `- FunctionWrapper<Literal:<>>
1052 | | | | | | `- '('
1053 | | | | | +- _RMemo
1054 | | | | | | `- NfaRegexp:<empty_adapter>
1055 | | | | | | +- Sequence(...)
1056 | | | | | | `- alphabet <Unicode>
1057 | | | | | +- Delayed
1058 | | | | | | `- matcher <loop>
1059 | | | | | +- _RMemo
1060 | | | | | | `- NfaRegexp:<empty_adapter>
1061 | | | | | | +- Sequence(...)
1062 | | | | | | `- alphabet <Unicode>
1063 | | | | | `- _RMemo
1064 | | | | | `- FunctionWrapper<Literal:<>>
1065 | | | | | `- ')'
1066 | | | | `- TransformationWrapper(<apply>)
1067 | | | +- start 0
1068 | | | `- first _RMemo
1069 | | | `- TrampolineWrapper<And>
1070 | | | +- _RMemo
1071 | | | | `- FunctionWrapper<Any:<apply>>
1072 | | | | `- '*/'
1073 | | | +- _RMemo
1074 | | | | `- NfaRegexp:<empty_adapter>
1075 | | | | +- Sequence(...)
1076 | | | | `- alphabet <Unicode>
1077 | | | `- Transform:<apply>
1078 | | | +- _RMemo
1079 | | | | `- TrampolineWrapper<Or>
1080 | | | | +- _RMemo
1081 | | | | | `- NfaRegexp:<empty_adapter,apply>
1082 | | | | | +- Sequence(...)
1083 | | | | | `- alphabet <Unicode>
1084 | | | | `- _RMemo
1085 | | | | `- TrampolineWrapper<And>
1086 | | | | +- _RMemo
1087 | | | | | `- FunctionWrapper<Literal:<>>
1088 | | | | | `- '('
1089 | | | | +- _RMemo
1090 | | | | | `- NfaRegexp:<empty_adapter>
1091 | | | | | +- Sequence(...)
1092 | | | | | `- alphabet <Unicode>
1093 | | | | +- Delayed
1094 | | | | | `- matcher <loop>
1095 | | | | +- _RMemo
1096 | | | | | `- NfaRegexp:<empty_adapter>
1097 | | | | | +- Sequence(...)
1098 | | | | | `- alphabet <Unicode>
1099 | | | | `- _RMemo
1100 | | | | `- FunctionWrapper<Literal:<>>
1101 | | | | `- ')'
1102 | | | `- TransformationWrapper(<apply>)
1103 | | `- TransformationWrapper(<apply>)
1104 | `- TransformationWrapper(<apply>)
1105 `- True""")
1106
1108
1110 self.assert_direct('0123456789',
1111 Columns(((0,3), Any()[3,...]),
1112 ((0,4), Any()[4:,...]),
1113 ((5,8), Any()[3:,...])),
1114 [['012', '0123', '567']])
1115
1117
1118 self.assert_direct(
1119 '''0123456789
1120 abcdefghij
1121 ''',
1122 Columns(((0,3), Any()[3:,...]),
1123 ((0,4), Any()[4:,...]),
1124 ((5,8), Any()[3:,...]))[2],
1125 [['012', '0123', '567',
1126 'abc', 'abcd', 'fgh']])
1127
1130
1135
1142
1144 '''
1145 This test requires evaluation of sub-matchers via trampolining; if
1146 it fails then there may be an issue with generator_matcher.
1147 '''
1148 parser = Consumer(Any() & Any('b')).get_parse()
1149 result = parser('ab')
1150 assert ['a', 'b'] == result, result
1151
1152
1153 -class PostMatchTest(BaseTest):
1154
1155 - def test_normal(self):
1156 matcher = PostMatch(Drop(Any()[:]) & Any(), r'[0-9]')
1157 matcher.config.no_full_first_match()
1158 results = list(matcher.parse_all('12a'))
1159 assert results == [['2'], ['1']], results
1160
1161 - def test_not(self):
1162 matcher = PostMatch(Drop(Any()[:]) & Any(), r'[0-9]', not_=True)
1163 matcher.config.no_full_first_match()
1164 results = list(matcher.parse_all('12a'))
1165 assert results == [['a']], results
1166