[Yaml] added support for compact inline notation with immediate sub mapping
This commit is contained in:
parent
a248fc133b
commit
bc9bbd8436
@ -83,11 +83,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (preg_match('/^([^ ]+)\: +({.*?)$/', $values['value'], $matches))
|
if (isset($values['leadspaces'])
|
||||||
{
|
|
||||||
$data[] = array($matches[1] => Inline::load($matches[2]));
|
|
||||||
}
|
|
||||||
elseif (isset($values['leadspaces'])
|
|
||||||
&& ' ' == $values['leadspaces']
|
&& ' ' == $values['leadspaces']
|
||||||
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches))
|
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches))
|
||||||
{
|
{
|
||||||
@ -99,7 +95,7 @@ class Parser
|
|||||||
$block = $values['value'];
|
$block = $values['value'];
|
||||||
if (!$this->isNextLineIndented())
|
if (!$this->isNextLineIndented())
|
||||||
{
|
{
|
||||||
$block .= "\n".$this->getNextEmbedBlock();
|
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data[] = $parser->parse($block);
|
$data[] = $parser->parse($block);
|
||||||
@ -283,18 +279,27 @@ class Parser
|
|||||||
/**
|
/**
|
||||||
* Returns the next embed block of YAML.
|
* Returns the next embed block of YAML.
|
||||||
*
|
*
|
||||||
|
* @param integer $indentation The indent level at which the block is to be read, or null for default
|
||||||
|
*
|
||||||
* @return string A YAML string
|
* @return string A YAML string
|
||||||
*/
|
*/
|
||||||
protected function getNextEmbedBlock()
|
protected function getNextEmbedBlock($indentation = null)
|
||||||
{
|
{
|
||||||
$this->moveToNextLine();
|
$this->moveToNextLine();
|
||||||
|
|
||||||
|
if (null === $indentation)
|
||||||
|
{
|
||||||
$newIndent = $this->getCurrentLineIndentation();
|
$newIndent = $this->getCurrentLineIndentation();
|
||||||
|
|
||||||
if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
|
if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
|
||||||
{
|
{
|
||||||
throw new ParserException(sprintf('Indentation problem at line %d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
throw new ParserException(sprintf('Indentation problem at line %d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$newIndent = $indentation;
|
||||||
|
}
|
||||||
|
|
||||||
$data = array(substr($this->currentLine, $newIndent));
|
$data = array(substr($this->currentLine, $newIndent));
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
- sfComments
|
- sfComments
|
||||||
|
- sfCompact
|
||||||
- sfTests
|
- sfTests
|
||||||
- sfObjects
|
- sfObjects
|
||||||
- sfMergeKey
|
- sfMergeKey
|
||||||
|
159
tests/fixtures/Symfony/Components/Yaml/sfCompact.yml
vendored
Normal file
159
tests/fixtures/Symfony/Components/Yaml/sfCompact.yml
vendored
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
--- %YAML:1.0
|
||||||
|
test: Compact notation
|
||||||
|
brief: |
|
||||||
|
Compact notation for sets of mappings with single element
|
||||||
|
yaml: |
|
||||||
|
---
|
||||||
|
# products purchased
|
||||||
|
- item : Super Hoop
|
||||||
|
- item : Basketball
|
||||||
|
quantity: 1
|
||||||
|
- item:
|
||||||
|
name: Big Shoes
|
||||||
|
nick: Biggies
|
||||||
|
quantity: 1
|
||||||
|
php: |
|
||||||
|
array (
|
||||||
|
array (
|
||||||
|
'item' => 'Super Hoop',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'item' => 'Basketball',
|
||||||
|
'quantity' => 1,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'item' => array(
|
||||||
|
'name' => 'Big Shoes',
|
||||||
|
'nick' => 'Biggies'
|
||||||
|
),
|
||||||
|
'quantity' => 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
---
|
||||||
|
test: Compact notation combined with inline notation
|
||||||
|
brief: |
|
||||||
|
Combinations of compact and inline notation are allowed
|
||||||
|
yaml: |
|
||||||
|
---
|
||||||
|
items:
|
||||||
|
- { item: Super Hoop, quantity: 1 }
|
||||||
|
- [ Basketball, Big Shoes ]
|
||||||
|
php: |
|
||||||
|
array (
|
||||||
|
'items' => array (
|
||||||
|
array (
|
||||||
|
'item' => 'Super Hoop',
|
||||||
|
'quantity' => 1,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'Basketball',
|
||||||
|
'Big Shoes'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
--- %YAML:1.0
|
||||||
|
test: Compact notation
|
||||||
|
brief: |
|
||||||
|
Compact notation for sets of mappings with single element
|
||||||
|
yaml: |
|
||||||
|
---
|
||||||
|
# products purchased
|
||||||
|
- item : Super Hoop
|
||||||
|
- item : Basketball
|
||||||
|
quantity: 1
|
||||||
|
- item:
|
||||||
|
name: Big Shoes
|
||||||
|
nick: Biggies
|
||||||
|
quantity: 1
|
||||||
|
php: |
|
||||||
|
array (
|
||||||
|
array (
|
||||||
|
'item' => 'Super Hoop',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'item' => 'Basketball',
|
||||||
|
'quantity' => 1,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'item' => array(
|
||||||
|
'name' => 'Big Shoes',
|
||||||
|
'nick' => 'Biggies'
|
||||||
|
),
|
||||||
|
'quantity' => 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
---
|
||||||
|
test: Compact notation combined with inline notation
|
||||||
|
brief: |
|
||||||
|
Combinations of compact and inline notation are allowed
|
||||||
|
yaml: |
|
||||||
|
---
|
||||||
|
items:
|
||||||
|
- { item: Super Hoop, quantity: 1 }
|
||||||
|
- [ Basketball, Big Shoes ]
|
||||||
|
php: |
|
||||||
|
array (
|
||||||
|
'items' => array (
|
||||||
|
array (
|
||||||
|
'item' => 'Super Hoop',
|
||||||
|
'quantity' => 1,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'Basketball',
|
||||||
|
'Big Shoes'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
--- %YAML:1.0
|
||||||
|
test: Compact notation
|
||||||
|
brief: |
|
||||||
|
Compact notation for sets of mappings with single element
|
||||||
|
yaml: |
|
||||||
|
---
|
||||||
|
# products purchased
|
||||||
|
- item : Super Hoop
|
||||||
|
- item : Basketball
|
||||||
|
quantity: 1
|
||||||
|
- item:
|
||||||
|
name: Big Shoes
|
||||||
|
nick: Biggies
|
||||||
|
quantity: 1
|
||||||
|
php: |
|
||||||
|
array (
|
||||||
|
array (
|
||||||
|
'item' => 'Super Hoop',
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'item' => 'Basketball',
|
||||||
|
'quantity' => 1,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'item' => array(
|
||||||
|
'name' => 'Big Shoes',
|
||||||
|
'nick' => 'Biggies'
|
||||||
|
),
|
||||||
|
'quantity' => 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
---
|
||||||
|
test: Compact notation combined with inline notation
|
||||||
|
brief: |
|
||||||
|
Combinations of compact and inline notation are allowed
|
||||||
|
yaml: |
|
||||||
|
---
|
||||||
|
items:
|
||||||
|
- { item: Super Hoop, quantity: 1 }
|
||||||
|
- [ Basketball, Big Shoes ]
|
||||||
|
php: |
|
||||||
|
array (
|
||||||
|
'items' => array (
|
||||||
|
array (
|
||||||
|
'item' => 'Super Hoop',
|
||||||
|
'quantity' => 1,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'Basketball',
|
||||||
|
'Big Shoes'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
Reference in New Issue
Block a user