W3C home > Mailing lists > Public > public-dap-commits@w3.org > September 2011

2009/dap/ReSpec.js/js respec.js,1.158,1.159

From: Robin Berjon via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 07 Sep 2011 15:31:45 +0000
To: public-dap-commits@w3.org
Message-Id: <E1R1K6L-00032E-FJ@lionel-hutz.w3.org>
Update of /sources/public/2009/dap/ReSpec.js/js
In directory hutz:/tmp/cvs-serv11640

Modified Files:
	respec.js 
Log Message:
dictionaries are now supported as well

Index: respec.js
===================================================================
RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -d -r1.158 -r1.159
--- respec.js	24 Aug 2011 12:35:03 -0000	1.158
+++ respec.js	7 Sep 2011 15:31:43 -0000	1.159
@@ -1448,7 +1448,7 @@
             var inf = w.definition(idl);
             var df = w.makeMarkup();
             idl.parentNode.replaceChild(df, idl);
-            if (inf.type == "interface" || inf.type == "exception") infNames.push(inf.id);
+            if (inf.type == "interface" || inf.type == "exception" || inf.type == "dictionary") infNames.push(inf.id);
         }
         document.normalize();
         var ants = document.querySelectorAll("a:not([href])");
@@ -1607,6 +1607,7 @@
         str = this.parseExtendedAttributes(str, def);
         if      (str.indexOf("interface") == 0) this.interface(def, str, idl);
         else if (str.indexOf("exception") == 0) this.exception(def, str, idl);
+        else if (str.indexOf("dictionary") == 0) this.dictionary(def, str, idl);
         else if (str.indexOf("typedef") == 0)   this.typedef(def, str, idl);
         else if (/\bimplements\b/.test(str))     this.implements(def, str, idl);
         else    error("Expected definition, got: " + str);
@@ -1629,6 +1630,20 @@
         return inf;
     },
     
+    dictionary:  function (inf, str, idl) {
+        inf.type = "dictionary";
+        var match = /^\s*dictionary\s+([A-Za-z][A-Za-z0-9]*)(?:\s+:\s*([^{]+)\s*)?/.exec(str);
+        if (match) {
+            inf.id = match[1];
+            inf.refId = this._id(inf.id);
+            if (match[2]) inf.superclasses = match[2].split(/\s*,\s*/);
+        }
+        else {
+            error("Expected dictionary, got: " + str);
+        }
+        return inf;
+    },
+    
     exception:  function (exc, str, idl) {
         exc.type = "exception";
         var match = /^\s*exception\s+([A-Za-z][A-Za-z0-9]*)\s*/.exec(str);
@@ -1696,6 +1711,9 @@
             if (obj.type == "exception") {
                 mem = this.exceptionMember(dt, dd);
             }
+            else if (obj.type == "dictionary") {
+                mem = this.dictionaryMember(dt, dd);
+            }
             else {
                 mem = this.interfaceMember(dt, dd);
             }
@@ -1755,7 +1773,41 @@
         }
 
         // NOTHING MATCHED
-        error("Expected interface member, got: " + str);
+        error("Expected exception member, got: " + str);
+    },
+    
+    dictionaryMember:    function (dt, dd) {
+        var mem = { children: [] };
+        var str = this._norm(dt.textContent);
+        mem.description = sn.documentFragment();
+        sn.copyChildren(dd, mem.description);
+        str = this.parseExtendedAttributes(str, mem);
+    
+        // MEMBER
+        var match = /^\s*([^=]+\??)\s+([^=\s]+)(?:\s*=\s*(.*))?$/.exec(str);
+        // var match = /^\s*(.*?)\s+(\S+)\s*$/.exec(str);
+        if (match) {
+            mem.type = "member";
+            var type = match[1];
+            mem.id = match[2];
+            mem.refId = this._id(mem.id);
+            mem.default = match[3];
+            mem.nullable = false;
+            if (/\?$/.test(type)) {
+                type = type.replace(/\?$/, "");
+                mem.nullable = true;
+            }
+            mem.array = false;
+            if (/\[\]$/.test(type)) {
+                type = type.replace(/\[\]$/, "");
+                mem.array = true;
+            }
+            mem.datatype = type;
+            return mem;
+        }
+
+        // NOTHING MATCHED
+        error("Expected dictionary member, got: " + str);
     },
     
     interfaceMember:    function (dt, dd) {
@@ -2082,6 +2134,48 @@
             return df;
         }
 
