[introspection-doc-generator] fixes for xml parsing, gjs and seed



commit b69689e3c26e829dfc838a238ee9d52d21f93e74
Author: Sylvain Duclos <sylvain_duclos yahoo com>
Date:   Sat Apr 16 16:33:33 2011 +0800

    fixes for xml parsing, gjs and seed

 Introspect/Base.js      |    7 +--
 Introspect/Basic.js     |    2 -
 Introspect/Callback.js  |    6 +--
 Introspect/Class.js     |    6 +--
 Introspect/Constant.js  |   13 ++----
 Introspect/Enum.js      |   12 +----
 Introspect/Field.js     |    5 +--
 Introspect/Link.js      |    2 +-
 Introspect/Method.js    |   24 +++++-----
 Introspect/NameSpace.js |  118 +++++++++++++++++++++++++++++++++++++----------
 Introspect/Property.js  |    2 +-
 Introspect/Signal.js    |    2 +-
 JsTemplate/Template.js  |    2 +-
 docs.js                 |    4 ++
 14 files changed, 127 insertions(+), 78 deletions(-)
---
diff --git a/Introspect/Base.js b/Introspect/Base.js
index 4a2460e..42efd44 100644
--- a/Introspect/Base.js
+++ b/Introspect/Base.js
@@ -2,8 +2,7 @@
 //Gtk = imports.gi.Gtk;
 const GI      = imports.gi.GIRepository;
 const GLib    = imports.gi.GLib;
-//xml     = imports.libxml;
-const xml     = imports.gi.libxml2;
+
 //GObject = imports.gi.GObject;
 
 const XObject = imports.XObject.XObject;
@@ -53,13 +52,13 @@ var Base = XObject.define(
         this.implementedBy = []; // interface - which object uses it.
         this.extendsClasses = []; // what it extends...
         this.childClasses = []; // what 
-         this.desc = NameSpace.doc(this.alias );
+         this.desc = NameSpace.doc(ns,name );
         
         
         var gi = GI.Repository.get_default();
         var ver = gi.get_version(ns);
         var pth = GI.Repository.get_search_path ();
-        var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
+        var gir_path = pth[0].replace(/lib.?.?\/girepository-1.0/, 'share\/gir-1.0');
        //console.log(fn);
         this.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
         this.gir_filename = ns + '-' + ver + '.gir';
diff --git a/Introspect/Basic.js b/Introspect/Basic.js
index ccb0909..01eb81d 100644
--- a/Introspect/Basic.js
+++ b/Introspect/Basic.js
@@ -2,8 +2,6 @@
 //Gtk = imports.gi.Gtk;
 const GI      = imports.gi.GIRepository;
 const GLib    = imports.gi.GLib;
-//xml     = imports.libxml;
-const xml     = imports.gi.libxml2;
 //GObject = imports.gi.GObject;
 
 const XObject = imports.XObject.XObject;
diff --git a/Introspect/Callback.js b/Introspect/Callback.js
index 0c1d6e5..c169c8a 100644
--- a/Introspect/Callback.js
+++ b/Introspect/Callback.js
@@ -2,9 +2,7 @@
 //Gtk = imports.gi.Gtk;
 const GI      = imports.gi.GIRepository;
 const GLib    = imports.gi.GLib;
-//xml     = imports.libxml;
-const xml     = imports.gi.libxml2;
-//GObject = imports.gi.GObject;
+
 
 const XObject = imports.XObject.XObject;
 const console = imports.console.console;
@@ -38,7 +36,7 @@ var Callback = XObject.define(
             returns :   [ { type :  this.typeToName(GI.callable_info_get_return_type(sig)) } ]            
             
         });
-        this.desc =  NameSpace.doc(memberOf.alias + '.' + this.name);
+        this.desc =  NameSpace.doc(memberOf.alias ,  this.name);
         //memberOf[saveto].push(this);
         //keylist.push(this.name);
         
diff --git a/Introspect/Class.js b/Introspect/Class.js
index 0e389ab..67d2b8f 100644
--- a/Introspect/Class.js
+++ b/Introspect/Class.js
@@ -2,10 +2,6 @@
 //Gtk = imports.gi.Gtk;
 const GI      = imports.gi.GIRepository;
 const GLib    = imports.gi.GLib;
-//xml     = imports.libxml;
-const xml     = imports.gi.libxml2;
-//GObject = imports.gi.GObject;
- 
  
 const XObject = imports.XObject.XObject;
 const console = imports.console.console;
