move formatting from JS to PHP
[mdref/mdref] / mdref / Structure.php
index dc871d1b960a8f3c00b762b88d27554016c8d8ac..ace780b4d0c62b340be869c124cdefebc3132cda 100644 (file)
@@ -129,7 +129,9 @@ class Structure {
        private function getConstants() : array {
                static $pattern = '/
                        \*\s+
+                       (?:[<]span[ ]class="constant"[>])?
                        (?<name>\w+)
+                       (?:[<]\/span[>])?
                        (?:\s*=\s*(?P<value>.+))?
                        (?P<desc>(?:\s*\n\s*[^\*\n#].*)*)
                /x';
@@ -149,6 +151,7 @@ class Structure {
                static $pattern = '/
                        \*\s+
                        (?P<modifiers>\w+\s+)*
+                       (?:\((?P<usages>(?:(?:\w+)\s*)*)\))*\s*
                        (?P<type>[\\\\\w]+)\s+
                        (?<name>\$\w+)
                        (?:\s*=\s*(?P<defval>.+))?
@@ -208,7 +211,7 @@ class Structure {
                        \s*,?\s*
                        (?P<desc>(?:.|\n(?!\s*\*))*)
                /x';
-               
+
                $returns = $this->splitList($pattern, $this->getSection("Returns"));
                $retvals = [];
                foreach ($returns as list(, $type, $desc)) {
@@ -294,7 +297,7 @@ abstract class StructureOf {
                                return $type;
                                break;
                        default:
-                               return ($type{0} === "\\" ? "":"\\") . $type;
+                               return ($type[0] === "\\" ? "":"\\") . $type;
                                break;
                }
        }
@@ -466,6 +469,7 @@ class StructureOfVar extends StructureOf {
        public $type;
        public $desc;
        public $modifiers;
+       public $usages;
        public $defval;
        public $ref;
 
@@ -475,7 +479,7 @@ class StructureOfVar extends StructureOf {
                                printf(" = ");
                                var_export(constant($this->defval));
                        } else if (strlen($this->defval)) {
-                               if (false !== strchr($this->defval, "\\") && $this->defval{0} != "\\") {
+                               if (false !== strchr($this->defval, "\\") && $this->defval[0] != "\\") {
                                        $this->defval = "\\" . $this->defval;
                                }
                                printf(" = %s", $this->defval);
@@ -489,8 +493,8 @@ class StructureOfVar extends StructureOf {
        function formatAsProp($level) {
                $indent = str_repeat("\t", $level);
                $this->formatDesc($level,
-                       preg_split('/\s+/', $this->modifiers, -1, PREG_SPLIT_NO_EMPTY)
-                       + [-1 => "var " . $this->saneType($this->type)]
+                       preg_split('/\s+/', $this->modifiers ." " . $this->usages, -1, PREG_SPLIT_NO_EMPTY)
+                       + [-1 => "var " . $this->saneType($this->type, false)]
                );
                printf("%s%s %s", $indent, $this->modifiers, $this->name);
                $this->formatDefval();