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

2009/dap/ReSpec.js/js respec.js,1.55,1.56

From: Robin Berjon via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 02 Dec 2009 17:42:15 +0000
To: public-dap-commits@w3.org
Message-Id: <E1NFtDT-0003bD-35@lionel-hutz.w3.org>
Update of /sources/public/2009/dap/ReSpec.js/js
In directory hutz:/tmp/cvs-serv13741/js

Modified Files:
	respec.js 
Log Message:
implemented nullable support, ISSUE-51

Index: respec.js
===================================================================
RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- respec.js	2 Dec 2009 17:10:08 -0000	1.55
+++ respec.js	2 Dec 2009 17:42:13 -0000	1.56
@@ -917,7 +917,13 @@
         if (match) {
             mem.type = "attribute";
             mem.readonly = (match[1] == "readonly");
-            mem.datatype = match[2];
+            var type = match[2];
+            mem.nullable = false;
+            if (/\?$/.test(type)) {
+                type = type.replace(/\?$/, "");
+                mem.nullable = true;
+            }
+            mem.datatype = type;
             mem.id = match[3];
             mem.raises = [];
             if (sgrs.length) {
@@ -957,10 +963,16 @@
         }
             
         // CONST
-        match = /^\s*const\s+\b([^=]+)\b\s+([^=\s]+)\s*=\s*(.*)$/.exec(str);
+        match = /^\s*const\s+\b([^=]+\??)\s+([^=\s]+)\s*=\s*(.*)$/.exec(str);
         if (match) {
             mem.type = "constant";
-            mem.datatype = match[1];
+            var type = match[1];
+            mem.nullable = false;
+            if (/\?$/.test(type)) {
+                type = type.replace(/\?$/, "");
+                mem.nullable = true;
+            }
+            mem.datatype = type;
             mem.id = match[2];
             mem.value = match[3];
             return mem;
@@ -970,7 +982,13 @@
         match = /^\s*\b(.*?)\s+\b(\S+)\s*\(\s*(.*)\s*\)\s*$/.exec(str);
         if (match) {
             mem.type = "method";
-            mem.datatype = match[1];
+            var type = match[1];
+            mem.nullable = false;
+            if (/\?$/.test(type)) {
+                type = type.replace(/\?$/, "");
+                mem.nullable = true;
+            }
+            mem.datatype = type;
             mem.id = match[2];
             mem.params = [];
             var prm = match[3];
@@ -1016,7 +1034,13 @@
                     prm = this.parseExtendedAttributes(prm, p);
                     var match = /^\s*\b(.+?)\s+([^\s]+)\s*$/.exec(prm);
                     if (match) {
-                        p.datatype = match[1];
+                        var type = match[1];
+                        p.nullable = false;
+                        if (/\?$/.test(type)) {
+                            type = type.replace(/\?$/, "");
+                            p.nullable = true;
+                        }
+                        p.datatype = type;
                         p.id = match[2];
                         p.description = sn.documentFragment();
                         sn.copyChildren(dd, p.description);
@@ -1037,7 +1061,13 @@
                     var match = re.exec(prm);
                     if (match) {
                         prm = prm.replace(re, "");
-                        p.datatype = match[1];
+                        var type = match[1];
+                        p.nullable = false;
+                        if (/\?$/.test(type)) {
+                            type = type.replace(/\?$/, "");
+                            p.nullable = true;
+                        }
+                        p.datatype = type;
                         p.id = match[2];
                         mem.params.push(p);
                     }
@@ -1140,7 +1170,7 @@
                         if (it.params.length) {
                             var table = sn.element("table", { "class": "parameters" }, desc);
                             var tr = sn.element("tr", {}, table);
-                            ["Parameter", "Type", "Description"].forEach(function (tit) { sn.element("th", {}, tr, tit); });
+                            ["Parameter", "Type", "Nullable", "Description"].forEach(function (tit) { sn.element("th", {}, tr, tit); });
                             for (var k = 0; k < it.params.length; k++) {
                                 var prm = it.params[k];
                                 var tr = sn.element("tr", {}, table);
@@ -1155,6 +1185,8 @@
                                 else {
                                     sn.element("code", {}, tyTD, [sn.element("a", {}, null, prm.datatype)]);
                                 }
+                                if (prm.nullable) sn.element("td", { "class": "prmNullTrue" }, tr, "\u2714");
+                                else              sn.element("td", { "class": "prmNullFalse" }, tr, "\u2718");
                                 var cnt = prm.description ? [prm.description] : "";
                                 sn.element("td", { "class": "prmDesc" }, tr, cnt);
                             }
@@ -1199,6 +1231,7 @@
                         else {
                             sn.element("code", {}, reDiv, [sn.element("a", {}, null, it.datatype)]);
                         }
+                        if (it.nullable) sn.text(", nullable", reDiv);
                     }
                     else if (type == "attribute") {
                         sn.text(" of type ", dt);
@@ -1214,6 +1247,7 @@
                         }
 
                         if (it.readonly) sn.text(", readonly", dt);
+                        if (it.nullable) sn.text(", nullable", dt);
                         
                         if (it.raises.length) {
                             var table = sn.element("table", { "class": "exceptions" }, desc);
@@ -1249,6 +1283,7 @@
                     else if (type == "constant") {
                         sn.text(" of type ", dt);
                         sn.element("span", { "class": "idlConstType" }, dt, [sn.element("a", {}, null, it.datatype)]);
+                        if (it.nullable) sn.text(", nullable", dt);
                     }
                 }
             }
@@ -1293,9 +1328,11 @@
             // we process attributes and methods in place
             var maxAttr = 0, maxMeth = 0, maxConst = 0;
             obj.children.forEach(function (it, idx) {
-                if (it.type == "attribute")   maxAttr = (it.datatype.length > maxAttr) ? it.datatype.length : maxAttr;
-                else if (it.type == "method") maxMeth = (it.datatype.length > maxMeth) ? it.datatype.length : maxMeth;
-                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.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;
             });
             var curLnk = "widl-" + obj.id + "-";
             for (var i = 0; i < obj.children.length; i++) {
@@ -1344,7 +1381,9 @@
         else               str += "         ";
         str += "attribute ";
         var pad = max - attr.datatype.length;
-        str += "<span class='idlAttrType'>" + this.writeDatatype(attr.datatype) + "</span> ";
+        if (attr.nullable) pad = pad - 1;
+        var nullable = attr.nullable ? "?" : "";
+        str += "<span class='idlAttrType'>" + this.writeDatatype(attr.datatype) + 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) {
@@ -1366,14 +1405,17 @@
         if (meth.extendedAttributes) str += this._idn(indent) + "[<span class='extAttr'>" + meth.extendedAttributes + "</span>]\n";
         str += this._idn(indent);
         var pad = max - meth.datatype.length;
-        str += "<span class='idlMethType'>" + this.writeDatatype(meth.datatype) + "</span> ";
+        if (meth.nullable) pad = pad - 1;
+        var nullable = meth.nullable ? "?" : "";
+        str += "<span class='idlMethType'>" + this.writeDatatype(meth.datatype) + 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 prm = "<span class='idlParam'>";
                                     if (it.extendedAttributes) prm += "[<span class='extAttr'>" + it.extendedAttributes + "</span>] ";
-                                    prm += "in <span class='idlParamType'>" + obj.writeDatatype(it.datatype) + "</span> " +
+                                    prm += "in <span class='idlParamType'>" + obj.writeDatatype(it.datatype) + nullable + "</span> " +
                                     "<span class='idlParamName'>" + it.id + "</span>" +
                                     "</span>";
                                     
@@ -1396,7 +1438,9 @@
         str += this._idn(indent);
         str += "const ";
         var pad = max - cons.datatype.length;
-        str += "<span class='idlConstType'><a>" + cons.datatype + "</a></span> ";
+        if (cons.nullable) pad = pad - 1;
+        var nullable = cons.nullable ? "?" : "";
+        str += "<span class='idlConstType'><a>" + cons.datatype + "</a>" + nullable + "</span> ";
         for (var i = 0; i < pad; i++) str += " ";
         str += "<span class='idlConstName'><a href='#" + curLnk + cons.id + "'>" + cons.id + "</a></span> = " +
                "<span class='idlConstValue'>" + cons.value + "</span>;</span>\n";
Received on Wednesday, 2 December 2009 17:42:20 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 2 December 2009 17:42:20 GMT