68
68
use base qw(RDF::Trine::Error);
70
package RDF::Trine::Error::ParserError::Explainable;
72
use base qw(RDF::Trine::Error::ParserError);
73
use Module::Load::Conditional qw[can_load];
77
$ANSI = can_load( modules => { 'Term::ANSIColor' => undef } );
86
$buffer = $fh->getline;
91
package RDF::Trine::Error::ParserError::Tokenized;
93
use base qw(RDF::Trine::Error::ParserError::Explainable);
99
my $text = $self->text;
100
my $t = $self->object;
101
my $line = $t->start_line;
102
my $col = $t->start_column;
103
my $buffer = $self->_get_line( $fh, $line );
104
my $maxlen = length($buffer) - $col;
106
if ($t->line == $t->start_line) {
107
$len = ($t->column - $t->start_column);
112
my $tabs = ($buffer =~ tr/\t//);
118
if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
119
print STDERR Term::ANSIColor::color('red');
120
print STDERR "$text:\n";
121
print STDERR Term::ANSIColor::color('reset');
122
print STDERR substr($buffer, 0, $col-1);
123
print STDERR Term::ANSIColor::color('red');
124
print STDERR substr($buffer, $col-1, $len);
125
print STDERR Term::ANSIColor::color('reset');
126
print STDERR substr($buffer, $col+$len-1);
127
print STDERR " " x ($col-1);
128
print STDERR Term::ANSIColor::color('blue');
131
print STDERR ("~" x ($len-1));
134
print STDERR Term::ANSIColor::color('reset');
136
print STDERR "$text:\n";
137
print STDERR $buffer;
138
print STDERR " " x ($col-1);
141
print STDERR ("~" x ($len-1));
147
package RDF::Trine::Error::ParserError::Positioned;
149
use base qw(RDF::Trine::Error::ParserError::Explainable);
155
my $text = $self->text;
156
my $pos = $self->value;
157
my ($line, $col) = @$pos;
158
my $buffer = $self->_get_line( $fh, $line );
160
my $tabs = ($buffer =~ tr/\t//);
166
if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
167
print STDERR Term::ANSIColor::color('red');
168
print STDERR "$text:\n";
169
print STDERR Term::ANSIColor::color('reset');
170
print STDERR $buffer;
171
print STDERR Term::ANSIColor::color('red');
172
print STDERR " " x ($col-1);
174
print STDERR Term::ANSIColor::color('reset');
177
print STDERR "$text:\n";
178
print STDERR $buffer;
179
print STDERR " " x ($col-1);
70
185
package RDF::Trine::Error::UnimplementedError;
72
187
use base qw(RDF::Trine::Error);