parseScalar example

 {
                if (str_starts_with($values['key'], '!php/const:')) {
                    trigger_deprecation('symfony/yaml', '6.2', 'YAML syntax for key "%s" is deprecated and replaced by "!php/const %s".', $values['key']substr($values['key'], 11));
                }

                if ($context && 'sequence' == $context) {
                    throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
                }
                $context = 'mapping';

                try {
                    $key = Inline::parseScalar($values['key']);
                } catch (ParseException $e) {
                    $e->setParsedLine($this->getRealCurrentLineNb() + 1);
                    $e->setSnippet($this->currentLine);

                    throw $e;
                }

                if (!\is_string($key) && !\is_int($key)) {
                    throw new ParseException((is_numeric($key) ? 'Numeric' : 'Non-string').' keys are not supported. Quote your evaluable mapping keys instead.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
                }

                
public function testParseInvalidTaggedSequenceShouldThrowException()
    {
        $this->expectException(ParseException::class);
        Inline::parse('!foo { bar: baz } qux', Yaml::PARSE_CUSTOM_TAGS);
    }

    public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
    {
        $value = "'don''t do somthin'' like that'";
        $expect = "don't do somthin' like that";

        $this->assertSame($expect, Inline::parseScalar($value));
    }

    /** * @dataProvider getDataForParseReferences */
    public function testParseReferences($yaml$expected)
    {
        $references = ['var' => 'var-value'];
        $this->assertSame($expected, Inline::parse($yaml, 0, $references));
    }

    
$tag = self::parseTag($value$i$flags);
        switch ($value[$i]) {
            case '[':
                $result = self::parseSequence($value$flags$i$references);
                ++$i;
                break;
            case '{':
                $result = self::parseMapping($value$flags$i$references);
                ++$i;
                break;
            default:
                $result = self::parseScalar($value$flags, null, $i, true, $references);
        }

        // some comments are allowed at the end         if (preg_replace('/\s*#.*$/A', '', substr($value$i))) {
            throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value$i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
        }

        if (null !== $tag && '' !== $tag) {
            return new TaggedValue($tag$result);
        }

        
 {
                if (str_starts_with($values['key'], '!php/const:')) {
                    trigger_deprecation('symfony/yaml', '6.2', 'YAML syntax for key "%s" is deprecated and replaced by "!php/const %s".', $values['key']substr($values['key'], 11));
                }

                if ($context && 'sequence' == $context) {
                    throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
                }
                $context = 'mapping';

                try {
                    $key = Inline::parseScalar($values['key']);
                } catch (ParseException $e) {
                    $e->setParsedLine($this->getRealCurrentLineNb() + 1);
                    $e->setSnippet($this->currentLine);

                    throw $e;
                }

                if (!\is_string($key) && !\is_int($key)) {
                    throw new ParseException((is_numeric($key) ? 'Numeric' : 'Non-string').' keys are not supported. Quote your evaluable mapping keys instead.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
                }

                
$tag = self::parseTag($value$i$flags);
        switch ($value[$i]) {
            case '[':
                $result = self::parseSequence($value$flags$i$references);
                ++$i;
                break;
            case '{':
                $result = self::parseMapping($value$flags$i$references);
                ++$i;
                break;
            default:
                $result = self::parseScalar($value$flags, null, $i, true, $references);
        }

        // some comments are allowed at the end         if (preg_replace('/\s*#.*$/A', '', substr($value$i))) {
            throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value$i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
        }

        if (null !== $tag && '' !== $tag) {
            return new TaggedValue($tag$result);
        }

        
Home | Imprint | This part of the site doesn't use cookies.