37 @trigger_error(sprintf(
'Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
41 $this->source =
$name;
47 $this->filename = $this->source->getName();
52 return implode(
"\n", $this->tokens);
57 $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current),
$tokens, array_slice($this->tokens, $this->current));
67 if (!isset($this->tokens[++$this->current])) {
68 throw new Twig_Error_Syntax(
'Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source);
71 return $this->tokens[$this->current - 1];
79 public function nextIf($primary, $secondary =
null)
81 if ($this->tokens[$this->current]->
test($primary, $secondary)) {
96 throw new Twig_Error_Syntax(sprintf(
'%sUnexpected token "%s" of value "%s" ("%s" expected%s).',
116 public function look($number = 1)
118 if (!isset($this->tokens[$this->current + $number])) {
119 throw new Twig_Error_Syntax(
'Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source);
122 return $this->tokens[$this->current + $number];
130 public function test($primary, $secondary =
null)
162 @trigger_error(sprintf(
'The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
164 return $this->source->getName();
178 @trigger_error(sprintf(
'The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
180 return $this->source->getCode();
196class_alias(
'Twig_TokenStream',
'Twig\TokenStream',
false);
An exception for terminatinating execution or to throw for unit testing.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Holds information about a non-compiled Twig template.
Represents a token stream.
nextIf($primary, $secondary=null)
Tests a token, sets the pointer to the next one and returns it or throws a syntax error.
expect($type, $value=null, $message=null)
Tests a token and returns it or throws a syntax error.
look($number=1)
Looks at the next token.
isEOF()
Checks if end of stream was reached.
getSource()
Gets the source code associated with this stream.
getFilename()
Gets the name associated with this stream (null if not defined).
injectTokens(array $tokens)
test($primary, $secondary=null)
Tests the current token.
next()
Sets the pointer to the next token and returns the old one.
getSourceContext()
Gets the source associated with this stream.
__construct(array $tokens, $name=null, $source=null)
static typeToEnglish($type)
Returns the English representation of a given type.
catch(Exception $e) $message