- Timestamp:
- 08/07/08 23:17:55 (4 months ago)
- Location:
- perl5/Pugs-Compiler-Rule
- Files:
-
- 1 added
- 2 modified
-
Regex-pm-parallel_alternation.pm (added)
-
lib/Pugs/Runtime/Match.pm (modified) (1 diff)
-
t/01-iterator_engine_step.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
perl5/Pugs-Compiler-Rule/lib/Pugs/Runtime/Match.pm
r15793 r21840 30 30 my $obj = bless \$_[1], $_[0]; 31 31 $_data{ refaddr $obj } = $_[1]; 32 return $obj; 33 } 34 35 sub clone { 36 my $data = { %{ $_[0]->data } }; 37 my $obj = bless $data, ref $_[0]; 38 $_data{ refaddr $obj } = $data; 32 39 return $obj; 33 40 } -
perl5/Pugs-Compiler-Rule/t/01-iterator_engine_step.t
r21812 r21840 4 4 use warnings; 5 5 6 use Test::More tests => 12; 7 # use Data::Dumper; 8 # $Data::Dumper::Indent = 1; 9 # $Data::Dumper::Pad = '# '; 6 use Test::More tests => 28; 7 use Data::Dumper; 8 $Data::Dumper::Indent = 1; 9 $Data::Dumper::Pad = '# '; 10 $Data::Dumper::Sortkeys = 1; 10 11 11 12 use_ok( 'Pugs::Runtime::Regex' ); 12 13 use Pugs::Runtime::Match; 13 14 14 my ( $rule, $match ); 15 16 { 17 $rule = Pugs::Runtime::Regex::constant( 'a' );15 { 16 my $match; 17 my $rule = Pugs::Runtime::Regex::constant( 'a' ); 18 18 19 $rule->( 'a123', undef, {capture=>1, single_step=>1}, $match ); 19 #print Dumper( $match ); 20 ok ( $match->bool, "a =~ /a/ #1" ); 21 is ( $match->tail, '123', "tail is ok" ); 20 #print Dumper( $match ); 21 ok ( $match->bool, "a =~ /a/ #1" ); 22 is ( $match->tail, '123', "tail is ok" ); 23 ok ( !defined($match->state), "no more states" ); 24 22 25 $rule->( 'c', undef, {capture=>1}, $match ); 23 ok ( ! $match->bool, "c =~ /a/ #2" ); 24 #is ( $match->tail, 'c123', "tail is ok" ); 25 #print Dumper( $match ); 26 ok ( ! $match->bool, "c =~ /a/ #2" ); 27 #is ( $match->tail, 'c123', "tail is ok" ); 28 #print Dumper( $match ); 29 26 30 $rule->( 'ca', undef, {}, $match); 27 ok( !$match->bool, "anchored match" ); 31 ok( !$match->bool, "anchored match" ); 32 28 33 } 29 34 30 35 { 31 36 # -- continuations in alternation() 32 $rule = 37 my $match; 38 my $rule = 33 39 Pugs::Runtime::Regex::alternation( [ 34 40 Pugs::Runtime::Regex::constant( 'x' ), … … 36 42 Pugs::Runtime::Regex::constant( 'ab' ), 37 43 ] ); 44 38 45 $rule->( 'ab', undef, {single_step => 1}, $match ); 39 #print "state: ", Dumper($match->state), "\n"; 40 is ( $match->str, '', "/[a|ab]/ multi-match continuation state #0 - no match" ); 46 #print "state: ", Dumper($match->state), "\n"; 47 is ( $match->str, '', "/[a|ab]/ multi-match continuation state #0 - no match" ); 48 ok ( defined($match->state), "more states" ); 49 41 50 $rule->( 'ab', $match->state, {single_step => 1}, $match ); 42 #print "state: ", Dumper($match->state), "\n"; 43 is ( $match->str, 'a', "/[a|ab]/ multi-match continuation state #1" ); 51 #print "# state: ", Dumper($match->state), "\n"; 52 is ( $match->str, 'a', "/[a|ab]/ multi-match continuation state #1" ); 53 ok ( defined($match->state), "more states" ); 54 44 55 $rule->( 'ab', $match->state, {single_step => 1}, $match ); 45 #print "state: ", Dumper($match->state), "\n"; 46 is ( $match->str, 'ab', "/[a|ab]/ multi-match continuation state #2" ); 47 #$rule->( 'ab', $match->state, {single_step => 1}, $match ); 48 #print "state: ", Dumper($match->state), "\n"; 49 #is ( $match->str, '', "/[a|ab]/ multi-match state #2" ); 50 #print Dumper( $match ); 56 #print "# state: ", Dumper($match->state), "\n"; 57 is ( $match->str, 'ab', "/[a|ab]/ multi-match continuation state #2" ); 58 ok ( !defined($match->state), "no more states" ); 59 51 60 } 52 61 53 62 { 54 63 # -- continuations in concat() 55 $rule = 64 my $match; 65 my $rule = 56 66 Pugs::Runtime::Regex::concat( [ 57 67 Pugs::Runtime::Regex::alternation( [ … … 65 75 ] ); 66 76 my $str = 'abbb'; 67 # expected: () (a,bb) () (ab,bb) 77 # expected: (a) (fail) (a,bb) (ab) (fail) (ab,bb) 78 68 79 $rule->( $str, undef, {single_step => 1}, $match ); 69 #print "state 1: ", Dumper($match->state), "\n"; 70 is ( $match->str, '', "/[a|ab][b|bb]/ continuation state #0" ); 71 72 $rule->( $str, $match->state, {single_step => 1}, $match ); 73 #print "state 2: ", Dumper($match->state), "\n"; 74 is ( $match->str, 'abb', "state #1" ); 75 76 TODO: { 77 local $TODO = 'concat single-step not implemented'; 78 79 $rule->( $str, $match->state, {single_step => 1}, $match ); 80 #print "state 3: ", Dumper($match->state), "\n"; 81 is ( $match->str, '', "state #2" ); 82 83 $rule->( $str, $match->state, {single_step => 1}, $match ); 84 #print "state 4: ", Dumper($match->state), "\n"; 85 is ( $match->str, 'abbb', "state #3" ); 86 } 80 #print "state 1: ", Dumper($match->state), "\n"; 81 is ( $match->str, 'a', "$str ~~ /[a|ab][x|bb]/ continuation state #0" ); 82 ok ( defined($match->state), "more states" ); 83 84 $rule->( $str, $match->state, {single_step => 1}, $match ); 85 #print "state 2: ", Dumper($match->state), "\n"; 86 is ( $match->str, '', "state #2" ); 87 ok ( defined($match->state), "more states" ); 88 89 $rule->( $str, $match->state, {single_step => 1}, $match ); 90 #print "state 3: ", Dumper($match->state), "\n"; 91 is ( $match->str, 'abb', "state #3" ); 92 ok ( defined($match->state), "more states" ); 93 94 $rule->( $str, $match->state, {single_step => 1}, $match ); 95 #print "state 4: ", Dumper($match->state), "\n"; 96 is ( $match->str, 'ab', "state #4" ); 97 ok ( defined($match->state), "more states" ); 98 99 $rule->( $str, $match->state, {single_step => 1}, $match ); 100 #print "state 5: ", Dumper($match->state), "\n"; 101 is ( $match->str, '', "state #5" ); 102 ok ( defined($match->state), "more states" ); 103 104 $rule->( $str, $match->state, {single_step => 1}, $match ); 105 #print "state 6: ", Dumper($match->state), "\n"; 106 is ( $match->str, 'abbb', "state #6" ); 107 ok ( !defined($match->state), "no more states" ); 108 109 } 110 111 { 112 # -- continuations in parallel_alternation() 113 my $match; 114 my $rule = 115 Pugs::Runtime::Regex::parallel_alternation( [ 116 Pugs::Runtime::Regex::concat( [ 117 Pugs::Runtime::Regex::constant( 'a' ), 118 Pugs::Runtime::Regex::constant( 'bb' ), 119 ] ), 120 Pugs::Runtime::Regex::concat( [ 121 Pugs::Runtime::Regex::constant( 'ab' ), 122 Pugs::Runtime::Regex::constant( 'bb' ), 123 ] ), 124 ] ); 125 my $str = 'abbb'; 126 # expected: (a|ab) (abb|abbb) -> longest token = abbb 127 128 $rule->( $str, undef, {single_step => 1}, $match ); 129 #print "state 1: ", Dumper($match->state), "\n"; 130 is ( $match->str, '', "$str ~~ /a bb | ab bb/ parallel_alternation state #0" ); 131 ok ( defined($match->state), "more states" ); 132 133 $rule->( $str, $match->state, {single_step => 1}, $match ); 134 #print "state 2: ", Dumper($match->state), "\n"; 135 is ( $match->str, 'abbb', "state #2" ); 136 ok ( !defined($match->state), "no more states" ); 87 137 88 138 }
