/** * parse the nex token and return it. */ public function nextToken() { // do we have tokens pushed back? get one if (!empty($this->pushedBack)) { return array_shift($this->pushedBack); } // have we reached the end of the code? if ($this->cursor >= $this->end) { return Twig_Token::EOF($this->lineno); } // otherwise dispatch to the lexing functions depending // on our current position in the code. switch ($this->position) { case self::POSITION_DATA: $tokens = $this->lexData(); break; case self::POSITION_BLOCK: $tokens = $this->lexBlock(); break; case self::POSITION_VAR: $tokens = $this->lexVar(); break; } // if the return value is not an array it's a token if (!is_array($tokens)) { return $tokens; } else { if (empty($tokens)) { return $this->nextToken(); } else { if (count($tokens) > 1) { $first = array_shift($tokens); $this->pushedBack = $tokens; return $first; } } } // otherwise return the first item of the array. return $tokens[0]; }