From 04e7de97e034476cebcc015fc0d5fdf6b751a8d7 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 10 Dec 2014 02:38:00 +0300 Subject: [PATCH] Some fixes for PHP version * Allow strftime() without second argument * Fix method calls (error in grammar) * Introduce a self::noop() hack to support method calls and key fetches on expressions --- template.lime | 4 ++-- template.parser.php | 16 ++++++++++------ template.php | 6 ++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/template.lime b/template.lime index 7095d2c..9cadaec 100644 --- a/template.lime +++ b/template.lime @@ -241,7 +241,7 @@ p10: p11/$ . p11: nonbrace | '(' exp/e ')' varpath/p { - $$ = [ '('.$e[0].')'.$p, false ]; + $$ = [ ($p !== '' ? 'self::noop('.$e[0].')'.$p : '('.$e[0].')'), false ]; } | '!' p11/a { $$ = [ '(!'.$a[0].')', true ]; @@ -343,7 +343,7 @@ varpart: '.' namekw/n { } | '.' name/n '(' list/l ')' { $argv = []; - foreach ($args as $a) { + foreach ($l as $a) { $argv[] = $a[0]; } $$ = '->'.$n.'('.implode(', ', $argv).')'; diff --git a/template.parser.php b/template.parser.php index 8a71b30..9e4211d 100644 --- a/template.parser.php +++ b/template.parser.php @@ -418,9 +418,13 @@ $code } /* strftime */ - function function_strftime($fmt, $date) + function function_strftime($fmt, $date = NULL) { - return "strftime($fmt, self::timestamp($date))"; + if ($date !== NULL) + { + $date = ", self::timestamp($date)"; + } + return "strftime($fmt$date)"; } /* ограничение длины строки $maxlen символами на границе пробелов и добавление '...', если что. */ @@ -4002,7 +4006,7 @@ class VMXTemplateParser extends lime_parser { $e = &$tokens[1]; $p = &$tokens[3]; - $result = [ '('.$e[0].')'.$p, false ]; + $result = [ ($p !== '' ? 'self::noop('.$e[0].')'.$p : '('.$e[0].')'), false ]; } function reduce_54_p11_3($tokens, &$result) { @@ -4255,7 +4259,7 @@ class VMXTemplateParser extends lime_parser { $l = &$tokens[3]; $argv = []; - foreach ($args as $a) { + foreach ($l as $a) { $argv[] = $a[0]; } $result = '->'.$n.'('.implode(', ', $argv).')'; @@ -4992,5 +4996,5 @@ class VMXTemplateParser extends lime_parser { ); } -// Time: 0.559287786484 seconds -// Memory: 11818920 bytes +// Time: 1,0702919960022 seconds +// Memory: 11815712 bytes diff --git a/template.php b/template.php index ab12056..481c636 100644 --- a/template.php +++ b/template.php @@ -474,6 +474,12 @@ class VMXTemplate return array($a); } + // No-op, just returns the single argument. Needed to workaround ($expression)['key'] and ($expression)->m() issues. + static function noop($a) + { + return $a; + } + // Guess if the array is associative based on the first key (for performance) static function is_assoc($a) {