W3C home > Mailing lists > Public > public-dap-commits@w3.org > December 2009

2009/dap/ReSpec.js/js respec.js,1.58,1.59

From: Robin Berjon via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 03 Dec 2009 12:21:54 +0000
To: public-dap-commits@w3.org
Message-Id: <E1NGAh0-0005BX-O5@lionel-hutz.w3.org>
Update of /sources/public/2009/dap/ReSpec.js/js
In directory hutz:/tmp/cvs-serv19897/js

Modified Files:
	respec.js 
Log Message:
support for IDL arrays

Index: respec.js
===================================================================
RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- respec.js	3 Dec 2009 11:56:08 -0000	1.58
+++ respec.js	3 Dec 2009 12:21:52 -0000	1.59
@@ -861,6 +861,11 @@
                 type = type.replace(/\?$/, "");
                 tdf.nullable = true;
             }
+            tdf.array = false;
+            if (/\[\]$/.test(type)) {
+                type = type.replace(/\[\]$/, "");
+                tdf.array = true;
+            }
             tdf.datatype = type;
             tdf.id = match[2];
             tdf.description = sn.documentFragment();
@@ -928,6 +933,11 @@
                 type = type.replace(/\?$/, "");
                 mem.nullable = true;
             }
+            mem.array = false;
+            if (/\[\]$/.test(type)) {
+                type = type.replace(/\[\]$/, "");
+                mem.array = true;
+            }
             mem.datatype = type;
             mem.id = match[3];
             mem.raises = [];
@@ -993,6 +1003,11 @@
                 type = type.replace(/\?$/, "");
                 mem.nullable = true;
             }
+            mem.array = false;
+            if (/\[\]$/.test(type)) {
+                type = type.replace(/\[\]$/, "");
+                mem.array = true;
+            }
             mem.datatype = type;
             mem.id = match[2];
             mem.params = [];
@@ -1045,6 +1060,11 @@
                             type = type.replace(/\?$/, "");
                             p.nullable = true;
                         }
+                        p.array = false;
+                        if (/\[\]$/.test(type)) {
+                            type = type.replace(/\[\]$/, "");
+                            p.array = true;
+                        }
                         p.datatype = type;
                         p.id = match[2];
                         p.description = sn.documentFragment();
@@ -1072,6 +1092,11 @@
                             type = type.replace(/\?$/, "");
                             p.nullable = true;
                         }
+                        p.array = false;
+                        if (/\[\]$/.test(type)) {
+                            type = type.replace(/\[\]$/, "");
+                            p.array = true;
+                        }
                         p.datatype = type;
                         p.id = match[2];
                         mem.params.push(p);
@@ -1140,6 +1165,7 @@
                 cnt = [ sn.text("Throughout this specification, the identifier "),
                         sn.element("span", { "class": "idlTypedefID" }, null, obj.id),
                         sn.text(" is used to refer to the "),
+                        sn.text(obj.array ? "array of " : ""),
                         tdt,
                         sn.text(obj.nullable ? " (nullable)" : ""),
                         sn.text(" type.")];
@@ -1204,7 +1230,9 @@
                                                                     sn.text(">")]);
                                 }
                                 else {
-                                    sn.element("code", {}, tyTD, [sn.element("a", {}, null, prm.datatype)]);
+                                    var cnt = [sn.element("a", {}, null, prm.datatype)];
+                                    if (prm.array) cnt.push(sn.text("[]"));
+                                    sn.element("code", {}, tyTD, cnt);
                                 }
                                 if (prm.nullable) sn.element("td", { "class": "prmNullTrue" }, tr, "\u2714");
                                 else              sn.element("td", { "class": "prmNullFalse" }, tr, "\u2718");
