/** * 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))); }
public function testConstruct() { $token = new Token(Token::T_ECHO, "echo", 1); $this->assertSame(Token::T_ECHO, $token->getType()); $this->assertSame("echo", $token->getcontent()); $this->assertSame(1, $token->getLine()); $this->assertSame("T_ECHO", $token->getName()); }
/** * 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); }