add some basic tracing using the new deparser
[scpubgit/DX.git] / lib / DX / Step / Backtrack.pm
index 8e3b5d8..d14ca2f 100644 (file)
@@ -6,14 +6,14 @@ 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],
-  );
+  trace backtrack => [ statement => [ [ symbol => 'backtrack' ] ] ];
+  foreach my $adj (@{$ss->adjustments_made}) {
+    my ($step_was, $ss_was) = @$adj;
+    if (my $alt = $step_was->alternative_step) {
+      return $ss_was->but(next_step => $alt);
+    }
+  }
+  return $ss->but(next_step => $ss->on_exhaustion_step);
 }
 
 1;