/** * Constructor... * * @param \vc\Tokens\Token $token The token that was encountered * @param Array $search The list of tokens being searched for * @param Array $allowed The list of allowed tokens */ public function __construct(\vc\Tokens\Token $token, array $search, array $allowed = array()) { parent::__construct(sprintf('Unexpected Token (%s) on line %d', $token->getName(), $token->getLine())); $this->addData("Encountered Token", $token->getName()); $this->addData("Token Line", $token->getLine()); $this->addData("Token Content", $token->getContent()); $this->addData("Searching for Tokens", implode(", ", array_map(array('\\vc\\Tokens\\Token', 'getTokenName'), $search))); $this->addData("Allowed Tokens", implode(", ", array_map(array('\\vc\\Tokens\\Token', 'getTokenName'), $allowed))); }
/** * Builds a token from a mixed input * * @param Mixed $input * @return \vc\Tokens\Token */ private function buildToken($input) { // In most cases, token_get_all represents a token as an array if (is_array($input)) { return \vc\Tokens\Token::fromArray($input); } // When a token is reinstated, its object gets shifted onto this list if ($input instanceof \vc\Tokens\Token) { return $input; } // For custom tokens, we need to derive the line number based on the // previous token. If the previous token contains a carriage return, // then we need to manually bump the value up $line = $this->current->getLine(); if ($this->current->is(\vc\Tokens\Token::T_WHITESPACE)) { $content = $this->current->getContent(); $line += substr_count($content, "\n") + substr_count($content, "\r"); } return new \vc\Tokens\Token(self::lookupToken($input), $input, $line); }
/** * Parses a number * * @param Boolean $positive Whether this value is positive * @param \vc\Tokens\Token $token The token to examine * @return \vc\Data\Value */ private function parseNumber($positive, \vc\Tokens\Token $token) { $content = $token->getContent(); if (!$positive) { $content = "-" . $content; } return new \vc\Data\Value($content, $token->getType() == Token::T_LNUMBER ? "int" : "float"); }