- Timestamp:
- 08/06/08 17:08:07 (4 months ago)
- Location:
- perl5/Pugs-Compiler-Rule
- Files:
-
- 2 modified
-
lib/Pugs/Runtime/Regex.pm (modified) (3 diffs)
-
t/01-iterator_engine_step.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
perl5/Pugs-Compiler-Rule/lib/Pugs/Runtime/Regex.pm
r21436 r21811 17 17 my $nodes = shift; 18 18 return sub { 19 my $single_step = $_[2]{single_step}; 19 20 my @state = $_[1] ? @{$_[1]} : ( 0, undef ); 20 21 while ( $state[0] <= $#$nodes ) { … … 24 25 $state[1] = $_[3]->state; 25 26 $state[0]++ unless $state[1]; 26 if ( $_[3] || $_[3]->data->{abort} ) {27 if ( $_[3] || $_[3]->data->{abort} || $single_step ) { 27 28 $_[3]->data->{state} = $state[0] > $#$nodes 28 29 ? undef … … 47 48 } 48 49 return sub { 50 my $single_step = $_[2]{single_step}; 49 51 my @state = $_[1] ? @{$_[1]} : ( undef, undef ); 50 52 #print "enter state ",Dumper(\@state); -
perl5/Pugs-Compiler-Rule/t/01-iterator_engine_step.t
r21810 r21811 4 4 use warnings; 5 5 6 use Test::More tests => 5 8;6 use Test::More tests => 53; 7 7 # use Data::Dumper; 8 8 # $Data::Dumper::Indent = 1; … … 16 16 { 17 17 $rule = Pugs::Runtime::Regex::constant( 'a' ); 18 $rule->( 'a123', undef, {capture=>1, s tep=>1}, $match );18 $rule->( 'a123', undef, {capture=>1, single_step=>1}, $match ); 19 19 #print Dumper( $match ); 20 20 ok ( $match->bool, "a =~ /a/ #1" ); … … 29 29 30 30 { 31 $rule =32 Pugs::Runtime::Regex::non_greedy_plus(33 Pugs::Runtime::Regex::alternation( [34 Pugs::Runtime::Regex::constant( 'a' ),35 Pugs::Runtime::Regex::constant( 'c' ),36 ] ),37 );38 $rule->( 'a123', undef, {capture=>1}, $match );39 ok ( $match->bool, "/[a|c]+?/ #1" );40 is ( $match->tail, '123', "tail is ok" );41 $rule->( 'c123', undef, {capture=>1}, $match );42 ok ( $match->bool, "/[a|c]+?/ #2" );43 is ( $match->tail, '123', "tail is ok" );44 #print Dumper( $match );45 $rule->( 'aa123', undef, {capture=>1}, $match );46 ok ( $match->bool, "/[a|c]+?/ #3" );47 is ( $match->tail, 'a123', "tail is ok" );48 }49 50 {51 31 # -- continuations in alternation() 52 32 $rule = 53 33 Pugs::Runtime::Regex::alternation( [ 34 Pugs::Runtime::Regex::constant( 'x' ), 54 35 Pugs::Runtime::Regex::constant( 'a' ), 55 36 Pugs::Runtime::Regex::constant( 'ab' ), 56 37 ] ); 57 $rule->( 'ab', undef, {}, $match ); 58 #print "state: ", Dumper($match->state), "\n"; 59 is ( $match->str, 'a', "/[a|ab]/ multi-match continuation state #0" ); 60 $rule->( 'ab', $match->state, {}, $match ); 61 #print "state: ", Dumper($match->state), "\n"; 62 is ( $match->str, 'ab', "/[a|ab]/ multi-match continuation state #1" ); 63 #$rule->( 'ab', $match->state, {}, $match ); 38 $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" ); 41 $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" ); 44 $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 ); 64 48 #print "state: ", Dumper($match->state), "\n"; 65 49 #is ( $match->str, '', "/[a|ab]/ multi-match state #2" );
