Author: fabien
Date: 2010-03-24 14:55:40 +0100 (Wed, 24 Mar 2010)
New Revision: 28761

Added:
   components/yaml/trunk/test/fixtures/sfCompact.yml
Modified:
   components/yaml/trunk/lib/sfYamlParser.php
   components/yaml/trunk/test/fixtures/index.yml
   components/yaml/trunk/test/sfYamlDumperTest.php
   components/yaml/trunk/test/sfYamlParserTest.php
Log:
[YAML] added support for compact inline notation with immediate sub mapping 
(refs #8082)

Modified: components/yaml/trunk/lib/sfYamlParser.php
===================================================================
--- components/yaml/trunk/lib/sfYamlParser.php  2010-03-24 13:31:51 UTC (rev 
28760)
+++ components/yaml/trunk/lib/sfYamlParser.php  2010-03-24 13:55:40 UTC (rev 
28761)
@@ -90,11 +90,7 @@
         }
         else
         {
-          if (preg_match('/^([^ ]+)\: +({.*?)$/', $values['value'], $matches))
-          {
-            $data[] = array($matches[1] => sfYamlInline::load($matches[2]));
-          }
-          elseif (isset($values['leadspaces'])
+          if (isset($values['leadspaces'])
             && ' ' == $values['leadspaces']
             && preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ 
\'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches))
           {
@@ -106,7 +102,7 @@
             $block = $values['value'];
             if (!$this->isNextLineIndented())
             {
-              $block .= "\n".$this->getNextEmbedBlock();
+              $block .= 
"\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
             }
 
             $data[] = $parser->parse($block);
@@ -290,17 +286,26 @@
   /**
    * 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
    */
-  protected function getNextEmbedBlock()
+  protected function getNextEmbedBlock($indentation = null)
   {
     $this->moveToNextLine();
 
-    $newIndent = $this->getCurrentLineIndentation();
+    if (null === $indentation)
+    {
+      $newIndent = $this->getCurrentLineIndentation();
 
-    if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
+      if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
+      {
+        throw new InvalidArgumentException(sprintf('Indentation problem at 
line %d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
+      }
+    }
+    else
     {
-      throw new InvalidArgumentException(sprintf('Indentation problem at line 
%d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
+      $newIndent = $indentation;
     }
 
     $data = array(substr($this->currentLine, $newIndent));

Modified: components/yaml/trunk/test/fixtures/index.yml
===================================================================
--- components/yaml/trunk/test/fixtures/index.yml       2010-03-24 13:31:51 UTC 
(rev 28760)
+++ components/yaml/trunk/test/fixtures/index.yml       2010-03-24 13:55:40 UTC 
(rev 28761)
@@ -1,4 +1,5 @@
 - sfComments
+- sfCompact
 - sfTests
 - sfObjects
 - sfMergeKey

Added: components/yaml/trunk/test/fixtures/sfCompact.yml
===================================================================
--- components/yaml/trunk/test/fixtures/sfCompact.yml                           
(rev 0)
+++ components/yaml/trunk/test/fixtures/sfCompact.yml   2010-03-24 13:55:40 UTC 
(rev 28761)
@@ -0,0 +1,53 @@
+--- %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'
+      )
+    )
+  )

Modified: components/yaml/trunk/test/sfYamlDumperTest.php
===================================================================
--- components/yaml/trunk/test/sfYamlDumperTest.php     2010-03-24 13:31:51 UTC 
(rev 28760)
+++ components/yaml/trunk/test/sfYamlDumperTest.php     2010-03-24 13:55:40 UTC 
(rev 28761)
@@ -15,7 +15,7 @@
 
 sfYaml::setSpecVersion('1.1');
 
-$t = new lime_test(150);
+$t = new lime_test(152);
 
 $parser = new sfYamlParser();
 $dumper = new sfYamlDumper();

Modified: components/yaml/trunk/test/sfYamlParserTest.php
===================================================================
--- components/yaml/trunk/test/sfYamlParserTest.php     2010-03-24 13:31:51 UTC 
(rev 28760)
+++ components/yaml/trunk/test/sfYamlParserTest.php     2010-03-24 13:55:40 UTC 
(rev 28761)
@@ -14,7 +14,7 @@
 
 sfYaml::setSpecVersion('1.1');
 
-$t = new lime_test(150);
+$t = new lime_test(152);
 
 $parser = new sfYamlParser();
 

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to