Advertisement
Xliff

Match eqv?

Mar 23rd, 2016
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.16 KB | None | 0 0
  1. #!/usr/bin/perl6
  2.  
  3. multi sub infix:<eqv>(Match:D $a, Match:D $b) {
  4.     return  $a.to   eqv $b.to   &&
  5.             $a.from eqv $b.from &&
  6.             $a.orig eqv $b.orig &&
  7.             $a.made eqv $b.made &&
  8.             $a.list eqv $b.list &&
  9.             $a.hash eqv $b.hash;
  10. }
  11.  
  12. my $string = 'aaaaaaaa' ;
  13. my regex xxx  { $<t1> = aa  $<t2> = a  a } ;
  14. my regex yyy { ($<t1> = [aa] ) ($<t2> = a) a } ;
  15. my regex zzz { ($<t1> = [aa] ) ($<t2> = a) a } ;
  16.  
  17. my $m1 = $string ~~ m:g/<xxx>/;
  18. my $m2 = $string ~~ m:g/<yyy>/;
  19. my $m3 = $string ~~ m:g/<yyy>/;
  20. my $m4 = $string ~~ m:g/<zzz>/;
  21.  
  22. my $ml1 = $string ~~ my regex y1 { ($<t1> = [aa] ) ($<t2> = a) a };
  23. my $ml2 = $string ~~ my regex y2 { ($<t1> = [aa] ) ($<t2> = a) a };
  24. my $ml3 = $string ~~ &yyy;
  25. my $ml4 = $string ~~ &zzz;
  26.  
  27. my $t1 = $m1 eqv $m1;
  28. my $t2 = $m1 eqv $m2;
  29. my $t3 = $m2 eqv $m1;
  30. my $t4 = $m2 eqv $m2;
  31. my $t5 = $m3 eqv $m2;
  32. my $t6 = $m4 eqv $m2;
  33.  
  34. my $t_lex_1 = $ml1 eqv $ml2;
  35. my $t_lex_2 = $ml3 eqv $ml4;
  36.  
  37. my $t_im1 = ('aaa' ~~ /a(..)/) eqv ('aaa' ~~ /a../);
  38. my $t_im2 = ('a' ~~ /(.)/) eqv ('ab' ~~ /(.)/);
  39.  
  40. say "$t1 / $t2 / $t3 / $t4 / $t5 / $t6";
  41. say "$t_lex_1 / $t_lex_2";
  42. say "$t_im1 / $t_im2";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement