8000 Merge pull request #1 from xabbuh/pr-40503 · symfony/symfony@eb0df02 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb0df02

Browse files
authored
Merge pull request #1 from xabbuh/pr-40503
simplify the patch
2 parents 590c94f + 5be10c7 commit eb0df02

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ private function doParse(string $value, int $flags)
171171
// array
172172
if (isset($values['value']) && 0 === strpos(ltrim($values['value'], ' '), '-')) {
173173
// Inline first child
174-
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(2, true, true) ?? '', $flags);
174+
$currentLineNumber = $this->getRealCurrentLineNb();
175+
176+
$sequenceIndentation = strlen($values['leadspaces']) + 1;
177+
$sequenceYaml = substr($this->currentLine, $sequenceIndentation);
178+
$sequenceYaml .= "\n".$this->getNextEmbedBlock($sequenceIndentation, true);
179+
180+
$data[] = $this->parseBlock($currentLineNumber, rtrim($sequenceYaml), $flags);
175181
} elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
176182
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags);
177183
} elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
@@ -559,19 +565,18 @@ private function getCurrentLineIndentation(): int
559565
/**
560566
* Returns the next embed block of YAML.
561567
*
562-
* @param int|null $indentation The indent level at which the block is to be read, or null for default
563-
* @param bool $inSequence True if the enclosing data structure is a sequence
564-
* @param bool $isInlineFirstChild True if the definition has an inline first element
568+
* @param int|null $indentation The indent level at which the block is to be read, or null for default
569+
* @param bool $inSequence True if the enclosing data structure is a sequence
565570
*
566571
* @return string A YAML string
567572
*
568573
* @throws ParseException When indentation problem are detected
569574
*/
570-
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false, bool $isInlineFirstChild = false): string
575+
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false): string
571576
{
572577
$oldLineIndentation = $this->getCurrentLineIndentation();
573578

574-
if (!$isInlineFirstChild && !$this->moveToNextLine()) {
579+
if (!$this->moveToNextLine()) {
575580
return '';
576581
}
577582

@@ -609,7 +614,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f
609614

610615
$data = [];
611616

612-
if ($isInlineFirstChild || $this->getCurrentLineIndentation() >= $newIndent) {
617+
if ($this->getCurrentLineIndentation() >= $newIndent) {
613618
$data[] = substr($this->currentLine, $newIndent);
614619
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
615620
$data[] = $this->currentLine;
@@ -619,7 +624,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f
619624
return '';
620625
}
621626

622-
if (!$isInlineFirstChild && $inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
627+
if ($inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
623628
// the previous line contained a dash but no item content, this line is a sequence item with the same indentation
624629
// and therefore no nested list or mapping
625630
$this->moveToPreviousLine();
@@ -638,7 +643,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f
638643

639644
$indent = $this->getCurrentLineIndentation();
640645

641-
if (!$isInlineFirstChild && $isItUnindentedCollection && !$this->isCurrentLineEmpty() && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) {
646+
if ($isItUnindentedCollection && !$this->isCurrentLineEmpty() && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) {
642647
$this->moveToPreviousLine();
643648
break;
644649
}

0 commit comments

Comments
 (0)
0