Author: fabien
Date: 2010-02-23 12:03:51 +0100 (Tue, 23 Feb 2010)
New Revision: 28206

Modified:
   components/yaml/trunk/lib/sfYamlParser.php
   components/yaml/trunk/test/fixtures/YtsSpecificationExamples.yml
Log:
[YAML] added support for compact notation (patch from redotheoffice - closes 
#8082)

Modified: components/yaml/trunk/lib/sfYamlParser.php
===================================================================
--- components/yaml/trunk/lib/sfYamlParser.php  2010-02-23 10:54:48 UTC (rev 
28205)
+++ components/yaml/trunk/lib/sfYamlParser.php  2010-02-23 11:03:51 UTC (rev 
28206)
@@ -72,7 +72,7 @@
       }
 
       $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))
         {
@@ -94,13 +94,30 @@
           {
             $data[] = array($matches[1] => sfYamlInline::load($matches[2]));
           }
+          elseif (isset($values['leadspaces'])
+            && ' ' == $values['leadspaces']
+            && preg_match('#^(?P<key>'.sfYamlInline::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 sfYamlParser($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>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ 
].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
+      else if (preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ 
\'"].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
       {
         $key = sfYamlInline::parseScalar($values['key']);
 

Modified: components/yaml/trunk/test/fixtures/YtsSpecificationExamples.yml
===================================================================
--- components/yaml/trunk/test/fixtures/YtsSpecificationExamples.yml    
2010-02-23 10:54:48 UTC (rev 28205)
+++ components/yaml/trunk/test/fixtures/YtsSpecificationExamples.yml    
2010-02-23 11:03:51 UTC (rev 28206)
@@ -149,7 +149,7 @@
       hr: 63,
       avg: 0.288
     }
-ruby: | 
+php: | 
   array(  
     'Mark McGwire' => 
       array( 'hr' => 65, 'avg' => 0.278 ), 
@@ -286,7 +286,6 @@
  
 --- 
 test: Sequence key shortcut 
-todo: true
 spec: 2.12
 yaml: | 
   ---
@@ -297,6 +296,21 @@
     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 }, 

-- 
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