From: Matt S Trout Date: Wed, 22 Jun 2016 17:22:36 +0000 (+0000) Subject: extract backtrack decisions out into steps X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c76de01dd23ba8e59821c8587f4e529d31181682;p=scpubgit%2FDX.git extract backtrack decisions out into steps --- diff --git a/lib/DX/SearchState.pm b/lib/DX/SearchState.pm index 99ac3f2..18979e7 100644 --- a/lib/DX/SearchState.pm +++ b/lib/DX/SearchState.pm @@ -35,16 +35,8 @@ sub new_for { sub with_one_step { my ($self) = @_; - my $hyp = $self->current_hypothesis; return undef unless my $step = $self->next_step; - my ($new_ss) = $step->apply_to($self); - return $new_ss if $new_ss; - my ($first_alt, @rest_alt) = @{$self->alternatives}; - return undef unless $first_alt; - trace 'search.backtrack.rewind_to' => $first_alt->[1]; - return $self->but( - next_step => DX::Step::Backtrack->new, - ); + return $step->apply_to($self); } sub force_backtrack { diff --git a/lib/DX/Step/InvokeNextPredicate.pm b/lib/DX/Step/InvokeNextPredicate.pm index dc9aab1..55bee44 100644 --- a/lib/DX/Step/InvokeNextPredicate.pm +++ b/lib/DX/Step/InvokeNextPredicate.pm @@ -12,7 +12,7 @@ sub apply_to { if (my $step = $self->proposition->resolve_for($hyp->scope)) { return $ss->but(next_step => $step); } - return undef; + return $ss->but(next_step => DX::Step::Backtrack->new); } 1; diff --git a/lib/DX/Step/Normal.pm b/lib/DX/Step/Normal.pm index 2ec93aa..e314088 100644 --- a/lib/DX/Step/Normal.pm +++ b/lib/DX/Step/Normal.pm @@ -30,7 +30,7 @@ sub apply_to { trace 'step.apply.old_hyp '.$self => $old_hyp; trace 'step.apply.actions '.$self => $self->actions; my $new_hyp = $self->_apply_to_hyp($old_hyp); - return (undef, $self->alternative_step) unless $new_hyp; + return $ss->but(next_step => DX::Step::Backtrack->new) unless $new_hyp; trace 'step.apply.new_hyp '.$self => $new_hyp; my $ns = DX::Step::InvokeNextPredicate->new( proposition => $ss->next_proposition($new_hyp)