From: Matt S Trout Date: Sun, 4 Mar 2018 18:32:05 +0000 (+0000) Subject: rename Deparse to TraceFormatter and add ambient indent level X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1444edde2aa4fa709e88c89ec203a6b579a008c7;p=scpubgit%2FDX.git rename Deparse to TraceFormatter and add ambient indent level --- diff --git a/lib/DX/ShellState.pm b/lib/DX/ShellState.pm index 8ddaab0..9f77143 100644 --- a/lib/DX/ShellState.pm +++ b/lib/DX/ShellState.pm @@ -24,7 +24,7 @@ sub trace_sub { 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"; diff --git a/lib/DX/Step/CompleteRecheck.pm b/lib/DX/Step/CompleteRecheck.pm index f74f90c..8886f3c 100644 --- a/lib/DX/Step/CompleteRecheck.pm +++ b/lib/DX/Step/CompleteRecheck.pm @@ -12,6 +12,7 @@ sub apply_to { 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; diff --git a/lib/DX/Step/EnterRecheck.pm b/lib/DX/Step/EnterRecheck.pm index a1954a1..f0fffd1 100644 --- a/lib/DX/Step/EnterRecheck.pm +++ b/lib/DX/Step/EnterRecheck.pm @@ -23,6 +23,7 @@ sub apply_to { trace recheck => [ statement => [ [ symbol => 'recheck' ], @{$prop->for_deparse->[1]}, + [ 'enter_block' ], ] ]; my $old_hyp = $old_ss->current_hypothesis; diff --git a/lib/DX/Step/FailRecheck.pm b/lib/DX/Step/FailRecheck.pm index f303d78..82ab5db 100644 --- a/lib/DX/Step/FailRecheck.pm +++ b/lib/DX/Step/FailRecheck.pm @@ -9,6 +9,7 @@ has resume_search_state => (is => 'ro', isa => SearchState, required => 1); sub apply_to { my ($self, $old_ss) = @_; trace recheck => [ statement => [ [ symbol => 'fail_recheck' ] ] ]; + trace recheck => [ 'leave_block' ]; return $self->resume_search_state; } diff --git a/lib/DX/Deparse.pm b/lib/DX/TraceFormatter.pm similarity index 75% rename from lib/DX/Deparse.pm rename to lib/DX/TraceFormatter.pm index a718678..17bfeb7 100644 --- a/lib/DX/Deparse.pm +++ b/lib/DX/TraceFormatter.pm @@ -1,15 +1,24 @@ -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 { @@ -100,4 +109,16 @@ sub _format_as_block { ), '}'; } +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; diff --git a/lib/DX/Utils.pm b/lib/DX/Utils.pm index 4c9f0b8..efdc259 100644 --- a/lib/DX/Utils.pm +++ b/lib/DX/Utils.pm @@ -111,8 +111,8 @@ sub proposition { sub deparse { $dp ||= do { - require DX::Deparse; - DX::Deparse->new; + require DX::TraceFormatter; + DX::TraceFormatter->new; }; my ($thing) = @_; $dp->format($thing);