12 @trigger_error(
'The grammar feature is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED);
29 if (!is_object($grammar)) {
30 $grammar = self::parseGrammar($grammar);
33 $grammar->setParser($this->parser);
34 $values = $grammar->parse($token);
52 abstract protected function getNode(
array $values, $line);
54 protected function getAttribute($node, $attribute, $arguments =
array(),
$type = Twig_Node_Expression_GetAttr::TYPE_ANY, $line = -1)
65 protected function call($node, $attribute, $arguments =
array(), $line = -1)
67 return $this->
getAttribute($node, $attribute, $arguments, Twig_Node_Expression_GetAttr::TYPE_METHOD, $line);
88 foreach ($values as $value) {
101 if (
true === $main) {
108 while ($cursor < strlen($str)) {
109 if (preg_match(
'/\s+/A', $str, $match, null, $cursor)) {
110 $cursor += strlen($match[0]);
111 } elseif (preg_match(
'/<(\w+)(?:\:(\w+))?>/A', $str, $match, null, $cursor)) {
112 $class = sprintf(
'Twig_Extensions_Grammar_%s', ucfirst(isset($match[2]) ? $match[2] :
'Expression'));
113 if (!class_exists($class)) {
114 throw new Twig_Error_Runtime(sprintf(
'Unable to understand "%s" in grammar (%s class does not exist)', $match[0], $class));
116 $grammar->addGrammar(
new $class($match[1]));
117 $cursor += strlen($match[0]);
118 } elseif (preg_match(
'/\w+/A', $str, $match, null, $cursor)) {
120 $cursor += strlen($match[0]);
121 } elseif (preg_match(
'/,/A', $str, $match, null, $cursor)) {
123 $cursor += strlen($match[0]);
124 } elseif (preg_match(
'/\[/A', $str, $match, null, $cursor)) {
125 $cursor += strlen($match[0]);
126 $grammar->addGrammar(self::parseGrammar($str,
false));
127 } elseif (
true !== $main && preg_match(
'/\]/A', $str, $match, null, $cursor)) {
128 $cursor += strlen($match[0]);
132 throw new Twig_Error_Runtime(sprintf(
'Unable to parse grammar "%s" near "...%s..."', $str, substr($str, $cursor, 10)));
call($node, $attribute, $arguments=array(), $line=-1)
Represents a node in the AST.
getGrammar()
Gets the grammar as an object or as a string.
markAsSafe(Twig_Node $node, $line=-1)
Exception thrown when an error occurs at runtime.
getNodeValues(array $values)
static parseGrammar($str, $main=true)
Represents a node that outputs an expression.
Base class for all token parsers.
parse(Twig_Token $token)
Parses a token and returns a node.
getAttribute($node, $attribute, $arguments=array(), $type=Twig_Node_Expression_GetAttr::TYPE_ANY, $line=-1)
Create styles array
The data for the language used.
getNode(array $values, $line)
Gets the nodes based on the parsed values.
output(Twig_Node $node, $line=-1)