@@ -1252,12 +1280,15 @@
                                                             sn.text(">")]);
                         }
                         else {
-                            sn.element("code", {}, reDiv, [sn.element("a", {}, null, it.datatype)]);
+                            var cnt = [sn.element("a", {}, null, it.datatype)];
+                            if (it.array) cnt.push(sn.text("[]"));
+                            sn.element("code", {}, reDiv, cnt);
                         }
                         if (it.nullable) sn.text(", nullable", reDiv);
                     }
                     else if (type == "attribute") {
                         sn.text(" of type ", dt);
+                        if (it.array) sn.text("array of ", dt);
                         var span = sn.element("span", { "class": "idlAttrType" }, dt);
                         var matched = /^sequence<(.+)>$/.exec(it.datatype);
                         if (matched) {
@@ -1268,7 +1299,6 @@
                         else {
                             sn.element("a", {}, span, it.datatype);
                         }
-
                         if (it.readonly) sn.text(", readonly", dt);
                         if (it.nullable) sn.text(", nullable", dt);
                         
@@ -1332,9 +1362,10 @@
         }
         else if (obj.type == "typedef") {
             var nullable = obj.nullable ? "?" : "";
+            var arr = obj.array ? "[]" : "";
             return  "<span class='idlTypedef' id='idl-def-" + obj.id + "'>typedef <span class='idlTypedefType'>" + 
                     this.writeDatatype(obj.datatype) +
-                    "</span>" + nullable + " <span class='idlTypedefID'>" + obj.id + "</span>;</span>";
+                    "</span>" + arr + nullable + " <span class='idlTypedefID'>" + obj.id + "</span>;</span>";
         }
         else if (obj.type == "implements") {
             return  "<span class='idlImplements'><a>" + obj.id + "</a> implements <a>" + obj.datatype + "</a>;";
@@ -1350,18 +1381,20 @@
                                                                 .join(", ");
             str += " {\n";
             // we process attributes and methods in place
-            var maxAttr = 0, maxMeth = 0, maxConst = 0;
+            var maxAttr = 0, maxMeth = 0, maxConst = 0, hasRO = false;
             obj.children.forEach(function (it, idx) {
                 var len = it.datatype.length;
                 if (it.nullable) len = len + 1;
+                if (it.array) len = len + 2;
                 if (it.type == "attribute") maxAttr = (len > maxAttr) ? len : maxAttr;
                 else if (it.type == "method") maxMeth = (len > maxMeth) ? len : maxMeth;
                 else if (it.type == "constant") maxConst = (len > maxConst) ? len : maxConst;
+                if (it.type == "attribute" && it.readonly) hasRO = true;
             });
             var curLnk = "widl-" + obj.id + "-";
             for (var i = 0; i < obj.children.length; i++) {
                 var ch = obj.children[i];
-                if (ch.type == "attribute") str += this.writeAttribute(ch, maxAttr, indent + 1, curLnk);
+                if (ch.type == "attribute") str += this.writeAttribute(ch, maxAttr, indent + 1, curLnk, hasRO);
                 else if (ch.type == "method") str += this.writeMethod(ch, maxMeth, indent + 1, curLnk);
                 else if (ch.type == "constant") str += this.writeConst(ch, maxConst, indent + 1, curLnk);
             }
@@ -1372,15 +1405,19 @@
             var str = "<span class='idlException' id='idl-def-" + obj.id + "'>";
             if (obj.extendedAttributes) str += this._idn(indent) + "[<span class='extAttr'>" + obj.extendedAttributes + "</span>]\n";
             str += this._idn(indent) + "exception <span class='idlExceptionID'>" + obj.id + "</span> {\n";
-            var maxAttr = 0, maxConst = 0;
+            var maxAttr = 0, maxConst = 0, hasRO = false;
             obj.children.forEach(function (it, idx) {
-                if (it.type == "attribute")   maxAttr = (it.datatype.length > maxAttr) ? it.datatype.length : maxAttr;
-                else if (it.type == "constant") maxConst = (it.datatype.length > maxConst) ? it.datatype.length : maxConst;
+                var len = it.datatype.length;
+                if (it.nullable) len = len + 1;
+                if (it.array) len = len + 2;
+                if (it.type == "attribute")   maxAttr = (len > maxAttr) ? len : maxAttr;
+                else if (it.type == "constant") maxConst = (len > maxConst) ? len : maxConst;
+                if (it.type == "attribute" && it.readonly) hasRO = true;
             });
             var curLnk = "widl-" + obj.id + "-";
             for (var i = 0; i < obj.children.length; i++) {
                 var ch = obj.children[i];
-                if (ch.type == "attribute") str += this.writeAttribute(ch, maxAttr, indent + 1, curLnk);
+                if (ch.type == "attribute") str += this.writeAttribute(ch, maxAttr, indent + 1, curLnk, hasRO);
                 else if (ch.type == "constant") str += this.writeConst(ch, maxConst, indent + 1, curLnk);
             }
             str += this._idn(indent) + "};</span>\n";
@@ -1388,7 +1425,7 @@
         }
     },
     
