/** * Parses the given token reader * * @param \vc\Data\Signature $signature The base data from which to build * the method * @param \vc\Tokens\Access $access The token stream * @return \vc\Data\Routine\Method */ public function parseMethod(\vc\Data\Signature $signature, \vc\Tokens\Access $access) { $method = $signature->buildMethod(); // Continue iterating until we encounter a Function token while (TRUE) { $token = $access->peekToRequired(array(Token::T_STATIC, Token::T_ABSTRACT, Token::T_FINAL, Token::T_PUBLIC, Token::T_PROTECTED, Token::T_PRIVATE, Token::T_FUNCTION)); // We don't want to consume the function token because the routine // parser looks for it. Break before we get a chance to pop it off // the stream if ($token->is(Token::T_FUNCTION)) { break; } $access->popToken(); if ($token->is(array(Token::T_PUBLIC, Token::T_PROTECTED, Token::T_PRIVATE))) { $method->setVisibility(\vc\Data\Visibility::fromToken($token)); } else { if ($token->is(Token::T_STATIC)) { $method->setStatic(TRUE); } else { if ($token->is(Token::T_ABSTRACT)) { $method->setAbstract(TRUE); } else { if ($token->is(Token::T_FINAL)) { $method->setFinal(TRUE); } } } } } $this->routine->parseRoutine($method, $access); return $method; }
/** * Parse a function out of the given token reader * * @param \vc\Data\Routine $routine The object to fill with data * @param \vc\Tokens\Access $access The token access * @return NULL */ public function parseRoutine(\vc\Data\Routine $routine, \vc\Tokens\Access $access) { $access->findRequired(array(Token::T_FUNCTION)); $token = $access->peekToRequired(array(Token::T_STRING, Token::T_AMPERSAND, Token::T_PARENS_OPEN)); // Handle routines that return a reference if ($token->is(Token::T_AMPERSAND)) { $routine->setReturnRef(TRUE); $access->popToken(); $token = $access->peekToRequired(array(Token::T_STRING, Token::T_PARENS_OPEN)); } // Names are optional because of anonymous methods if ($token->is(Token::T_STRING)) { $access->popToken(); $routine->setName($token->getContent()); } $routine->setArgs($this->args->parseArgs($access)); $access->findRequired(array(Token::T_CURLY_OPEN, Token::T_SEMICOLON)); $this->brackets->parseCurlies($access); }
/** * Parses a value from a token stream * * @param \vc\Tokens\Access $access * @return \vc\Data\Value */ public function parseValue(\vc\Tokens\Access $access) { $token = $access->peekToRequired(array(Token::T_LNUMBER, Token::T_DNUMBER, Token::T_STRING, Token::T_START_HEREDOC, Token::T_CONSTANT_ENCAPSED_STRING, Token::T_ARRAY, Token::T_MINUS, Token::T_NS_SEPARATOR), array(Token::T_EQUALS)); switch ($token->getType()) { // Strings case Token::T_CONSTANT_ENCAPSED_STRING: $access->popToken(); return $this->parseString($token); // HereDocs // HereDocs case Token::T_START_HEREDOC: $access->popToken(); return $this->parseHereDoc($access); // Negative numbers // Negative numbers case Token::T_MINUS: $access->popToken(); $token = $access->findRequired(array(Token::T_LNUMBER, Token::T_DNUMBER)); return $this->parseNumber(FALSE, $token); // Positive Numbers // Positive Numbers case Token::T_LNUMBER: case Token::T_DNUMBER: $access->popToken(); return $this->parseNumber(TRUE, $token); // Keywords like true, false, null and relative constants // Keywords like true, false, null and relative constants case Token::T_STRING: return $this->parseKeyword($access, $token); // Absolute Constants // Absolute Constants case Token::T_NS_SEPARATOR: return $this->parseConstant($access); // Arrays // Arrays case Token::T_ARRAY: $access->popToken(); return $this->parseArray($access); default: throw new \RuntimeException("Unexpected Type"); } }