Lines Matching defs:scalar

262      * Parses a YAML scalar.
268 public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array &$references = [], bool &$isQuoted = null)
270 if (\in_array($scalar[$i], ['"', "'"], true)) {
271 // quoted scalar
273 $output = self::parseQuotedScalar($scalar, $i);
276 $tmp = ltrim(substr($scalar, $i), " \n");
278 throw new ParseException(sprintf('Unexpected end of line, expected one of "%s".', implode('', $delimiters)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
281 throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
289 $output = substr($scalar, $i);
296 } elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
301 throw new ParseException(sprintf('Malformed inline YAML string: "%s".', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
304 // a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
306 throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]), self::$parsedLineNumber + 1, $output, self::$parsedFilename);
318 * Parses a YAML quoted scalar.
322 private static function parseQuotedScalar(string $scalar, int &$i = 0): string
324 if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
325 throw new ParseException(sprintf('Malformed inline YAML string: "%s".', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
331 if ('"' == $scalar[$i]) {
561 private static function evaluateScalar(string $scalar, int $flags, array &$references = [], bool &$isQuotedString = null)
564 $scalar = trim($scalar);
566 if (0 === strpos($scalar, '*')) {
567 if (false !== $pos = strpos($scalar, '#')) {
568 $value = substr($scalar, 1, $pos - 2);
570 $value = substr($scalar, 1);
585 $scalarLower = strtolower($scalar);
589 case '' === $scalar:
590 case '~' === $scalar:
596 case '!' === $scalar[0]:
598 case 0 === strpos($scalar, '!!str '):
599 $s = (string) substr($scalar, 6);
607 case 0 === strpos($scalar, '! '):
608 return substr($scalar, 2);
609 case 0 === strpos($scalar, '!php/object'):
611 if (!isset($scalar[12])) {
617 return unserialize(self::parseScalar(substr($scalar, 12)));
621 throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
625 case 0 === strpos($scalar, '!php/const'):
627 if (!isset($scalar[11])) {
634 if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
638 throw new ParseException(sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
641 throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Did you forget to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
645 case 0 === strpos($scalar, '!!float '):
646 return (float) substr($scalar, 8);
647 case 0 === strpos($scalar, '!!binary '):
648 return self::evaluateBinaryScalar(substr($scalar, 9));
651 throw new ParseException(sprintf('The string "%s" could not be parsed as it uses an unsupported built-in tag.', $scalar), self::$parsedLineNumber, $scalar, self::$parsedFilename);
652 case preg_match('/^(?:\+|-)?0o(?P<value>[0-7_]++)$/', $scalar, $matches):
655 if ('-' === $scalar[0]) {
660 case \in_array($scalar[0], ['+', '-', '.'], true) || is_numeric($scalar[0]):
661 if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) {
662 $scalar = str_replace('_', '', $scalar);
666 case ctype_digit($scalar):
667 if (preg_match('/^0[0-7]+$/', $scalar)) {
668 trigger_deprecation('symfony/yaml', '5.1', 'Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0. Use "%s" to represent the octal number.', '0o'.substr($scalar, 1));
670 return octdec($scalar);
673 $cast = (int) $scalar;
675 return ($scalar === (string) $cast) ? $cast : $scalar;
676 case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
677 if (preg_match('/^-0[0-7]+$/', $scalar)) {
678 trigger_deprecation('symfony/yaml', '5.1', 'Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0. Use "%s" to represent the octal number.', '-0o'.substr($scalar, 2));
680 return -octdec(substr($scalar, 1));
683 $cast = (int) $scalar;
685 return ($scalar === (string) $cast) ? $cast : $scalar;
686 case is_numeric($scalar):
687 case Parser::preg_match(self::getHexRegex(), $scalar):
688 $scalar = str_replace('_', '', $scalar);
690 return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar;
696 case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
697 return (float) str_replace('_', '', $scalar);
698 case Parser::preg_match(self::getTimestampRegex(), $scalar):
700 $time = new \DateTime($scalar, new \DateTimeZone('UTC'));
707 if (false !== $scalar = $time->getTimestamp()) {
708 return $scalar;
718 return (string) $scalar;
734 throw new ParseException('Using the unquoted scalar value "!" is not supported. You must quote it.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
737 // Is followed by a scalar and is a built-in tag
761 public static function evaluateBinaryScalar(string $scalar): string
763 $parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
766 throw new ParseException(sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', \strlen($parsedBinaryData)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
770 throw new ParseException(sprintf('The base64 encoded data (%s) contains invalid characters.', $parsedBinaryData), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);