[Templates-cvs] cvs commit: TT3/lib/Template Scanner.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Wed, 10 Nov 2004 17:57:34 +0000
cvs 04/11/10 17:57:34
Modified: lib/Template Scanner.pm
Log:
* added extract() to show extract from source text on error
* bypass loop if no tagset regex, to handle empty or disabled tagsets
Revision Changes Path
1.3 +22 -4 TT3/lib/Template/Scanner.pm
Index: Scanner.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/Scanner.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Scanner.pm 2004/11/09 13:30:49 1.2
+++ Scanner.pm 2004/11/10 17:57:34 1.3
@@ -20,7 +20,7 @@
# Handle multiple lines for nested calls.
#
# REVISION
-# $Id: Scanner.pm,v 1.2 2004/11/09 13:30:49 abw Exp $
+# $Id: Scanner.pm,v 1.3 2004/11/10 17:57:34 abw Exp $
#
#========================================================================
@@ -32,7 +32,7 @@
use Template::Tagset;
use base qw( Template::Base );
-our $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
+our $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
our $DEBUG = 0 unless defined $DEBUG;
our $ERROR = '';
our $TAGSET = 'Template::Tagset';
@@ -149,7 +149,7 @@
$texttag = $self->{ text };
my $tagset = $self->{ tagset };
my $tagmap = $tagset->tagmap() || return $self->error($tagset->error());
- my $regex = $tagmap->{ regex };
+ my $regex = $tagmap->{ regex } || last SCAN_FOR_TAGS;
while ($$textref =~ /$regex/cg) {
# each time around the loop, the above regex returns
@@ -165,6 +165,7 @@
$lines = ($pretext =~ tr/\n//);
local $self->{ match } = $match = {
+ text => $textref,
line => $$lineref,
lines => $lines,
offset => $start_pos,
@@ -199,6 +200,7 @@
# setup data structure containing info about current match
$start_pos = pos($$textref) || 0;
local $self->{ match } = $match = {
+ text => $textref,
start => $start,
line => $$lineref,
offset => $start_pos,
@@ -249,6 +251,7 @@
my $pretext = $1;
$lines = ($pretext =~ tr/\n//);
local $self->{ match } = $match = {
+ text => $textref,
line => $$lineref,
lines => $lines,
offset => $start_pos,
@@ -314,6 +317,8 @@
my $match = shift || $self->{ match }
|| return $self->error('no current match');
+ # TODO: see if the current position has changed wrt offset?
+
if (defined $match->{ location }) {
return $match->{ location };
}
@@ -328,7 +333,20 @@
}
}
+# TODO: figure out how to stuff the extract (and line number info, etc.) into an
+# exception to throw back
+sub extract {
+ my $self = shift;
+ my $match = shift || $self->{ match }
+ || return $self->error('no current match');
+ my $textref = $match->{ text };
+ my $pos = pos($$textref) || return '';
+ my $extract = substr($$textref, $match->{ offset }, $pos - $match->{ offset });
+ $extract =~ s/\n/\\n/g;
+ return $extract;
+}
+
sub scan_error {
my $self = shift;
return $self->error($self->location(), ': ', @_);
@@ -370,7 +388,7 @@
=head1 VERSION
-$Revision: 1.2 $
+$Revision: 1.3 $
=head1 COPYRIGHT