/** * Parses a single constant declarator. * * <code> * class Foo * { * // -------- * const BAR = 42; * // -------- * } * </code> * * Or in a comma separated constant defintion: * * <code> * class Foo * { * // -------- * const BAR = 42, * // -------- * * // -------------- * const BAZ = 'Foobar', * // -------------- * * // ---------- * const FOO = 3.14; * // ---------- * } * </code> * * @return \PDepend\Source\AST\ASTConstantDeclarator * @since 0.9.6 */ private function parseConstantDeclarator() { // Remove leading comments and create a new token stack $this->consumeComments(); $this->tokenStack->push(); $token = $this->consumeToken(Tokens::T_STRING); $this->consumeComments(); $this->consumeToken(Tokens::T_EQUAL); $declarator = $this->builder->buildAstConstantDeclarator($token->image); $declarator->setValue($this->parseStaticValue()); return $this->setNodePositionsAndReturn($declarator); }
/** * Parses a single constant declarator. * * <code> * class Foo * { * // -------- * const BAR = 42; * // -------- * } * </code> * * Or in a comma separated constant defintion: * * <code> * class Foo * { * // -------- * const BAR = 42, * // -------- * * // -------------- * const BAZ = 'Foobar', * // -------------- * * // ---------- * const FOO = 3.14; * // ---------- * } * </code> * * @return \PDepend\Source\AST\ASTConstantDeclarator * @since 0.9.6 */ protected function parseConstantDeclarator() { // Remove leading comments and create a new token stack $this->consumeComments(); $this->tokenStack->push(); $tokenType = $this->tokenizer->peek(); if (false === $this->isMethodName($tokenType)) { $this->throwUnexpectedTokenException(); } $token = $this->consumeToken($tokenType); $this->consumeComments(); $this->consumeToken(Tokens::T_EQUAL); $declarator = $this->builder->buildAstConstantDeclarator($token->image); $declarator->setValue($this->parseConstantDeclaratorValue()); return $this->setNodePositionsAndReturn($declarator); }