sync fixes
[app.jsdoc] / JSDOC / Collapse.js
index 54f9309..c555600 100644 (file)
@@ -6,15 +6,11 @@ console     = imports.console.console;
 
 // make sure parent is loaded..
 TokenStream = imports.TokenStream.TokenStream;
+  
 /**
- * 
- */
-
-/**
- * @namespace JSDOC
+ * @scope JSDOC
  * @class Collapse
- * @extends TokenStream
+ * @extends JSDOC.TokenStream
  * base class for parsing segments of token array..
  * 
  * 
@@ -30,7 +26,7 @@ TokenStream = imports.TokenStream.TokenStream;
        ( ) - collapse into first element.
        [ ] - collapse into first element.
  * c) items = , seperation within the above..
- *
+ * d) props = for  { xx: ... , yy: ....}
  * 
  * 
  * usage:
@@ -46,12 +42,12 @@ TokenStream = imports.TokenStream.TokenStream;
  
 Collapse = XObject.define(
     
-    function (ar, scrFile)
+    function (cfg)
     {
         Collapse.superclass.constructor.call(this, cfg);
         
         
-        
+        this.allJSDOC = [];
        // console.dump(ar);
         
     }, 
@@ -67,6 +63,39 @@ Collapse = XObject.define(
          * @type {Array} top level statements
          */
         statements : false,
+        
+        /**
+         * @cfg {Boolean} createJSDOC    create .jsdoc properties on tokens.
+         */
+        createJSDOC : false,
+        
+        /**
+         * @type {Array} allJSDOC if createJSDOC is set, then all the files JSDOC comments
+         *                        are stored here, in theory to verify that all have been used up..
+         */
+        allJSDOC : false,
+        
+        /**
+         * collapse the token array
+         * if collapseTop is set, then statments is set to the array statements (which is an array of tokens)
+         * otherwise this.tokens is set..
+         */
+        collapse : function(ar) {
+           
+            ar = ar || this.tokens ;
+            this.rewind();
+            ar = this.spaces(ar);
+            ar = this._collapse(ar);
+        
+            if (this.collapseTop) {
+                //print(JSON.stringify(ar, null,4));
+                
+                return this.toItems(ar, [ ';', '{'] );
+                
+            }
+            return ar;
+        },
+        
         /**
          * Add all the comments to the closed token.
          * adds :
@@ -76,15 +105,24 @@ Collapse = XObject.define(
          *
          *
          */
-        spaces : function () {
+        spaces : function (toks)
+        {
+            this.tokens = toks;
+            this.rewind();
             var ar = [];
             var pref = [];
             
             var tok;
+            var jsdoc;
+            var _this = this;
             
             for (var i = 0; i < this.tokens.length; i ++) {
                 tok = this.tokens[i];
                 
+                if (this.createJSDOC) {
+                    tok.jsdoc = false;
+                }
+                
                 if (tok.is("COMM") || tok.is("WHIT")) {
                     pref.push(tok);
                     continue;
@@ -98,10 +136,18 @@ Collapse = XObject.define(
                         }
                         if (e.name == "JSDOC") {
                             tok.comment = e.data;
+                            if (_this.createJSDOC) { 
+                                tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
+                                _this.allJSDOC.push(tok.jsdoc); 
+                            }
                         }
                         // kludge for private..
                         if (e.is("COMM") && e.data.match(/\/\/\s+private/)) {
                             tok.comment = '/** @private */';
+                            if (_this.createJSDOC) { 
+                                tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
+                                _this.allJSDOC.push(tok.jsdoc); 
+                            }
                         }
                         
                         tok.prefix += e.data;
@@ -113,19 +159,16 @@ Collapse = XObject.define(
                 pref=  [];
                 
             }
-            this.tokens = ar;
+            return ar;
             
         },
-        collapse : function() {
-            this.spaces();
-            var nar = this._collapse(this.tokens);
         
-            this.tokens = nar;
-        }        
-        collapse : function(ar, depth) {
+        
+             
+        _collapse : function(ar, depth) {
             
             depth = depth || 0;
-            var st = new  TokenStream(ar);
+            var st = new  TokenStream({ tokens : ar });
             var ret = [];
             
             while (true) {
@@ -182,28 +225,33 @@ Collapse = XObject.define(
                                 if (tok.data != '{') {
                                     // paramters or array elements..
                                     tok.items = this.toItems(toks, [',']);
+                                    tok.args = [];
+                                    tok.items.forEach(function(tar) {
+                                        if (tar[0].is('NAME')) {
+                                            tok.args.push(tar[0].data);
+                                        }
+                                    });
                                     
                                     
-                                } else {
-                                    // check for types.. it could be a list of statements.. or object
+                                        
+                                    ret.push(tok);
                                     
-                                    var ost = new  TokenStream(toks);
-                                    //console.dump(ost.look(2,true) );
-                                    if (ost.look(2,true) && ost.look(2,true).data == ":") {
-                                        tok.props = this.toProps(toks);
-                                    } else {
-                                        // list of statemetns..
-                                        tok.items = this.toItems(toks,[ ';', '{'] );;
-                                    }
+                                    continue;
                                     
                                     
+                                }  
+                                    // check for types.. it could be a list of statements.. or object
+                                    
+                                var ost = new  TokenStream({tokens : toks});
+                                //console.dump(ost.look(2,true) );
+                                if (ost.look(2,true) && ost.look(2,true).data == ":") {
+                                    tok.props = this.toProps(toks);
+                                } else {
+                                    // list of statemetns..
+                                    tok.items = this.toItems(toks,[ ';', '{'] ); 
                                 }
-                                 
-                                
-                                
-                                
-                                
                                 
+                                   
                                 
                                 //Seed.print(" ADD : " + add.length  +  " ITEMS: " + tok.items.length);
                                 
@@ -264,9 +312,9 @@ Collapse = XObject.define(
         toProps : function(ar)
         {
             
-            var ret = { }
+            var ret = { };
                
-            var g = { key : '', val: [] }
+            var g = { key : '', val: [] };
                
             
             var k = '';