From: Matt S Trout Date: Wed, 22 Jun 2016 02:30:23 +0000 (+0000) Subject: move backtracing out into a step X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=55131db4600e877c076ab37e907540229274534d;p=scpubgit%2FDX.git move backtracing out into a step --- diff --git a/lib/DX/Step/Backtrack.pm b/lib/DX/Step/Backtrack.pm new file mode 100644 index 0000000..8e3b5d8 --- /dev/null +++ b/lib/DX/Step/Backtrack.pm @@ -0,0 +1,19 @@ +package DX::Step::Backtrack; + +use DX::Class; + +with 'DX::Role::Step'; + +sub apply_to { + my ($self, $ss) = @_; + my ($first_alt, @rest_alt) = @{$ss->alternatives}; + return $ss->but(next_step => undef) unless $first_alt; + trace 'search.backtrack.rewind_to' => $first_alt->[1]; + return $ss->but( + current_hypothesis => $first_alt->[0], + alternatives => \@rest_alt, + next_step => $first_alt->[1], + ); +} + +1;