[Sungrazr-svn] [112] Sungrazr_Docs_Phpdoc: [CHG] Simplified regex.

0 views
Skip to first unread message

cl...@killersoft.com

unread,
Feb 9, 2008, 10:59:50 PM2/9/08
to Sungra...@googlegroups.com
Revision
112
Author
clay
Date
2008-02-09 19:59:49 -0800 (Sat, 09 Feb 2008)

Log Message

Sungrazr_Docs_Phpdoc: [CHG] Simplified regex. Added support for (gasp) a subsubparam. Paul will hate this.

Modified Paths

Diff

Modified: trunk/Sungrazr/Docs/Phpdoc.php (111 => 112)


--- trunk/Sungrazr/Docs/Phpdoc.php	2008-02-10 03:27:27 UTC (rev 111)
+++ trunk/Sungrazr/Docs/Phpdoc.php	2008-02-10 03:59:49 UTC (rev 112)
@@ -49,17 +49,26 @@
      *  $param::static
      *  $param[key]
      * 
+     * A second level of sub-parameters is supported as well, such as:
+     *  
+     *  $param->property[key]
+     * 
+     * If the first word of the summary is "required", a required = true 
+     * element will be added to the $info for this sub-param.
+     * 
      * Intended to document expected keys/properties of parameters.
      * 
      * @param string $line The block line.
      * 
      * @return void
      * 
+     * @todo Consider re-factoring to support deeper levels than subsubparam     
+     * 
      */
     public function parseSubparam($line)
     {
         // string|array $param->varname Summary or description.
-        preg_match('/(\S+)?(?:(?:\s+\&?\$)(\S+)((?:[^a-z]+)\S+))?((\s+)(.*))?/', $line, $matches);
+        preg_match('/(\S+)?(?:\s+\&?\$)(\S+)(.*)?/', $line, $matches);
 
         if (! $matches) {
             return;
@@ -68,6 +77,7 @@
         // split subparam
         $param = null;
         $subparam = null;
+        $subsubparam = null;
         if (strpos($matches[2], '::') !== false) {
             $tmp = explode('::', $matches[2]);
         } elseif (strpos($matches[2], '->') !== false) {
@@ -77,7 +87,20 @@
             $tmp[1] = str_replace(']', '', $tmp[1]);
         }
         $param = @$tmp[0];
-        $subparam = @$tmp[1];        
+        $subparam = @$tmp[1];
+        
+        // sub-sub-param?
+        $tmp2 = array();
+        if (strpos($subparam, '->') !== false) {
+            $tmp2 = explode('->', $subparam);
+        } elseif (strpos($subparam, '[') !== false) {
+            $tmp2 = explode('[', $subparam);
+            $tmp2[1] = str_replace(']', '', $tmp2[1]);
+        }
+        if (! empty($tmp2)) {
+            $subparam = $tmp2[0];
+            $subsubparam = $tmp2[1];
+        }
 
 
         if (empty($param)) {
@@ -88,23 +111,32 @@
         if (empty($this->_info['param'][$param])) {
             return;
         }
-        
-        // do we have a subparams array?
-        if (empty($this->_info['subparam'])) {
-            $this->_info['subparam'][$param] = array();
-        }
-                
+                        
         // variable type
         $type = $matches[1];
                 
         // always need a summary element
         $summ = trim($matches[3]);
         
-        // save the param
-        $this->_info['subparam'][$param][$subparam] = array(
-            'type' => $type,
-            'summ' => $summ,
-        );
+        // sub-param info
+        $info = array();
+        $info['type'] = $type;
+        $info['summ'] = $summ;
+        
+        // is this sub parameter required?
+        if (substr($summ, 0, 8) == 'required') {
+            $info['required'] = true;
+            $info['summ'] = substr($summ, 9);
+        }
+        
+        if (! empty($subsubparam)) {
+            $info['name'] = $subsubparam;
+            $this->_info['param'][$param]['param'][$subparam]['param'][] = $info;
+        } else {
+            $this->_info['param'][$param]['param'][$subparam] = $info;
+        }
+        
     }
     
+    
 }
\ No newline at end of file
Reply all
Reply to author
Forward
0 new messages