@@ -26,7 +22,7 @@ const Base      = imports.Introspect.Base.Base;
 var Class = XObject.define(
     function(ns, name) {
         Base.call(this, ns, name);
-        print("Class ctr - parent called");
+        //print("Class ctr - parent called");
         this.loadExtends();
         this.loadImplements();
         //console.log("CREATED(Class) " + this.alias);
diff --git a/Introspect/Constant.js b/Introspect/Constant.js
index 9992ffb..b7cf15a 100644
--- a/Introspect/Constant.js
+++ b/Introspect/Constant.js
@@ -2,9 +2,6 @@
 //Gtk = imports.gi.Gtk;
 const GI        = imports.gi.GIRepository;
 const GLib      = imports.gi.GLib;
-//const xml       = imports.libxml;
-const xml       = imports.gi.libxml2;
-
 
 const XObject   = imports.XObject.XObject;
 const console   = imports.console.console;
@@ -32,11 +29,10 @@ var Constant = XObject.define(
 
         this.value= 'UNKNOWN';
 
-        /* gjs constant_info_get_value introspectable="0"
         if (ty != 'interface') {
-            //var argm = new GI.Argument();
+            var argm = new GI.Argument();
             //var argm = new GI._Argument();
-            var argm;
+            //var argm;
             GI.constant_info_get_value(prop, argm);
             if (ty != 'utf8') {
                 this.value = argm.v_long;
@@ -44,9 +40,8 @@ var Constant = XObject.define(
                 this.value = argm.v_string;
             }
         } 
-        */
-
-        this.desc = NameSpace.doc(memberOf.alias + '.' + this.name)
+         
+        this.desc = NameSpace.doc(memberOf.alias,  this.name)
 
         memberOf[saveto].push(this);
         keylist.push(this.name);
diff --git a/Introspect/Enum.js b/Introspect/Enum.js
index 8c21355..8c316ac 100644
--- a/Introspect/Enum.js
+++ b/Introspect/Enum.js
@@ -2,23 +2,15 @@
 //Gtk = imports.gi.Gtk;
 const GI      = imports.gi.GIRepository;
 const GLib    = imports.gi.GLib;
-//xml     = imports.libxml;
-const xml     = imports.gi.libxml2;
-
-
-
+ 
 const XObject     = imports.XObject.XObject;
 const console     = imports.console.console;
 
 const NameSpace   = imports.Introspect.NameSpace.NameSpace;
 const Base        = imports.Introspect.Base.Base;
 
- 
   
 
-
-
-
 var Enum = XObject.define(
     function(ns, name) {
         Base.call(this, ns, name);
@@ -33,7 +25,7 @@ var Enum = XObject.define(
                 return; // already loaded..
             }
             
-            this.desc = NameSpace.doc(this.alias);
+            this.desc = NameSpace.doc(this.alias,'');
             var bi = this.getBI();
                  
             for(var i =0; i < GI.enum_info_get_n_values(bi); i++) {
diff --git a/Introspect/Field.js b/Introspect/Field.js
index 8206b7b..1fb3c56 100644
--- a/Introspect/Field.js
+++ b/Introspect/Field.js
@@ -2,10 +2,7 @@
 //Gtk = imports.gi.Gtk;
 const GI      = imports.gi.GIRepository;
 const GLib    = imports.gi.GLib;
-//xml     = imports.libxml;
-const xml     = imports.gi.libxml2;
-
-
+ 
 
 const XObject     = imports.XObject.XObject;
 const console     = imports.console.console;
diff --git a/Introspect/Link.js b/Introspect/Link.js
index 104f5cc..24331ce 100644
--- a/Introspect/Link.js
+++ b/Introspect/Link.js
@@ -1,4 +1,4 @@
-//<script type="text/javascript">
+    //<script type="text/javascript">
 
 const console = imports.console.console;
 
diff --git a/Introspect/Method.js b/Introspect/Method.js
index 7d1caa1..d3d32ea 100644
--- a/Introspect/Method.js
+++ b/Introspect/Method.js
@@ -35,14 +35,14 @@ var Method = XObject.define(
         var retval = [ { 
                 name : 0, 
                 type :  this.typeToName(GI.callable_info_get_return_type(m)),
-                desc : NameSpace.doc(memberOf.alias + '.' + n_original + '.return-value')
+                desc : NameSpace.doc(memberOf.alias ,  n_original + '.return-value')
         } ];
 
         var args = this.argsToArrays(m, retval);
 
         if ((n == 'c_new') && !args.length && memberOf.constructors.length) {
 
-            memberOf.constructors[0].doc = NameSpace.doc(memberOf.alias + '.' + n_original);
+            memberOf.constructors[0].doc = NameSpace.doc(memberOf.alias ,  n_original);
 
             return false; // skip.
         }
@@ -53,18 +53,18 @@ var Method = XObject.define(
         // this is a bit messy, as we probably loose the doc's on new..
 
         XObject.extend(this, {
-            name : n,
-            params: args,
-            returns :  retval,
-            isConstructor : flags & GI.FunctionInfoFlags.IS_CONSTRUCTOR,
-            isStatic : !(flags & GI.FunctionInfoFlags.IS_METHOD),
-            memberOf : memberOf.alias,
-            exceptions : [],
-            desc : NameSpace.doc(memberOf.alias + '.' + n_original)
+            name            : n,
+            params          : args,
+            returns         :  retval,
+            isConstructor   : flags & GI.FunctionInfoFlags.IS_CONSTRUCTOR,
+            isStatic        : !(flags & GI.FunctionInfoFlags.IS_METHOD),
+            memberOf        : memberOf.alias,
+            exceptions      : [],
+            desc            : NameSpace.doc(memberOf.alias ,  n_original)
         });
         // add descriptions to the arguments..
         this.params.map(function(p) {
-            p.desc = NameSpace.doc(memberOf.alias + '.' + n_original + '.' + p.name);
+            p.desc = NameSpace.doc(memberOf.alias, n_original + '.' + p.name);
             //Seed.print(memberOf.alias + '.' + n_original + '.' + p.name + ':' +  p.desc);
         });
 
@@ -125,4 +125,4 @@ var Method = XObject.define(
     Basic,
 
     {}
-);
\ No newline at end of file
+);
diff --git a/Introspect/NameSpace.js b/Introspect/NameSpace.js
index c14c5b1..4d2e62c 100644
--- a/Introspect/NameSpace.js
+++ b/Introspect/NameSpace.js
@@ -3,9 +3,8 @@
 
 const GI      = imports.gi.GIRepository;
 const GLib    = imports.gi.GLib;
-//const xml     = imports.libxml;
-const xml     = imports.gi.libxml2;
 
+ 
 const File    = imports.File.File;
 const XObject = imports.XObject.XObject;
 const console = imports.console.console;
@@ -97,7 +96,7 @@ var NameSpace = {
             methods        : [],
             values         : [], /// really constants.
             signals        : [],
-            interfaces     : [],
+            interfaces     : []
         };
 
         //console.log("NS: " + ns);
@@ -128,7 +127,7 @@ var NameSpace = {
                     continue;
 
                 case  GI.InfoType.CALLBACK:
-                   // new Introspect.Callback(info, ret, 'callbacks', []);
+                    new imports.Introspect.Callback.Callback(info, ret, 'callbacks', []);
                     continue;
 
                 case  GI.InfoType.ENUM:
@@ -197,11 +196,14 @@ var NameSpace = {
         }
     },
 
-    doc : function(what) {
-        //print ("DOC: + " +what);
-        var ns = what.split('.').shift();
-        return '';
+    doc : function(ns,what)
+    {
+        // invalid or empty namespace..
+        if (typeof(ns) == 'undefined' || -1 != ns.indexOf('.')) {
+            return '';
+        }
         this.commentLoad(ns);
+        
 
         return typeof(this.comments[ns][what]) == 'undefined' ?  '' : this.comments[ns][what];
     },
@@ -235,14 +237,15 @@ var NameSpace = {
             return null;
         }
 
-        function walk (element, path) {
+        function seed_walk (element, path) {
 
             if (!element) {
                 return;
             }
 
             var n =  getAttribute(element, 'name') ;
-            //console.log("WALK" + n);
+            //console.log("WALK: " + n);
+            
             if (element.name == 'signal') {
                 path += '.signal';
             }
@@ -255,43 +258,110 @@ var NameSpace = {
             if (element.name == 'return-value') {
                 path += '.return-value';
             }
-
-            var d =   getAttribute(element,'doc');
-            if (d) {
-             //   Seed.print(path + ':' + d);
-                ret[path] = d;
+            if (element.name == 'doc') {
+                ret[path] = element.content;
+                return;
+                // no child nodes of this..
             }
-
+             
             var child = element.children;
 
             while (child){
                 //console.log(child.tag);
                 if (child.type == "element"){
-                    walk (child, path);
+                    seed_walk (child, path);
                 }
                 child = child.next;
             }
         }
-
+        
+        function gjs_walk(gir) {
+            // clip XML declaration as per instruction at https://developer.mozilla.org/en/E4X
+            // to work around bug https://bugzilla.mozilla.org/show_bug.cgi?id=336551
+            //gir = gir.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "");    // ";
+            // the regex above take too long
+            gir = gir.replace(/^<\?xml version="1.0"\?>/, '');
+            //console.log('YYY : ');
+        
+            // clip gtk namespace declaration as it confuse the parser
+            gir = gir.replace(/xmlns=\"http:\/\/www.gtk.org\/introspection\/core\/1.0\"/, "");
+            //console.log('ZZZ : ');
+        
+        
+            var doc = new XML(gir);
+        
+            var ret = {};
+            var c = doc.namespace.*;
+            for (var i in c) {
+                if (c[i].function) {
+                    ret[c[i]  name] = c[i].doc.toString();
+        
+                    if (c[i]['return-value']) {
+                        var idxstr  = c[i]  name + '.return-value';
+                        ret[idxstr] = c[i]['return-value'].doc.toString();
+                        //console.log("=== XML: " +i+ '/' + ret[idxstr] + '/' + c[i] + '/' + idxstr);
+                    }
+        
+                    if (c[i].parameters) {
+                        for (var j in c[i].parameters.parameter) {
+                            var idxstr  = c[i]  name + '.' +  c[i] parameters parameter[j]  name;
+                            ret[idxstr] = c[i].parameters.parameter[j].doc.toString();
+                            //console.log('XXX : ' + c[i].parameters.parameter[j] + '///' + idxstr);
+                        }
+                    }
+                }
+        
+                // alias not in code but in gir
+                //if (c[i].alias) {
+                //    var idxstr  = c[i]  name;
+                //    ret[idxstr] = c[i].alias.doc.toString();
+                //    //console.log('YYY : ' + c[i].alias + '///' + idxstr);
+                //}
+        
+                // doc not in gir
+                //if (c[i].enumeration) {
+                //    // ,,,
+                //}
+                //if (c[i].constant) {
+                //    // ..,
+                //}
+            }
+        
+            return ret;
+        }
+        
+        
+        
+        var gi = GI.Repository.get_default();
         var pth = GI.Repository.get_search_path ();
 
-        var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
+        var gir_path = pth[0].replace(/lib.?.?\/girepository-1.0/, 'share\/gir-1.0');
 
         //console.log(fn);
         var  fn = gir_path + '/'+ ns + '-' + ver + '.gir';
         // console.log(fn);
 
         if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
-            console.log('missing docc file ' + fn);
+            console.log('missing gir file for docs ' + fn);
             this.comments[ns] = {};
 
             return;
         }
-
-        var doc = xml.parseFile(fn);
-        //console.log("xmldoc?" + doc);
-        walk (doc.root, '');
+        if (typeof(Seed) == 'undefined') {
+            const gjsxml      = imports.templates.gjs.parseXMLdoc;
+            var gir           = File.read(fn);
+            this.comments[ns] = gjs_walk(gir);
+         } else {
+            const seedxml     = imports.libxml;
+            var doc           = seedxml.parseFile(fn);
+            seed_walk(doc.root, '');
+            this.comments[ns] = ret;
+         }
+        //console.log('loaded gir file for docs ' + fn);
+        //console.log('--------------- DUMP --------------------');
         //console.dump(ret);
+        //console.log('--------------- DUMP --------------------');
+
         this.comments[ns] = ret;
     },
 
diff --git a/Introspect/Property.js b/Introspect/Property.js
index fb0a9be..f8cf5b5 100644
--- a/Introspect/Property.js
+++ b/Introspect/Property.js
@@ -23,7 +23,7 @@ var Property = XObject.define(
         this.memberOf = memberOf.alias
         memberOf[saveto].push(this);
         keylist.push(this.name);
-        this.desc = NameSpace.doc(this.memberOf + '.' + n_original);
+        this.desc = NameSpace.doc(this.memberOf ,  n_original);
         
 
         if (typeof(this.type) == 'string' && this.type.indexOf('.') > -1) {
diff --git a/Introspect/Signal.js b/Introspect/Signal.js
index 0624ebf..7d0cbef 100644
--- a/Introspect/Signal.js
+++ b/Introspect/Signal.js
@@ -33,7 +33,7 @@ var Signal = XObject.define(
             memberOf : memberOf.alias,
             exceptions : [],
             returns :   [ { type :  this.typeToName(GI.callable_info_get_return_type(sig)) } ],
-            desc : NameSpace.doc(memberOf.alias + '.signal.' + n_original)
+            desc : NameSpace.doc(memberOf.alias , 'signal.' + n_original)
         });
         memberOf[saveto].push(this);
         keylist.push(this.name);
diff --git a/JsTemplate/Template.js b/JsTemplate/Template.js
index bd094ad..4f7e52e 100644
--- a/JsTemplate/Template.js
+++ b/JsTemplate/Template.js
@@ -150,7 +150,7 @@ var Template = XObject.define(
                  File.write('/tmp/template.js', this.code);
                  //Seed.print('in /tmp/template.js');
                  console.log('in /tmp/template.js');
-                 //throw e;
+                 throw e;
                  //Seed.quit();
             }
 
diff --git a/docs.js b/docs.js
index 1d67d12..badc2d9 100644
--- a/docs.js
+++ b/docs.js
@@ -60,6 +60,10 @@ ns_list = ns_list.sort();
 //print("loading library to make sure it works.");
 ns_list.forEach(function(ns_name)
 {
+    // do not try and load Epiphany as it depends on webkit, which is not in ns_list????
+    if (ns_name == 'Epiphany') {
+        return;
+    }
     var core = imports.gi[ns_name];
 });
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]