44 return implode(
"\n", $this->tokens);
49 $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current));
59 if (!isset($this->tokens[++$this->current])) {
60 throw new Twig_Error_Syntax(
'Unexpected end of template', $this->tokens[$this->current - 1]->getLine(), $this->filename);
63 return $this->tokens[$this->current - 1];
71 public function expect($type, $value = null, $message = null)
74 if (!$token->test($type, $value)) {
75 $line = $token->getLine();
76 throw new Twig_Error_Syntax(sprintf(
'%sUnexpected token "%s" of value "%s" ("%s" expected%s)',
77 $message ? $message.
'. ' :
'',
96 public function look($number = 1)
98 if (!isset($this->tokens[$this->current + $number])) {
99 throw new Twig_Error_Syntax(
'Unexpected end of template', $this->tokens[$this->current + $number - 1]->getLine(), $this->filename);
102 return $this->tokens[$this->current + $number];
110 public function test($primary, $secondary = null)
next()
Sets the pointer to the next token and returns the old one.
isEOF()
Checks if end of stream was reached.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
look($number=1)
Looks at the next token.
static typeToEnglish($type, $line=-1)
Returns the english representation of a given type.
injectTokens(array $tokens)
Represents a token stream.
expect($type, $value=null, $message=null)
Tests a token and returns it or throws a syntax error.
getFilename()
Gets the filename associated with this stream.
test($primary, $secondary=null)
Tests the current token.
__construct(array $tokens, $filename=null)
Constructor.
getCurrent()
Gets the current token.
__toString()
Returns a string representation of the token stream.