[Templates-cvs] cvs commit: TT3/lib/Template/TT3 Scanner.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Mon, 15 Dec 2003 17:31:28 +0000
cvs 03/12/15 17:31:28
Modified: lib/Template/TT3 Scanner.pm
Log:
* fixed minor bug in line reporting and changed text blocks to be
reported as a range of line nos from-to.
Revision Changes Path
1.5 +18 -14 TT3/lib/Template/TT3/Scanner.pm
Index: Scanner.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/TT3/Scanner.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Scanner.pm 2003/12/15 15:31:12 1.4
+++ Scanner.pm 2003/12/15 17:31:28 1.5
@@ -18,7 +18,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Scanner.pm,v 1.4 2003/12/15 15:31:12 abw Exp $
+# $Id: Scanner.pm,v 1.5 2003/12/15 17:31:28 abw Exp $
#
#========================================================================
@@ -30,7 +30,7 @@
use vars qw( $VERSION $DEBUG $ERROR $WARNING $TAGS );
use base qw( Template::TT3::Base );
-$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
$ERROR = '';
$TAGS = [ ];
@@ -187,9 +187,10 @@
# is there any text preceding the tag start?
if (defined $pretext && length $pretext) {
# count newlines and notify document
- $self->{ line } += ($pretext =~ tr/\n//);
+ $self->{ size } = ($pretext =~ tr/\n//);
$document->text(\$pretext)
- || return $self->scan_error($document->error());
+ || return $self->error($document->error());
+ $self->{ line } += delete $self->{ size };
}
# look for the tag object corresponding to this start token
@@ -205,13 +206,13 @@
$self->debug("matched $start against $regexen->[$n]\n")
if $DEBUG;
$tag = $self->{ regtags }->[$n]
- || return $self->scan_error("no tag for regex $regexen->[$n]");
+ || return $self->error("no tag for regex $regexen->[$n]");
# cached tag found for the start token in tagmap
$tagmap->{ $start } = $tag;
last;
}
}
- return $self->scan_error("no tag defined for '$start'")
+ return $self->error("no tag defined for '$start'")
unless defined $tag;
}
@@ -230,7 +231,7 @@
};
# scan for closing tag and report error if not found
- return $self->scan_error("no closing tag to match $start")
+ return $self->error("no closing tag to match $start")
unless $$textref =~ /$regex/gc;
my ($content, $end) = ($1, $2);
@@ -241,11 +242,11 @@
# call tag scan() method to handle tag content
$tag->scan(\$content, $document, $start, $end)
- || return $self->scan_error($tag->error());
+ || return $self->error($tag->error());
# update document position
- $self->{ line } += $self->{ size };
- $self->{ size } = 0;
+ $self->{ line } += delete $self->{ size };
+# $self->{ size } = 0;
}
else {
# an open tag that has a start but no pre-defined end token.
@@ -261,7 +262,7 @@
# call tag scan() method to scan forwards
$tag->scan($textref, $document, $start)
- || return $self->scan_error($tag->error());
+ || return $self->error($tag->error());
# count any newlines consumed between start and end positions
my $end_pos = pos $$textref || 0;
@@ -280,25 +281,28 @@
# scan for any trailing text
if ($$textref =~ / \G (.+) /sx) {
my $text = $1;
+ $self->{ size } = ($text =~ tr/\n//);
$document->text(\$text)
- || return $self->scan_error($document->error());
+ || return $self->error($document->error());
+ $self->{ line } += delete $self->{ size };
}
return 1;
}
-
sub line {
my $self = shift;
return @_ ? ($self->{ line } = shift) : $self->{ line };
}
+
sub size {
my $self = shift;
return @_ ? ($self->{ size } = shift) : $self->{ size };
}
+
sub position {
my $self = shift;
@@ -347,7 +351,7 @@
=head1 VERSION
-$Revision: 1.4 $
+$Revision: 1.5 $
=head1 COPYRIGHT