Fix eat_code_line in PHP version

databind
Vitaliy Filippov 2015-02-17 16:02:54 +03:00
parent 4638b1682a
commit 3fb510b015
4 changed files with 11 additions and 25 deletions

View File

@ -93,7 +93,7 @@ chunks = {
} }
. .
chunk = literal { chunk = literal {
$$ = '$t .= ' . $1 . ";\n"; $$ = ($1 != "''" && $1 != '""' ? '$t .= ' . $1 . ";\n" : '');
} }
| "<!--" code_chunk/c "-->" { | "<!--" code_chunk/c "-->" {
$$ = $c; $$ = $c;

View File

@ -4,7 +4,7 @@
* Homepage: http://yourcmc.ru/wiki/VMX::Template * Homepage: http://yourcmc.ru/wiki/VMX::Template
* License: GNU GPLv3 or later * License: GNU GPLv3 or later
* Author: Vitaliy Filippov, 2006-2015 * Author: Vitaliy Filippov, 2006-2015
* Version: V3 (LALR), 2015-01-17 * Version: V3 (LALR), 2015-02-17
* *
* This file contains the implementation of VMX::Template compiler. * This file contains the implementation of VMX::Template compiler.
* It is only used when a template is compiled in runtime. * It is only used when a template is compiled in runtime.
@ -777,6 +777,7 @@ class VMXTemplateLexer
} }
if ($this->in_code <= 0 && $this->in_subst <= 0) if ($this->in_code <= 0 && $this->in_subst <= 0)
{ {
$was_code = true;
$code_pos = strpos($this->code, $this->options->begin_code, $this->pos+$this->force_literal); $code_pos = strpos($this->code, $this->options->begin_code, $this->pos+$this->force_literal);
$subst_pos = strpos($this->code, $this->options->begin_subst, $this->pos+$this->force_literal); $subst_pos = strpos($this->code, $this->options->begin_subst, $this->pos+$this->force_literal);
$this->force_literal = 0; $this->force_literal = 0;
@ -795,7 +796,7 @@ class VMXTemplateLexer
$str = substr($this->code, $this->pos, $code_pos-$this->pos); $str = substr($this->code, $this->pos, $code_pos-$this->pos);
if ($this->options->eat_code_line) if ($this->options->eat_code_line)
{ {
$str = preg_replace('/\n[ \t]*$/s', "\n", $str); $str = preg_replace('/\n[ \t]*$/s', $was_code ? '' : "\n", $str);
} }
$r = array('literal', "'".addcslashes($str, "'\\")."'"); $r = array('literal', "'".addcslashes($str, "'\\")."'");
$this->lineno += substr_count($r[1], "\n"); $this->lineno += substr_count($r[1], "\n");
@ -822,6 +823,7 @@ class VMXTemplateLexer
$this->pos += strlen($this->options->begin_code); $this->pos += strlen($this->options->begin_code);
$this->in_code = 1; $this->in_code = 1;
} }
$was_code = true;
} }
else else
{ {
@ -840,6 +842,7 @@ class VMXTemplateLexer
$this->pos++; $this->pos++;
$this->in_subst = 1; $this->in_subst = 1;
} }
$was_code = false;
} }
return $r; return $r;
} }
@ -898,23 +901,6 @@ class VMXTemplateLexer
$this->in_code -= ($t === $this->options->end_code); $this->in_code -= ($t === $this->options->end_code);
if (!$this->in_code) if (!$this->in_code)
{ {
if ($this->options->eat_code_line)
{
$p = $this->pos;
while ($p < $this->codelen && (($c = $this->code{$p}) == ' ' || $c == "\t" || $c == "\r"))
{
$p++;
}
if ($p < $this->codelen && $this->code{$p} == "\n")
{
$p++;
if ($p < $this->codelen && $this->code{$p} == "\r")
{
$p++;
}
$this->pos = $p;
}
}
return array('-->', $t); return array('-->', $t);
} }
} }
@ -3596,7 +3582,7 @@ class VMXTemplateParser extends lime_parser {
// (3) chunk := literal // (3) chunk := literal
$result = reset($tokens); $result = reset($tokens);
$result = '$t .= ' . $tokens[0] . ";\n"; $result = ($tokens[0] != "''" && $tokens[0] != '""' ? '$t .= ' . $tokens[0] . ";\n" : '');
} }
function reduce_4_chunk_2($tokens, &$result) { function reduce_4_chunk_2($tokens, &$result) {
@ -5005,5 +4991,5 @@ class VMXTemplateParser extends lime_parser {
); );
} }
// Time: 1,0702919960022 seconds // Time: 2,6265029907227 seconds
// Memory: 11815712 bytes // Memory: 11885624 bytes

View File

@ -8,7 +8,7 @@
* Homepage: http://yourcmc.ru/wiki/VMX::Template * Homepage: http://yourcmc.ru/wiki/VMX::Template
* License: GNU GPLv3 or later * License: GNU GPLv3 or later
* Author: Vitaliy Filippov, 2006-2015 * Author: Vitaliy Filippov, 2006-2015
* Version: V3 (LALR), 2015-01-17 * Version: V3 (LALR), 2015-02-17
* *
* The template engine is split into two parts: * The template engine is split into two parts:
* (1) This file - always used when running templates * (1) This file - always used when running templates

View File

@ -93,7 +93,7 @@ chunks: {
} }
; ;
chunk: literal { chunk: literal {
'$t .= ' . $_[1][0] . ";\n"; ($_[1][0] ne "''" && $_[1][0] ne '""' ? '$t .= ' . $_[1][0] . ";\n" : '');
} }
| '<!--' code_chunk '-->' { | '<!--' code_chunk '-->' {
$_[2]; $_[2];