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)) {
94 if (!$token->test(
$type, $value)) {
95 $line = $token->getLine();
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();
196 class_alias(
'Twig_TokenStream',
'Twig\TokenStream',
false);
__construct(array $tokens, $name=null, $source=null)
getSource()
Gets the source code associated with this stream.
getFilename()
Gets the name associated with this stream (null if not defined).
look($number=1)
Looks at the next token.
test($primary, $secondary=null)
Tests the current token.
getSourceContext()
Gets the source associated with this stream.
Represents a token stream.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
expect($type, $value=null, $message=null)
Tests a token and returns it or throws a syntax error.
nextIf($primary, $secondary=null)
Tests a token, sets the pointer to the next one and returns it or throws a syntax error...
isEOF()
Checks if end of stream was reached.
next()
Sets the pointer to the next token and returns the old one.
catch(Exception $e) $message
injectTokens(array $tokens)
Create styles array
The data for the language used.
static typeToEnglish($type)
Returns the English representation of a given type.
Holds information about a non-compiled Twig template.