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)));
Exception thrown when an error occurs at runtime.