Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Inline.php

function Inline::parseSequence

Parses a YAML sequence.

Throws

ParseException When malformed inline YAML string is parsed

2 calls to Inline::parseSequence()
Inline::parse in vendor/symfony/yaml/Inline.php
Converts a YAML string to a PHP value.
Inline::parseMapping in vendor/symfony/yaml/Inline.php
Parses a YAML mapping.

File

vendor/symfony/yaml/Inline.php, line 349

Class

Inline
Inline implements a YAML parser/dumper for the YAML inline syntax.

Namespace

Symfony\Component\Yaml

Code

private static function parseSequence(string $sequence, int $flags, int &$i = 0, array &$references = []) : array {
    $output = [];
    $len = \strlen($sequence);
    ++$i;
    // [foo, bar, ...]
    $lastToken = null;
    while ($i < $len) {
        if (']' === $sequence[$i]) {
            return $output;
        }
        if (',' === $sequence[$i] || ' ' === $sequence[$i]) {
            if (',' === $sequence[$i] && (null === $lastToken || 'separator' === $lastToken)) {
                $output[] = null;
            }
            elseif (',' === $sequence[$i]) {
                $lastToken = 'separator';
            }
            ++$i;
            continue;
        }
        $tag = self::parseTag($sequence, $i, $flags);
        switch ($sequence[$i]) {
            case '[':
                // nested sequence
                $value = self::parseSequence($sequence, $flags, $i, $references);
                break;
            case '{':
                // nested mapping
                $value = self::parseMapping($sequence, $flags, $i, $references);
                break;
            default:
                $value = self::parseScalar($sequence, $flags, [
                    ',',
                    ']',
                ], $i, null === $tag, $references, $isQuoted);
                // the value can be an array if a reference has been resolved to an array var
                if (\is_string($value) && !$isQuoted && str_contains($value, ': ')) {
                    // embedded mapping?
                    try {
                        $pos = 0;
                        $value = self::parseMapping('{' . $value . '}', $flags, $pos, $references);
                    } catch (\InvalidArgumentException) {
                        // no, it's not
                    }
                }
                if (!$isQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
                    $references[$matches['ref']] = $matches['value'];
                    $value = $matches['value'];
                }
                --$i;
        }
        if (null !== $tag && '' !== $tag) {
            $value = new TaggedValue($tag, $value);
        }
        $output[] = $value;
        $lastToken = 'value';
        ++$i;
    }
    throw new ParseException(\sprintf('Malformed inline YAML string: "%s".', $sequence), self::$parsedLineNumber + 1, null, self::$parsedFilename);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal