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
databind
Vitaliy Filippov 2014-12-10 02:38:00 +03:00
parent c86ac3e832
commit 04e7de97e0
3 changed files with 18 additions and 8 deletions

View File

@ -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).')';

View File

@ -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

View File

@ -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)
{