+        else if (obj.type == "dictionary") {
+            var df = sn.documentFragment();
+            var curLnk = "widl-" + obj.refId + "-";
+            var things = obj.children;
+            if (things.length == 0) return df;
+            if (!this.noIDLSorting) {
+                things.sort(function (a, b) {
+                    if (a.id < b.id) return -1;
+                    if (a.id > b.id) return 1;
+                      return 0;
+                });
+            }
+            
+            var sec = sn.element("section", {}, df);
+            sn.element("h2", {}, sec, "Members");
+            var dl = sn.element("dl", { "class": "members" }, sec);
+            for (var j = 0; j < things.length; j++) {
+                var it = things[j];
+                var dt = sn.element("dt", { id: curLnk + it.refId }, dl);
+                sn.element("code", {}, dt, it.id);
+                var desc = sn.element("dd", {}, dl, [it.description]);
+                sn.text(" of type ", dt);
+                if (it.array) sn.text("array of ", dt);
+                var span = sn.element("span", { "class": "idlMemberType" }, dt);
+                var matched = /^sequence<(.+)>$/.exec(it.datatype);
+                if (matched) {
+                    sn.text("sequence<", span);
+                    sn.element("a", {}, span, matched[1]);
+                    sn.text(">", span);
+                }
+                else {
+                    sn.element("a", {}, span, it.datatype);
+                }
+                if (it.nullable) sn.text(", nullable", dt);
+                if (it.default) {
+                    sn.text(", defaulting to ", dt);
+                    sn.element("code", {}, dt, [sn.text(it.default)]);
+                }
+            }
+            return df;
+        }
+
         else if (obj.type == "interface") {
             var df = sn.documentFragment();
             var curLnk = "widl-" + obj.refId + "-";
@@ -2330,6 +2424,31 @@
             str += this._idn(indent) + "};</span>\n";
             return str;
         }
+        else if (obj.type == "dictionary") {
+            var str = "<span class='idlDictionary' id='idl-def-" + obj.refId + "'>";
+            if (obj.extendedAttributes) str += this._idn(indent) + "[<span class='extAttr'>" + obj.extendedAttributes + "</span>]\n";
+            str += this._idn(indent) + "dictionary <span class='idlDictionaryID'>" + obj.id + "</span>";
+            if (obj.superclasses && obj.superclasses.length) str += " : " +
+                                                obj.superclasses.map(function (it) {
+                                                                        return "<span class='idlSuperclass'><a>" + it + "</a></span>"
+                                                                    })
+                                                                .join(", ");
+            str += " {\n";
+            var max = 0;
+            obj.children.forEach(function (it, idx) {
+                var len = it.datatype.length;
+                if (it.nullable) len = len + 1;
+                if (it.array) len = len + 2;
+                max = (len > max) ? len : max;
+            });
+            var curLnk = "widl-" + obj.refId + "-";
+            for (var i = 0; i < obj.children.length; i++) {
+                var ch = obj.children[i];
+                str += this.writeMember(ch, max, indent + 1, curLnk);
+            }
+            str += this._idn(indent) + "};</span>\n";
+            return str;
+        }
     },
     
     writeField:    function (attr, max, indent, curLnk) {
@@ -2441,6 +2560,20 @@
         return str;
     },
 
+    writeMember:    function (memb, max, indent, curLnk) {
+        var str = "<span class='idlMember'>";
+        str += this._idn(indent);
+        var pad = max - memb.datatype.length;
+        if (memb.nullable) pad = pad - 1;
+        var nullable = memb.nullable ? "?" : "";
+        str += "<span class='idlMemberType'><a>" + memb.datatype + "</a>" + nullable + "</span> ";
+        for (var i = 0; i < pad; i++) str += " ";
+        str += "<span class='idlMemberName'><a href='#" + curLnk + memb.refId + "'>" + memb.id + "</a></span>";
+        if (memb.default) str += " = <span class='idlMemberValue'>" + memb.default + "</span>"
+        str += ";</span>\n";
+        return str;
+    },
+
     writeDatatype:    function (dt) {
         var matched = /^sequence<(.+)>$/.exec(dt);
         if (matched) {
Received on Wednesday, 7 September 2011 15:31:51 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 7 September 2011 15:31:52 GMT