JSDOC/TokenReader.js
[gnome.introspection-doc-generator] / JSDOC / Parser.js
index 75e4c9d..80ffd93 100644 (file)
@@ -1,9 +1,10 @@
 //<script type="text/javascript">
 
-Walker      = imports.Walker.Walker;
-Symbol      = imports.Symbol.Symbol;
-DocComment  = imports.DocComment.DocComment;
-Options     = imports.Options.Options;
+const Walker2      = imports.Walker2.Walker2;
+const Symbol      = imports.Symbol.Symbol;
+const SymbolSet      = imports.SymbolSet.SymbolSet;
+const DocComment  = imports.DocComment.DocComment;
+const Options     = imports.Options.Options;
 /**
  * Parser is a static  instance..
  * 
@@ -11,7 +12,7 @@ Options     = imports.Options.Options;
  */
  
  
-Parser = {
+const Parser = {
        conf: { 
         loaded: false 
     },
@@ -30,10 +31,10 @@ Parser = {
         if (this.conf.loaded) {
             return;
         }
-        print("init parser conf!?");
+        //print("init parser conf!?");
         this.conf = {
             loaded : true,
-            ignoreCode:                 Options.n,
+            //ignoreCode:                 Options.n,
             ignoreAnonymous:           true, // factory: true
             treatUnderscoredAsPrivate: true, // factory: true
             explain:                   false // factory: false
@@ -61,34 +62,45 @@ Parser = {
         
         // not a nice way to set stuff...
         
-        JSDOC.Symbol.srcFile = (srcFile || "");
-        JSDOC.DocComment.shared = ""; // shared comments don't cross file boundaries
+        Symbol.srcFile = (srcFile || "");
+        DocComment.shared = ""; // shared comments don't cross file boundaries
         
        
         
         
         
-        this.filesSymbols[JSDOC.Symbol.srcFile] = new JSDOC.SymbolSet();
+        this.filesSymbols[Symbol.srcFile] = new SymbolSet();
+        
+        //Options.LOG.inform("Parser - run walker");
+        this.walker = new  Walker2(ts);
+        this.walker.buildSymbolTree();
+        
+        
         
-        this.walker = new JSDOC.Walker2(ts);
-        this.walker.buildSymbolTree()
         //this.walker.walk(ts); // adds to our symbols
        // throw "done sym tree";
-        
+        //Options.LOG.inform("Parser - checking symbols");
         // filter symbols by option
         for (p in this.symbols._index) {
             var symbol = this.symbols.getSymbol(p);
             
+           // print(JSON.stringify(symbol, null,4));
+            
             if (!symbol) continue;
             
+            if (symbol.isPrivate) {
+                this.symbols.deleteSymbol(symbol.alias);
+                continue;
+            }
+            
             if (symbol.is("FILE") || symbol.is("GLOBAL")) {
                 continue;
             }
-            else if (!JSDOC.opt.a && !symbol.comment.isUserComment) {
+            //else if (!Options.a && !symbol.comment.isUserComment) {
                 //print("Deleting Symbols (no a / user comment): " + symbol.alias);
                 //this.symbols.deleteSymbol(symbol.alias);
-                //this.filesSymbols[JSDOC.Symbol.srcFile].deleteSymbol(symbol.alias);
-            }
+                //this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
+            //}
             
             if (/#$/.test(symbol.alias)) { // we don't document prototypes - this should not happen..
                 // rename the symbol ??
@@ -97,18 +109,18 @@ Parser = {
                     print("Renaming Symbol (got  a #): " + symbol.alias);
                     var n = '' + symbol.alias;
                     this.symbols.renameSymbol( n ,n.substring(0,n-1));
-                    this.filesSymbols[JSDOC.Symbol.srcFile].renameSymbol( n ,n.substring(0,n-1));
+                    this.filesSymbols[Symbol.srcFile].renameSymbol( n ,n.substring(0,n-1));
                     continue;
                 }
                 */
                 print("Deleting Symbols (got  a #): " + symbol.alias);
                 
                 this.symbols.deleteSymbol(symbol.alias);
-                this.filesSymbols[JSDOC.Symbol.srcFile].deleteSymbol(symbol.alias);
+                this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
             
             }
         }
-        //print(JSDOC.prettyDump(JSDOC.toQDump(this.filesSymbols[JSDOC.Symbol.srcFile]._index,'{','}')));
+        //print(prettyDump(toQDump(this.filesSymbols[Symbol.srcFile]._index,'{','}')));
         //print("AfterParse: " + this.symbols.keys().toSource().split(",").join(",\n   "));
         return this.symbols.toArray();
     },
@@ -116,7 +128,7 @@ Parser = {
        
        addSymbol: function(symbol) 
     {
-         print("PARSER addSYMBOL : " + symbol.alias);
+        //print("PARSER addSYMBOL : " + symbol.alias);
         
                // if a symbol alias is documented more than once the last one with the user docs wins
                if (this.symbols.hasSymbol(symbol.alias)) {
@@ -124,7 +136,7 @@ Parser = {
             
                        if (oldSymbol.comment.isUserComment && !oldSymbol.comment.hasTags) {
                                if (symbol.comment.isUserComment) { // old and new are both documented
-                                       JSDOC.opt.LOG.warn("The symbol '"+symbol.alias+"' is documented more than once.");
+                                       Options.LOG.warn("The symbol '"+symbol.alias+"' is documented more than once.");
                                }
                                else { // old is documented but new isn't
                                        return;
@@ -141,13 +153,13 @@ Parser = {
                }
                
                // -p flag is required to document private things
-               if ((symbol.isInner || symbol.isPrivate) && !JSDOC.opt.p) return;
+               if ((symbol.isInner || symbol.isPrivate) && !Options.p) return;
                
                // ignored things are not documented, this doesn't cascade
                if (symbol.isIgnored) return;
         // add it to the file's list... (for dumping later..)
-        if (JSDOC.Symbol.srcFile) {
-            this.filesSymbols[JSDOC.Symbol.srcFile].addSymbol(symbol);
+        if (Symbol.srcFile) {
+            this.filesSymbols[Symbol.srcFile].addSymbol(symbol);
         }
                
                this.symbols.addSymbol(symbol);
@@ -155,7 +167,7 @@ Parser = {
        
        addBuiltin: function(name) {
   
-               var builtin = new JSDOC.Symbol(name, [], "CONSTRUCTOR", new JSDOC.DocComment(""));
+               var builtin = new Symbol(name, [], "CONSTRUCTOR", new DocComment(""));
                builtin.isNamespace = false;
                builtin.srcFile = "";
                builtin.isPrivate = false;
@@ -181,9 +193,16 @@ Parser = {
                        }
                        print("-------------------\n");
                }
-       }
-    
-    
-    
+       },
+    /**
+     * return symbols so they can be serialized.
+     */
+    symbolsToObject : function(srcFile)
+    {
+        //this.filesSymbols[srcFile] is a symbolset..
+        return this.filesSymbols[srcFile];
+        
+            //    Parser.filesSymbols[srcFile]._index
+    }
 
 }
\ No newline at end of file