public function __construct(Tokenizer $tokens, $expect = null, $where = null) { if ($expect && count($expect) == 1 && is_string($expect[0])) { $expect = ", expect '" . $expect[0] . "'"; } else { $expect = ""; } if (!$tokens->curr) { $this->message = "Unexpected end of " . ($where ?: "expression") . "{$expect}"; } else { $this->message = "Unexpected token '" . $tokens->current() . "' in " . ($where ?: "expression") . "{$expect}"; } }
private function _parseName(Tokenizer $tokens) { $tokens->skipIf(T_NS_SEPARATOR); $name = $tokens->get(T_STRING); while ($tokens->next()->is(T_NS_SEPARATOR)) { $name .= '\\' . $tokens->next()->get(T_STRING); } return ltrim($name, '\\'); }
public function parseVariable(Tokenizer $tokens) { $name = substr($tokens->getAndNext(), 1); if ($tokens->is(T_OBJECT_OPERATOR, T_DOUBLE_COLON)) { drop("parse object"); } elseif ($tokens->is('[')) { drop("parse array"); } elseif ($tokens->is('(')) { drop("parse call"); } else { return $this->variable($name); } }