sub {
my ($tag, $thing) = @_;
my ($part) = split /\./, $tag;
- return unless $self->trace_these->{$part};
+ return unless $self->trace_these->{$part} or $ENV{DX_TRACE};
my $dp = deparse($thing);
$dp =~ s/\n$//;
warn "${dp}\n";
my ($self, $ss) = @_;
trace recheck => [ statement => [ [ symbol => 'complete_recheck' ] ] ];
+ trace recheck => [ 'leave_block' ];
my $prop = $self->was_recheck_for;
my $re_ss = $self->resume_search_state;
sub apply_to {
my ($self, $old_ss) = @_;
trace recheck => [ statement => [ [ symbol => 'fail_recheck' ] ] ];
+ trace recheck => [ 'leave_block' ];
return $self->resume_search_state;
}
-package DX::Deparse;
+package DX::TraceFormatter;
use Scalar::Util qw(blessed);
use curry;
+use List::Util qw(min);
use DX::Class;
+has ambient_indent_level => (
+ is => 'rwp', lazy => 1, clearer => 1, default => 0
+);
+
sub indent_by { ' ' }
sub format {
my ($self, $thing) = @_;
- local our $Indent_Level = 0;
- $self->_format($thing);
+ local our $Indent_Level = $self->ambient_indent_level;
+ my $unindented = $self->_format($thing);
+ my $indent_level = min($Indent_Level, $self->ambient_indent_level);
+ (my $indented = $unindented)
+ =~ s/^/${\($self->indent_by x $indent_level)}/mg;
+ return $indented;
}
sub _format {
), '}';
}
+sub _format_as_enter_block {
+ my ($self) = @_;
+ $self->_set_ambient_indent_level($self->ambient_indent_level + 1);
+ '{'
+}
+
+sub _format_as_leave_block {
+ my ($self) = @_;
+ $self->_set_ambient_indent_level($self->ambient_indent_level - 1);
+ '}'
+}
+
1;