Changeset 21811 for perl5

Show
Ignore:
Timestamp:
08/06/08 17:08:07 (4 months ago)
Author:
fglock
Message:

[PCR] single-step in alternations

Location:
perl5/Pugs-Compiler-Rule
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • perl5/Pugs-Compiler-Rule/lib/Pugs/Runtime/Regex.pm

    r21436 r21811  
    1717    my $nodes = shift; 
    1818    return sub { 
     19        my $single_step = $_[2]{single_step}; 
    1920        my @state = $_[1] ? @{$_[1]} : ( 0, undef ); 
    2021        while ( $state[0] <= $#$nodes ) { 
     
    2425            $state[1] = $_[3]->state; 
    2526            $state[0]++ unless $state[1]; 
    26             if ( $_[3] || $_[3]->data->{abort} ) { 
     27            if ( $_[3] || $_[3]->data->{abort} || $single_step ) { 
    2728                $_[3]->data->{state} = $state[0] > $#$nodes  
    2829                    ? undef 
     
    4748    } 
    4849    return sub { 
     50        my $single_step = $_[2]{single_step}; 
    4951        my @state = $_[1] ? @{$_[1]} : ( undef, undef ); 
    5052        #print "enter state ",Dumper(\@state); 
  • perl5/Pugs-Compiler-Rule/t/01-iterator_engine_step.t

    r21810 r21811  
    44use warnings; 
    55 
    6 use Test::More tests => 58; 
     6use Test::More tests => 53; 
    77# use Data::Dumper; 
    88# $Data::Dumper::Indent = 1; 
     
    1616{ 
    1717  $rule = Pugs::Runtime::Regex::constant( 'a' ); 
    18   $rule->( 'a123', undef, {capture=>1, step=>1}, $match ); 
     18  $rule->( 'a123', undef, {capture=>1, single_step=>1}, $match ); 
    1919  #print Dumper( $match ); 
    2020  ok ( $match->bool, "a =~ /a/ #1" ); 
     
    2929 
    3030{ 
    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 { 
    5131  # -- continuations in alternation() 
    5232  $rule =  
    5333      Pugs::Runtime::Regex::alternation( [ 
     34        Pugs::Runtime::Regex::constant( 'x' ),  
    5435        Pugs::Runtime::Regex::constant( 'a' ),  
    5536        Pugs::Runtime::Regex::constant( 'ab' ),  
    5637      ] ); 
    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 ); 
    6448  #print "state: ", Dumper($match->state), "\n"; 
    6549  #is ( $match->str, '', "/[a|ab]/ multi-match state #2" );