sub backtrack {
my ($self) = @_;
- while (my ($state, $var) = @{$self->last_choice}) {
+ my ($state, $var) = ($self);
+ while (($state, $var) = @{$state->last_choice}) {
$var->bound_value; $var->clear_bound_value;
- return $state unless $var->bound_stream->is_exhausted;
+ return $state->mark_choice($var) unless $var->bound_stream->is_exhausted;
}
die "Out of options";
}
$self->new(%$self, next_op => $then);
}
+sub run {
+ my ($state) = @_;
+ while (my $op = $state->next_op) {
+ $state = $op->run($state);
+ }
+ return $state;
+}
+
1;