fixed SimpleTokenParser accepts comma(",") in grammar

This commit is contained in:
fivestar
2010-08-31 11:32:37 +09:00
committed by Fabien Potencier
parent 839f16145e
commit a115a0667d
2 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ abstract class Twig_SimpleTokenParser extends Twig_TokenParser
}
$grammar->addGrammar(new $class($match[1]));
$cursor += strlen($match[0]);
} elseif (preg_match('/(\w+)/A', $str, $match, null, $cursor)) {
} elseif (preg_match('/(\w+|,)/A', $str, $match, null, $cursor)) {
$grammar->addGrammar(new Twig_Grammar_Constant($match[1]));
$cursor += strlen($match[0]);
} elseif (preg_match('/\[/A', $str, $match, null, $cursor)) {
+11
View File
@@ -96,6 +96,17 @@ class Twig_Tests_SimpleTokenParserTest extends PHPUnit_Framework_TestCase
)
)
)),
array('<expr:expression> [with <arguments:array> [, <optional:expression>]]', new Twig_Grammar_Tag(
new Twig_Grammar_Expression('expr'),
new Twig_Grammar_Optional(
new Twig_Grammar_Constant('with'),
new Twig_Grammar_Array('arguments'),
new Twig_Grammar_Optional(
new Twig_Grammar_Constant(','),
new Twig_Grammar_Expression('optional')
)
)
)),
);
}
}