From cc4434a2fe6f09acc6b61cea426f8796ff225996 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 17 Feb 2015 16:06:54 +0300 Subject: [PATCH] Fix eat_code_line in Perl version --- VMXTemplate.pm | 2 +- VMXTemplate/Lexer.pm | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/VMXTemplate.pm b/VMXTemplate.pm index 551c909..92a52b8 100644 --- a/VMXTemplate.pm +++ b/VMXTemplate.pm @@ -9,7 +9,7 @@ # Homepage: http://yourcmc.ru/wiki/VMX::Template # License: GNU GPLv3 or later # Author: Vitaliy Filippov, 2006-2015 -# Version: V3 (LALR), 2015-01-09 +# Version: V3 (LALR), 2015-02-17 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/VMXTemplate/Lexer.pm b/VMXTemplate/Lexer.pm index 86fd2b1..bb6e601 100644 --- a/VMXTemplate/Lexer.pm +++ b/VMXTemplate/Lexer.pm @@ -106,6 +106,7 @@ sub read_token } if ($self->{in_code} <= 0 && $self->{in_subst} <= 0) { + my $was_code = 1; my $r; my $code_pos = index($self->{code}, $self->{options}->{begin_code}, $self->{skip_chars}); my $subst_pos = $self->{options}->{begin_subst} ne '' ? index($self->{code}, $self->{options}->{begin_subst}, $self->{skip_chars}) : -1; @@ -124,7 +125,7 @@ sub read_token my $str = $self->eat($code_pos); if ($self->{options}->{eat_code_line}) { - $str =~ s/\n[ \t]*$/\n/s; + $was_code ? $str =~ s/\n[ \t]*$//s : $str =~ s/\n[ \t]*$/\n/s; } $r = [ 'literal', [ "'".addcslashes($str, "'")."'", 1 ] ]; } @@ -150,6 +151,7 @@ sub read_token $self->eat(length $self->{options}->{begin_code}); $self->{in_code} = 1; } + $was_code = 1; } else { @@ -166,6 +168,7 @@ sub read_token $self->eat(length $self->{options}->{begin_subst}); $self->{in_subst} = 1; } + $was_code = 0; } return @$r; } @@ -221,11 +224,6 @@ sub read_token $self->{in_code}-- if $t eq $self->{options}->{end_code}; if (!$self->{in_code}) { - if ($self->{options}->{eat_code_line} && - $self->{code} =~ /^([ \t\r]+\n\r?)/so) - { - $self->eat(length $1); - } return ('-->', $t); } }