/** * @return Token The next token * @throws Exceptions\SyntaxException */ private function parseToken() { do { $done = true; $token = $this->stream->next(); $type = $token->getType(); $value = $token->getValue(); switch ($type) { case Token::STRING: case Token::LITERAL: $this->operandStack->push(new DataNode($value)); break; case Token::IDENTIFIER: $this->parseIdentifier($value); break; case Token::VARIABLE: $this->parseVariable($value); break; case Token::PUNCTUATION: switch ($value) { case '(': $this->parseExpression(false); break; case '[': $this->parseArray(); break; default: $type = $token->getTypeString(); $line = $token->getLine(); throw new SyntaxException("Unexpected {$type} ({$value}) token", $line); } break; default: $this->stream->expectCurrent(Token::OPERATOR, [$this->unaryPrefixOperators, 'isOperator']); $this->pushOperator($this->unaryPrefixOperators->getOperator($value)); $done = false; break; } } while (!$done); return $this->parsePostfixOperator(); }
public function parseBlock(Stream $stream, $endTags, $type = Token::TAG_START) { ++$this->level; $root = new RootNode(); $token = $stream->next(); while (!$token->test($type, $endTags)) { $token = $this->parseToken($token, $stream, $root); } --$this->level; return $root; }