-    writeAttribute:    function (attr, max, indent, curLnk) {
+    writeAttribute:    function (attr, max, indent, curLnk, hasRO) {
         var sets = [], gets = [];
         if (attr.raises.length) {
             for (var i = 0; i < attr.raises.length; i++) {
@@ -1401,13 +1438,17 @@
         var str = "<span class='idlAttribute'>";
         if (attr.extendedAttributes) str += this._idn(indent) + "[<span class='extAttr'>" + attr.extendedAttributes + "</span>]\n";
         str += this._idn(indent);
-        if (attr.readonly) str += "readonly ";
-        else               str += "         ";
+        if (hasRO) {
+            if (attr.readonly) str += "readonly ";
+            else               str += "         ";
+        }
         str += "attribute ";
         var pad = max - attr.datatype.length;
         if (attr.nullable) pad = pad - 1;
+        if (attr.array) pad = pad - 2;
         var nullable = attr.nullable ? "?" : "";
-        str += "<span class='idlAttrType'>" + this.writeDatatype(attr.datatype) + nullable + "</span> ";
+        var arr = attr.array ? "[]" : "";
+        str += "<span class='idlAttrType'>" + this.writeDatatype(attr.datatype) + arr + nullable + "</span> ";
         for (var i = 0; i < pad; i++) str += " ";
         str += "<span class='idlAttrName'><a href='#" + curLnk + attr.id + "'>" + attr.id + "</a></span>";
         if (gets.length) {
@@ -1430,17 +1471,20 @@
         str += this._idn(indent);
         var pad = max - meth.datatype.length;
         if (meth.nullable) pad = pad - 1;
+        if (meth.array) pad = pad - 2;
         var nullable = meth.nullable ? "?" : "";
-        str += "<span class='idlMethType'>" + this.writeDatatype(meth.datatype) + nullable + "</span> ";
+        var arr = meth.array ? "[]" : "";
+        str += "<span class='idlMethType'>" + this.writeDatatype(meth.datatype) + arr + nullable + "</span> ";
         for (var i = 0; i < pad; i++) str += " ";
         str += "<span class='idlMethName'><a href='#" + curLnk + meth.id + "'>" + meth.id + "</a></span> (";
         var obj = this;
         str += meth.params.map(function (it) {
                                     var nullable = it.nullable ? "?" : "";
                                     var optional = it.optional ? " optional " : " ";
+                                    var arr = it.array ? "[]" : "";
                                     var prm = "<span class='idlParam'>";
                                     if (it.extendedAttributes) prm += "[<span class='extAttr'>" + it.extendedAttributes + "</span>] ";
-                                    prm += "in" + optional + "<span class='idlParamType'>" + obj.writeDatatype(it.datatype) + nullable + "</span> " +
+                                    prm += "in" + optional + "<span class='idlParamType'>" + obj.writeDatatype(it.datatype) + arr + nullable + "</span> " +
                                     "<span class='idlParamName'>" + it.id + "</span>" +
                                     "</span>";
                                     return prm;
Received on Thursday, 3 December 2009 12:21:56 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 3 December 2009 12:22:04 GMT