JSDOC/TokenReader.js
[gnome.introspection-doc-generator] / JSDOC / Collapse.js
index c7ea183..af58a91 100644 (file)
@@ -1,11 +1,12 @@
 //<script type="text/javscript">
-XObject = imports.XObject.XObject;
+const XObject = imports.XObject.XObject;
 
  
-console     = imports.console.console; 
+const console     = imports.console.console; 
 
 // make sure parent is loaded..
-TokenStream = imports.TokenStream.TokenStream;
+const TokenStream = imports.TokenStream.TokenStream;
+
 /**
  * 
  * base class for parsing segments of token array..
@@ -31,14 +32,13 @@ TokenStream = imports.TokenStream.TokenStream;
  * 
  */ 
  
-Collapse = XObject.define(
+const Collapse = XObject.define(
     function (ar)
     {
-         
         Collapse.superclass.constructor.call(this, ar);
         
         this.spaces();
-        var ar = this.collapse(this.tokens);
+        ar = this.collapse(this.tokens);
         
         this.tokens = ar;
         
@@ -88,10 +88,10 @@ Collapse = XObject.define(
                   //  Seed.print(TokenStream.toString(ret));
                     return ret;
                 }
-               // console.log(tok.data);
+                // console.log(tok.data);
                 switch(tok.type) {
                     case "VOID": 
-                        return; //EOF
+                        return ret; //EOF
                         
                         
                     case "KEYW": 
@@ -111,23 +111,27 @@ Collapse = XObject.define(
                                 
                                 var start = st.cursor;
                                 st.next(1);
-                                var add = st.balance(tok.name);
+                                var add = st.balance(tok.data);
                                 if (!add) {
-                                    console.dump(tok);
-                                    console.dump(start + '...' + st.cursor);
-                                    console.dump(st.tokens);
+                                    Seed.print(tok);
+                                    Seed.print(start + '...' + st.cursor);
+                                    Seed.print(st.tokens);
                                  
                                 }
                                 if (add) {
                                     add.shift();
                                 }
-                                //Seed.print(TokenStream.toString(aa));
+                                //Seed.print("ADD");
+                                //Seed.print(JSON.stringify(add, null,4));
+                                
                                 
                                 
                                 var toks = add ? this.collapse(add) : [];
                                 tok.items = false;
                                 tok.props = false;
                                 
+                                
+                                
                                 if (tok.data != '{') {
                                     // paramters or array elements..
                                     tok.items = this.toItems(toks, [',']);
@@ -190,6 +194,12 @@ Collapse = XObject.define(
                     g.push(ar[i]);
                     continue;
                 }
+                // var a=..., b =...
+                if ((ar[i].data != ';') && g.length && (g[0].name == "VAR")) {;
+                    g.push(ar[i]);
+                    continue;
+                }
+                
                 g.push(ar[i]);
                 ret.push(g);
                 g = [];
@@ -235,8 +245,9 @@ Collapse = XObject.define(
                    
                 }
             }
-             // last..
-            if (k.length) {
+             // last.. - if g.val.length is 0 then it's a trailing ','...
+             // we should really throw a syntax error in that case..
+            if (k.length && g.val.length) {
                 ret[k] = g;
             }
             return ret;
@@ -246,4 +257,4 @@ Collapse = XObject.define(
 
     
     
-});
\ No newline at end of file
+});