sync fixes
[app.jsdoc] / JSDOC / Collapse.js
index 3a7f58d..c555600 100644 (file)
@@ -6,13 +6,11 @@ console     = imports.console.console;
 
 // make sure parent is loaded..
 TokenStream = imports.TokenStream.TokenStream;
-/**
- * @namespace JSDOC
- */
-
+  
 /**
- * 
+ * @scope JSDOC
+ * @class Collapse
+ * @extends JSDOC.TokenStream
  * base class for parsing segments of token array..
  * 
  * 
@@ -28,50 +26,132 @@ TokenStream = imports.TokenStream.TokenStream;
        ( ) - collapse into first element.
        [ ] - collapse into first element.
  * c) items = , seperation within the above..
- * 
- * usage: x = new Collapse(token_array)
+ * d) props = for  { xx: ... , yy: ....}
  * 
  * 
+ * usage:
+ *  x = new Collapse({
+ *      srcFile : ....
+ *  })
+ *  x.collapse();
  * 
  * 
+ * @param {Object} array tokens
+     
  */ 
  
 Collapse = XObject.define(
-    function (ar)
+    
+    function (cfg)
     {
-         
-        Collapse.superclass.constructor.call(this, ar);
+        Collapse.superclass.constructor.call(this, cfg);
         
-        this.spaces();
-        var ar = this.collapse(this.tokens);
-        
-        this.tokens = ar;
         
+        this.allJSDOC = [];
        // console.dump(ar);
         
     }, 
     TokenStream, 
     {
-    
-        spaces : function () {
+        
+        /**
+         * @cfg {Boolean} collapseTop make statements array of top level tokens.
+         */
+        collapseTop : false,
+        
+        /**
+         * @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 :
+         *   token.comments = [] (array of COMMENTS)
+         *   token.comment = combined string
+         *   token.jsdoc = last comment (as DocComment)
+         *
+         *
+         */
+        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;
                 }
                 tok.prefix = '';
                 if (pref.length) {
+                    tok.comments = [];
                     pref.forEach( function(e) {
                         if (!e) {
                             return;
                         }
+                        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;
+                        
                     })
                 }
                 
@@ -79,16 +159,21 @@ Collapse = XObject.define(
                 pref=  [];
                 
             }
-            this.tokens = ar;
+            return ar;
             
         },
-        collapse : function(ar) {
+        
+        
+             
+        _collapse : function(ar, depth) {
             
-            var st = new  TokenStream(ar);
+            depth = depth || 0;
+            var st = new  TokenStream({ tokens : ar });
             var ret = [];
             
             while (true) {
                 var  tok = st.look(1,true);
+                tok.depth = depth;
                 if (!tok || !tok.is) {
                   //  Seed.print(TokenStream.toString(ret));
                     return ret;
@@ -131,7 +216,7 @@ Collapse = XObject.define(
                                 
                                 
                                 
-                                var toks = add ? this.collapse(add) : [];
+                                var toks = add ? this._collapse(add, depth+1) : [];
                                 tok.items = false;
                                 tok.props = false;
                                 
@@ -140,26 +225,33 @@ Collapse = XObject.define(
                                 if (tok.data != '{') {
                                     // paramters or array elements..
                                     tok.items = this.toItems(toks, [',']);
-                                } else {
-                                    // check for types.. it could be a list of statements.. or object
+                                    tok.args = [];
+                                    tok.items.forEach(function(tar) {
+                                        if (tar[0].is('NAME')) {
+                                            tok.args.push(tar[0].data);
+                                        }
+                                    });
                                     
-                                    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,[ ';', '{'] );;
-                                    }
                                     
+                                        
+                                    ret.push(tok);
                                     
+                                    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);
                                 
@@ -220,9 +312,9 @@ Collapse = XObject.define(
         toProps : function(ar)
         {
             
-            var ret = { }
+            var ret = { };
                
-            var g = { key : '', val: [] }
+            var g = { key : '', val: [] };
                
             
             var k = '';