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}"; } }
public function parseTerm(Tokenizer $tokens) { $zval = new Zval($this); if ($tokens->is(Tokenizer::MACRO_UNARY)) { $unary = $tokens->getAndNext(); } else { $unary = ""; } if ($tokens->is(T_LNUMBER, T_DNUMBER)) { return $zval->setScalar($tokens->getAndNext() * intval($unary . "1")); } elseif ($tokens->is(T_CONSTANT_ENCAPSED_STRING)) { $string = $tokens->getAndNext(); if ($string[0] == '"') { $string = substr($string, 1, -1); } else { $string = addslashes(substr($string, 1, -1)); } return $zval->setScalar($string); } elseif ($tokens->is(T_STRING)) { if ($tokens->isSpecialVal()) { return $zval->setScalar(json_decode(strtolower($tokens->getAndNext()))); } else { throw new \RuntimeException("callback or constant: " . $tokens->current()); } } elseif ($tokens->is(T_VARIABLE)) { return $this->parseVariable($tokens); } else { throw new \RuntimeException("Another tokens not ready yet: " . $tokens->current()); } }