Lines Matching refs:this

9  * file that was distributed with this source code.
62 $this->filename = $filename;
65 return $this->parse(file_get_contents($filename), $flags);
67 $this->filename = null;
84 throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
87 $this->refs = [];
97 $data = $this->doParse($value, $flags);
102 $this->refsBeingParsed = [];
103 $this->offset = 0;
104 $this->lines = [];
105 $this->currentLine = '';
106 $this->numberOfParsedLines = 0;
107 $this->refs = [];
108 $this->skippedLineNumbers = [];
109 $this->locallySkippedLineNumbers = [];
110 $this->totalNumberOfLines = null;
118 $this->currentLineNb = -1;
119 $this->currentLine = '';
120 $value = $this->cleanup($value);
121 $this->lines = explode("\n", $value);
122 $this->numberOfParsedLines = \count($this->lines);
123 $this->locallySkippedLineNumbers = [];
125 if (null === $this->totalNumberOfLines) {
126 $this->totalNumberOfLines = $this->numberOfParsedLines;
129 if (!$this->moveToNextLine()) {
137 while ($this->isCurrentLineEmpty()) {
138 if (!$this->moveToNextLine()) {
144 if (null !== ($tag = $this->getLineTag($this->currentLine, $flags, false)) && !$this->moveToNextLine()) {
149 if ($this->isCurrentLineEmpty()) {
154 if ("\t" === $this->currentLine[0]) {
155 throw new ParseException('A YAML file cannot contain tabs as indentation.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
158 Inline::initialize($flags, $this->getRealCurrentLineNb(), $this->filename);
161 if ('-' === $this->currentLine[0] && self::preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+))?$#u', rtrim($this->currentLine), $values)) {
163 throw new ParseException('You cannot define a sequence item when in a mapping.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
169 $this->refsBeingParsed[] = $isRef;
174 throw new ParseException('Complex mappings are not supported.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
180 $currentLineNumber = $this->getRealCurrentLineNb();
183 $sequenceYaml = substr($this->currentLine, $sequenceIndentation);
184 $sequenceYaml .= "\n".$this->getNextEmbedBlock($sequenceIndentation, true);
186 $data[] = $this->parseBlock($currentLineNumber, rtrim($sequenceYaml), $flags);
188 $data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags);
189 } elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
192 $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags)
199 || self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
202 // this is a compact notation element, add to next block and parse
204 if ($this->isNextLineIndented()) {
205 $block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + \strlen($values['leadspaces']) + 1);
208 $data[] = $this->parseBlock($this->getRealCurrentLineNb(), $block, $flags);
210 $data[] = $this->parseValue($values['value'], $flags, $context);
214 $this->refs[$isRef] = end($data);
215 array_pop($this->refsBeingParsed);
218 self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
222 throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
229 $e->setParsedLine($this->getRealCurrentLineNb() + 1);
230 $e->setSnippet($this->currentLine);
236 throw new ParseException((is_numeric($key) ? 'Numeric' : 'Non-string').' keys are not supported. Quote your evaluable mapping keys instead.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
249 if (!\array_key_exists($refName, $this->refs)) {
250 if (false !== $pos = array_search($refName, $this->refsBeingParsed, true)) {
251 throw new ParseException(sprintf('Circular reference [%s] detected for reference "%s".', implode(', ', array_merge(\array_slice($this->refsBeingParsed, $pos), [$refName])), $refName), $this->currentLineNb + 1, $this->currentLine, $this->filename);
254 throw new ParseException(sprintf('Reference "%s" does not exist.', $refName), $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
257 $refValue = $this->refs[$refName];
264 throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
272 $value = $this->getNextEmbedBlock();
274 $parsed = $this->parseBlock($this->getRealCurrentLineNb() + 1, $value, $flags);
281 throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
285 // If the value associated with the merge key is a sequence, then this sequence is expected to contain mapping nodes
294 throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem, $this->filename);
307 $this->refsBeingParsed[] = $isRef;
314 } elseif (!isset($values['value']) || '' === $values['value'] || 0 === strpos($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags)) || '<<' === $key) {
317 if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) {
327 throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine);
331 $realCurrentLineNbKey = $this->getRealCurrentLineNb();
332 $value = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(), $flags);
334 $this->refs[$refMatches['ref']] = $value;
350 throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $realCurrentLineNbKey + 1, $this->currentLine);
354 $value = $this->parseValue(rtrim($values['value']), $flags, $context);
360 throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine);
364 $this->refs[$isRef] = $data[$key];
365 array_pop($this->refsBeingParsed);
367 } elseif ('"' === $this->currentLine[0] || "'" === $this->currentLine[0]) {
369 throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
373 return Inline::parse($this->lexInlineQuotedString(), $flags, $this->refs);
375 $e->setParsedLine($this->getRealCurrentLineNb() + 1);
376 $e->setSnippet($this->currentLine);
380 } elseif ('{' === $this->currentLine[0]) {
382 throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
386 $parsedMapping = Inline::parse($this->lexInlineMapping(), $flags, $this->refs);
388 while ($this->moveToNextLine()) {
389 if (!$this->isCurrentLineEmpty()) {
390 throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
396 $e->setParsedLine($this->getRealCurrentLineNb() + 1);
397 $e->setSnippet($this->currentLine);
401 } elseif ('[' === $this->currentLine[0]) {
403 throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
407 $parsedSequence = Inline::parse($this->lexInlineSequence(), $flags, $this->refs);
409 while ($this->moveToNextLine()) {
410 if (!$this->isCurrentLineEmpty()) {
411 throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
417 $e->setParsedLine($this->getRealCurrentLineNb() + 1);
418 $e->setSnippet($this->currentLine);
424 if ('---' === $this->currentLine) {
425 throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
428 if ($deprecatedUsage = (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1])) {
429 throw new ParseException('Complex mappings are not supported.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
433 if (\is_string($value) && $this->lines[0] === trim($value)) {
435 $value = Inline::parse($this->lines[0], $flags, $this->refs);
437 $e->setParsedLine($this->getRealCurrentLineNb() + 1);
438 $e->setSnippet($this->currentLine);
447 if (0 === $this->currentLineNb) {
452 foreach ($this->lines as $line) {
458 if (0 === $this->offset && !$deprecatedUsage && isset($line[0]) && ' ' === $line[0]) {
459 throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
463 throw new ParseException('Mapping values are not allowed in multi-line blocks.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
497 throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
499 } while ($this->moveToNextLine());
520 $skippedLineNumbers = $this->skippedLineNumbers;
522 foreach ($this->locallySkippedLineNumbers as $lineNumber) {
532 $parser->totalNumberOfLines = $this->totalNumberOfLines;
534 $parser->refs = &$this->refs;
535 $parser->refsBeingParsed = $this->refsBeingParsed;
547 $realCurrentLineNumber = $this->currentLineNb + $this->offset;
549 foreach ($this->skippedLineNumbers as $skippedLineNumber) {
565 if (' ' !== ($this->currentLine[0] ?? '')) {
569 return \strlen($this->currentLine) - \strlen(ltrim($this->currentLine, ' '));
582 $oldLineIndentation = $this->getCurrentLineIndentation();
584 if (!$this->moveToNextLine()) {
596 if ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
597 $EOF = !$this->moveToNextLine();
603 $newIndent = $this->getCurrentLineIndentation();
608 $this->moveToPreviousLine();
611 $unindentedEmbedBlock = $this->isStringUnIndentedCollectionItem();
613 if (!$this->isCurrentLineEmpty() && 0 === $newIndent && !$unindentedEmbedBlock) {
614 throw new ParseException('Indentation problem.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
622 if ($this->getCurrentLineIndentation() >= $newIndent) {
623 $data[] = substr($this->currentLine, $newIndent ?? 0);
624 } elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
625 $data[] = $this->currentLine;
627 $this->moveToPreviousLine();
633 // the previous line contained a dash but no item content, this line is a sequence item with the same indentation
635 $this->moveToPreviousLine();
640 $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
641 $isItComment = $this->isCurrentLineComment();
643 while ($this->moveToNextLine()) {
645 $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
646 $isItComment = $this->isCurrentLineComment();
649 $indent = $this->getCurrentLineIndentation();
651 if ($isItUnindentedCollection && !$this->isCurrentLineEmpty() && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) {
652 $this->moveToPreviousLine();
656 if ($this->isCurrentLineBlank()) {
657 $data[] = substr($this->currentLine, $newIndent);
662 $data[] = substr($this->currentLine, $newIndent);
663 } elseif ($this->isCurrentLineComment()) {
664 $data[] = $this->currentLine;
666 $this->moveToPreviousLine();
670 throw new ParseException('Indentation problem.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
679 return (\count($this->lines) - 1) > $this->currentLineNb;
687 if ($this->currentLineNb >= $this->numberOfParsedLines - 1) {
691 $this->currentLine = $this->lines[++$this->currentLineNb];
701 if ($this->currentLineNb < 1) {
705 $this->currentLine = $this->lines[--$this->currentLineNb];
730 if (!\array_key_exists($value, $this->refs)) {
731 if (false !== $pos = array_search($value, $this->refsBeingParsed, true)) {
732 throw new ParseException(sprintf('Circular reference [%s] detected for reference "%s".', implode(', ', array_merge(\array_slice($this->refsBeingParsed, $pos), [$value])), $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
735 throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
738 return $this->refs[$value];
744 $data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), abs((int) $modifiers));
759 $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
761 return Inline::parse($this->lexInlineMapping($cursor), $flags, $this->refs);
763 $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
765 return Inline::parse($this->lexInlineSequence($cursor), $flags, $this->refs);
771 $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
772 $parsedValue = Inline::parse($this->lexInlineQuotedString($cursor), $flags, $this->refs);
774 if (isset($this->currentLine[$cursor]) && preg_replace('/\s*(#.*)?$/A', '', substr($this->currentLine, $cursor))) {
775 throw new ParseException(sprintf('Unexpected characters near "%s".', substr($this->currentLine, $cursor)));
782 while ($this->moveToNextLine()) {
784 if (0 === $this->getCurrentLineIndentation()) {
785 $this->moveToPreviousLine();
790 $lines[] = trim($this->currentLine);
806 Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
808 $parsedValue = Inline::parse($value, $flags, $this->refs);
811 throw new ParseException('A colon cannot be used in an unquoted mapping value.', $this->getRealCurrentLineNb() + 1, $value, $this->filename);
817 $e->setParsedLine($this->getRealCurrentLineNb() + 1);
818 $e->setSnippet($this->currentLine);
827 * @param string $style The style indicator that was used to begin this block scalar (| or >)
828 * @param string $chomping The chomping indicator that was used to begin this block scalar (+ or -)
829 * @param int $indentation The indentation indicator that was used to begin this block scalar
833 $notEOF = $this->moveToNextLine();
838 $isCurrentLineBlank = $this->isCurrentLineBlank();
844 if ($notEOF = $this->moveToNextLine()) {
846 $isCurrentLineBlank = $this->isCurrentLineBlank();
852 $currentLineLength = \strlen($this->currentLine);
854 for ($i = 0; $i < $currentLineLength && ' ' === $this->currentLine[$i]; ++$i) {
865 self::preg_match($pattern, $this->currentLine, $matches)
868 if ($isCurrentLineBlank && \strlen($this->currentLine) > $indentation) {
869 $blockLines[] = substr($this->currentLine, $indentation);
877 if ($notEOF = $this->moveToNextLine()) {
878 $isCurrentLineBlank = $this->isCurrentLineBlank();
887 $this->moveToPreviousLine();
888 } elseif (!$notEOF && !$this->isCurrentLineLastLineInDocument()) {
940 $currentIndentation = $this->getCurrentLineIndentation();
944 $EOF = !$this->moveToNextLine();
949 } while (!$EOF && ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()));
955 $ret = $this->getCurrentLineIndentation() > $currentIndentation;
958 $this->moveToPreviousLine();
969 return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
977 return '' === $this->currentLine || '' === trim($this->currentLine, ' ');
986 $ltrimmedLine = '' !== $this->currentLine && ' ' === $this->currentLine[0] ? ltrim($this->currentLine, ' ') : $this->currentLine;
993 return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1);
1008 $this->offset += $count;
1014 $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
1022 $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
1037 $currentIndentation = $this->getCurrentLineIndentation();
1041 $EOF = !$this->moveToNextLine();
1046 } while (!$EOF && ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()));
1052 $ret = $this->getCurrentLineIndentation() === $currentIndentation && $this->isStringUnIndentedCollectionItem();
1055 $this->moveToPreviousLine();
1066 return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
1132 if ($nextLineCheck && !$this->isNextLineIndented()) {
1140 throw new ParseException(sprintf('The built-in tag "!%s" is not implemented.', $tag), $this->getRealCurrentLineNb() + 1, $value, $this->filename);
1147 throw new ParseException(sprintf('Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "%s".', $matches['tag']), $this->getRealCurrentLineNb() + 1, $value, $this->filename);
1152 $quotation = $this->currentLine[$cursor];
1162 $cursor += strspn($this->currentLine, ' ', $cursor);
1165 if ($this->isCurrentLineBlank()) {
1171 for (; \strlen($this->currentLine) > $cursor; ++$cursor) {
1172 switch ($this->currentLine[$cursor]) {
1176 } elseif (isset($this->currentLine[++$cursor])) {
1177 $value .= '\\'.$this->currentLine[$cursor];
1184 if ("'" === $quotation && isset($this->currentLine[$cursor]) && "'" === $this->currentLine[$cursor]) {
1191 $value .= $this->currentLine[$cursor];
1195 if ($this->isCurrentLineBlank()) {
1198 } elseif ('\\' === $this->currentLine[-1]) {
1206 if ($this->hasMoreLines()) {
1209 } while ($this->moveToNextLine());
1217 $cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
1223 return substr($this->currentLine, $offset, $cursor - $offset);
1228 return $this->lexInlineStructure($cursor, '}');
1233 return $this->lexInlineStructure($cursor, ']');
1238 $value = $this->currentLine[$cursor];
1242 $this->consumeWhitespaces($cursor);
1244 while (isset($this->currentLine[$cursor])) {
1245 switch ($this->currentLine[$cursor]) {
1248 $value .= $this->lexInlineQuotedString($cursor);
1252 $value .= $this->currentLine[$cursor];
1256 $value .= $this->lexInlineMapping($cursor);
1259 $value .= $this->lexInlineSequence($cursor);
1262 $value .= $this->currentLine[$cursor];
1269 $value .= $this->lexUnquotedString($cursor);
1272 if ($this->consumeWhitespaces($cursor)) {
1277 if ($this->hasMoreLines()) {
1280 } while ($this->moveToNextLine());
1290 $whitespaceOnlyTokenLength = strspn($this->currentLine, ' ', $cursor);
1294 if (isset($this->currentLine[$cursor])) {
1298 if ($this->hasMoreLines()) {
1301 } while ($this->moveToNextLine());