Ejemplo n.º 1
0
 public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
 {
     $this->expectException("Scabbia\\Yaml\\ParseException");
     Inline::parse('{ foo: |foo }');
     $this->expectException("Scabbia\\Yaml\\ParseException");
     Inline::parse('{ foo: >foo }');
 }
Ejemplo n.º 2
0
 /**
  * Parses a YAML value
  *
  * @param string  $value                  A YAML value
  * @param string $context                 The parser context (either sequence or mapping)
  *
  * @throws ParseException When reference does not exist
  * @return mixed  A PHP value
  */
 protected function parseValue($value, $context)
 {
     if (strpos($value, "*") === 0) {
         if (($pos = strpos($value, "#")) !== false) {
             $value = substr($value, 1, $pos - 2);
         } else {
             $value = substr($value, 1);
         }
         if (!array_key_exists($value, $this->refs)) {
             throw new ParseException(sprintf("Reference \"%s\" does not exist.", $value), $this->currentLine);
         }
         return $this->refs[$value];
     }
     if (preg_match("/^" . self::BLOCK_SCALAR_HEADER_PATTERN . "\$/", $value, $matches)) {
         $modifiers = isset($matches["modifiers"]) ? $matches["modifiers"] : "";
         return $this->parseBlockScalar($matches["separator"], preg_replace("#\\d+#", "", $modifiers), (int) abs($modifiers));
     }
     try {
         $parsedValue = Inline::parse($value, $this->refs);
         if ($context === "mapping" && $value[0] !== "\"" && $value[0] !== "'" && $value[0] !== "[" && $value[0] !== "{" && $value[0] !== "!" && strpos($parsedValue, ": ") !== false) {
             throw new ParseException("A colon cannot be used in an unquoted mapping value.");
         }
         return $parsedValue;
     } catch (ParseException $e) {
         $e->setParsedLine($this->getRealCurrentLineNb() + 1);
         $e->setSnippet($this->currentLine);
         throw $e;
     }
 }