Fix '~=' operator

This commit is contained in:
bzick 2014-06-08 23:50:43 +04:00
parent f6c4da8297
commit f3de50813e
2 changed files with 15 additions and 8 deletions

View File

@ -724,6 +724,10 @@ class Template extends Render
break; break;
} }
} elseif ($tokens->is('~')) { // string concatenation operator: 'asd' ~ $var } elseif ($tokens->is('~')) { // string concatenation operator: 'asd' ~ $var
if($tokens->isNext('=')) { // ~=
$exp[] = ".=";
$tokens->next()->next();
} else {
$concat = array(array_pop($exp)); $concat = array(array_pop($exp));
while ($tokens->is('~')) { while ($tokens->is('~')) {
$tokens->next(); $tokens->next();
@ -734,6 +738,7 @@ class Template extends Render
} }
} }
$exp[] = "(" . implode(".", $concat) . ")"; $exp[] = "(" . implode(".", $concat) . ")";
}
} else { } else {
break; break;
} }

View File

@ -1170,6 +1170,7 @@ class TemplateTest extends TestCase
array('{"string" ~ ++$one ~ "end"}', "string2end"), array('{"string" ~ ++$one ~ "end"}', "string2end"),
array('{"string" ~ "one" ~ "end"}', "stringoneend"), array('{"string" ~ "one" ~ "end"}', "stringoneend"),
array('{"string" ~ 1 ~ "end"}', "string1end"), array('{"string" ~ 1 ~ "end"}', "string1end"),
array('{$one ~= "string"} is {$one}', "1string is 1string"),
); );
} }
@ -1536,6 +1537,7 @@ class TemplateTest extends TestCase
/** /**
* @dataProvider providerConcat * @dataProvider providerConcat
* @group testConcat
*/ */
public function testConcat($code, $result) public function testConcat($code, $result)
{ {