/** * Parses the constant value. * * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * @param \TokenReflection\IReflection $parent Parent reflection object * @return \TokenReflection\ReflectionConstant * @throws \TokenReflection\Exception\ParseException If the constant value could not be determined. */ private function parseValue(Stream $tokenStream, IReflection $parent) { if (!$tokenStream->is('=')) { throw new Exception\ParseException($this, $tokenStream, 'Could not find the definition start.', Exception\ParseException::UNEXPECTED_TOKEN); } $tokenStream->skipWhitespaces(true); static $acceptedTokens = array('-' => true, '+' => true, T_STRING => true, T_NS_SEPARATOR => true, T_CONSTANT_ENCAPSED_STRING => true, T_DNUMBER => true, T_LNUMBER => true, T_DOUBLE_COLON => true, T_CLASS_C => true, T_DIR => true, T_FILE => true, T_FUNC_C => true, T_LINE => true, T_METHOD_C => true, T_NS_C => true, T_TRAIT_C => true); while (null !== ($type = $tokenStream->getType())) { if (T_START_HEREDOC === $type) { $this->valueDefinition[] = $tokenStream->current(); while (null !== $type && T_END_HEREDOC !== $type) { $tokenStream->next(); $this->valueDefinition[] = $tokenStream->current(); $type = $tokenStream->getType(); } $tokenStream->next(); } elseif (isset($acceptedTokens[$type])) { $this->valueDefinition[] = $tokenStream->current(); $tokenStream->next(); } elseif ($tokenStream->isWhitespace(true)) { $tokenStream->skipWhitespaces(true); } else { break; } } if (empty($this->valueDefinition)) { throw new Exception\ParseException($this, $tokenStream, 'Value definition is empty.', Exception\ParseException::LOGICAL_ERROR); } $value = $tokenStream->getTokenValue(); if (null === $type || ',' !== $value && ';' !== $value) { throw new Exception\ParseException($this, $tokenStream, 'Invalid value definition.', Exception\ParseException::LOGICAL_ERROR); } return $this; }