Skip to content

Commit

Permalink
[Yaml] added support for compact notation (patch from redotheoffice - c…
Browse files Browse the repository at this point in the history
…loses #8082)
  • Loading branch information
fabpot committed Feb 23, 2010
1 parent 8302376 commit a80a61b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/Symfony/Components/Yaml/Parser.php
Expand Up @@ -65,7 +65,7 @@ public function parse($value)
}

$isRef = $isInPlace = $isProcessed = false;
if (preg_match('#^\-(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#', $this->currentLine, $values))
{
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#', $values['value'], $matches))
{
Expand All @@ -87,13 +87,30 @@ public function parse($value)
{
$data[] = array($matches[1] => Inline::load($matches[2]));
}
elseif (isset($values['leadspaces'])
&& ' ' == $values['leadspaces']
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches))
{
// this is a compact notation element, add to next block and parse
$c = $this->getRealCurrentLineNb();
$parser = new Parser($c);
$parser->refs =& $this->refs;

$block = $values['value'];
if (!$this->isNextLineIndented())
{
$block .= "\n".$this->getNextEmbedBlock();
}

$data[] = $parser->parse($block);
}
else
{
$data[] = $this->parseValue($values['value']);
}
}
}
else if (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ ].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
else if (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
{
$key = Inline::parseScalar($values['key']);

Expand Down
Expand Up @@ -149,7 +149,7 @@ yaml: |
hr: 63,
avg: 0.288
}
ruby: |
php: |
array(
'Mark McGwire' =>
array( 'hr' => 65, 'avg' => 0.278 ),
Expand Down Expand Up @@ -286,7 +286,6 @@ syck: |
---
test: Sequence key shortcut
todo: true
spec: 2.12
yaml: |
---
Expand All @@ -297,6 +296,21 @@ yaml: |
quantity: 4
- item : Big Shoes
quantity: 1
php: |
array (
array (
'item' => 'Super Hoop',
'quantity' => 1,
),
array (
'item' => 'Basketball',
'quantity' => 4,
),
array (
'item' => 'Big Shoes',
'quantity' => 1,
)
)
perl: |
[
{ item => 'Super Hoop', quantity => 1 },
Expand Down

0 comments on commit a80a61b

Please sign in to comment.