JSDOC/Walker2.js
[gnome.introspection-doc-generator] / JSDOC / Walker2.js
index 136b048..57cfea3 100644 (file)
@@ -4,7 +4,7 @@ XObject      = imports.XObject.XObject;
 Scope        = imports.Scope.Scope;
 DocComment   = imports.DocComment.DocComment;
 Symbol       = imports.Symbol.Symbol;
-Parser       = imports.Parser.Parser;
+
 
 /**
 * Scope stuff
@@ -156,29 +156,30 @@ Walker2 = XObject.define(
             //print(JSON.stringify(this.ts, null, 4)); Seed.quit();
             
             while (null != (token = this.ts.next())) {
-                print("TOK"+ token.toString());
+                //print("TOK"+ token.toString());
                 //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
                   
-                if (token.is('WHIT')) {
+                if (token.is('COMM')) {
                       
                  
                     if (token.name != 'JSDOC') {
+                        //print("Walker2 : spce is not JSDOC");
                         continue; //skip.
                     }
                     if (this.currentDoc) {
                         // add it to the current scope????
                         
                         this.addSymbol('', true);
-
+                        //print ( "Unconsumed Doc: " + token.toString())
                         //throw "Unconsumed Doc (TOKwhitespace): " + this.currentDoc.toSource();
                     }
                     
-                    
+                   // print ( "NEW COMMENT: " + token.toString())
                     var newDoc = new DocComment(token.data);
                     
                     // it's a scope changer..
                     if (newDoc.getTag("scope").length) {
-                        //print(newDoc.getTag("scope").toSource());
+                        //print("Walker2 : doctag changes scope");
                         //throw "done";
                         scope.ident = '$private$|' + newDoc.getTag("scope")[0].desc;
                         continue;
@@ -188,6 +189,7 @@ Walker2 = XObject.define(
                     if (newDoc.getTag("scopeAlias").length) {
                         //print(newDoc.getTag("scopeAlias").toSource());
                         // @scopeAlias a=b
+                        //print("Walker2 : doctag changes scope (alias)");
                         var sal = newDoc.getTag("scopeAlias")[0].desc.split("=");
                         aliases[sal[0]] = sal[1];
                         
@@ -197,6 +199,7 @@ Walker2 = XObject.define(
                     
                     /// got a  doc comment..
                     //token.data might be this.??? (not sure though)
+                    //print("Walker2 : setting currentDoc");
                     this.currentDoc = newDoc;
                     continue;
                 }
@@ -208,8 +211,8 @@ Walker2 = XObject.define(
                 // things that stop comments carrying on...??
                 
                 if (this.currentDoc && (
-                        token.tokN.data == ';' || 
-                        token.tokN.data == '}')) {
+                        token.data == ';' || 
+                        token.data == '}')) {
                     this.addSymbol('', true);
                     //throw "Unconsumed Doc ("+ token.toString() +"): " + this.currentDoc.toSource();
                 }
@@ -244,14 +247,10 @@ Walker2 = XObject.define(
                     // a  << scope
                 // xxx.applyIf(a, {
                     // a  << scope
-                if (token.type = 'NAME') {
+                if (token.type == 'NAME') {
                     
                     //print("TOK(ident)"+ token.toString());
-                    
-                    
-                       
-                    
-                    
+                     
                     if (/\.extend$/.test(token.data) &&
                         this.ts.lookTok(1).data == '(' &&
                         this.ts.lookTok(2).type == 'NAME' &&
@@ -418,19 +417,7 @@ Walker2 = XObject.define(
                     }
                     
 
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
+                     
                     
                     
                     
@@ -451,23 +438,32 @@ Walker2 = XObject.define(
                         if (((this.ts.lookTok(1).data == ':' )|| (this.ts.lookTok(1).data == '=')) &&
                             (this.ts.lookTok(2).name == "FUNCTION")
                             ) {
+                               // this.ts.nextTok();
+                               // this.ts.nextTok();
                                 atype = 'FUNCTION';
                         }
                         
                         //print("ADD SYM:" + atype + ":" + token.toString() + this.ts.lookTok(1).toString() + this.ts.lookTok(2).toString());
                         
                         this.addSymbol(
-                            this.ts.lookTok(-1).tokN == Script.TOKdot ? token.data :    fixAlias(token.data),
+                            this.ts.lookTok(-1).data == '.' ? token.data :    fixAlias(token.data),
                             false,
                             atype);
                         
+                        this.currentDoc = false;
+                        
+                        
                     }
                  
                     
                     continue; // dont care about other idents..
                     
-                }        
-                if (token.type == "STRN")   {
+                }
+                
+                //print ("NOT NAME");
+                
+                
+                if (token.type == "STRN")   { // THIS WILL NOT HAPPEN HERE?!!?
                     if (this.currentDoc) {
                         this.addSymbol(token.data.substring(1,token.data.length-1),false,'OBJECT');
 
@@ -477,13 +473,16 @@ Walker2 = XObject.define(
                 // really we only have to deal with object constructs and function calls that change the scope...
                 
                 
-                 if (token.name == 'FUNCTION') {
-                     
+                if (token.name == 'FUNCTION') {
+                    //print("GOT FUNCTION");
                     // see if we have an unconsumed doc...
                     
                     if (this.currentDoc) {
-                            print(this.ts.dumpToCur());
-                            throw "Unhandled doc (TOKfunction)" + token.toString();
+                            throw {
+                                name: "ArgumentError", 
+                                message: "Unhandled doc (TOKfunction)" + token.toString()
+                            };
+                            
                             //this.addSymbol(this.currentDoc.getTag('class')[0].name, true);
 
                             //throw "Unconsumed Doc: (TOKrbrace)" + this.currentDoc.toSource();
@@ -501,7 +500,7 @@ Walker2 = XObject.define(
                             (this.ts.lookTok(-2).type == 'NAME')
                         ) {
                         scopeName = this.ts.lookTok(-2).data;
-                        this.ts.balanceN('(');
+                        this.ts.balance('(');
                         token = this.ts.nextTok(); // should be {
                         //print("FOO=FUNCITON() {}" + this.ts.context() + "\n" + token.toString());
                         
@@ -568,7 +567,7 @@ Walker2 = XObject.define(
                         //print("got for : function() {"); 
                             
                         //scopeName = this.ts.look(-3).data;
-                        this.ts.balanceN(Script.TOKlparen);
+                        this.ts.balance('(');
                         //print(token.toString())
                         token = this.ts.nextTok(); // should be {
                         //print(token.toString())
@@ -591,7 +590,7 @@ Walker2 = XObject.define(
                             (this.ts.lookTok(1).type == 'NAME') 
                         ) {
                         //scopeName = this.ts.look(-3).data;
-                        this.ts.balanceN('(');
+                        this.ts.balance('(');
                         token = this.ts.nextTok(); // should be {
                             
                         var fnScope = new Scope(this.braceNesting, scope, token.n, '');
@@ -619,7 +618,7 @@ Walker2 = XObject.define(
                          //   (this.ts.lookTok(-4).tokN == Script.TOKidentifier)
                         ) {
                         //scopeName = this.ts.look(-3).data;
-                        this.ts.balanceN('(');
+                        this.ts.balance('(');
                         token = this.ts.nextTok(); // should be {
                         var fnScope = new Scope(this.braceNesting, scope, token.n, '$private$');
                         this.indexedScopes[this.ts.cursor] = fnScope;
@@ -634,8 +633,12 @@ Walker2 = XObject.define(
                     }
                     
                     
-                    print(this.ts.context());
-                    throw "dont know how to handle function syntax??";
+                    throw {
+                        name: "ArgumentError", 
+                        message: "dont know how to handle function syntax??\n" +
+                                token.toString()
+                    };
+            
                     
                     continue;
                     
@@ -737,6 +740,8 @@ Walker2 = XObject.define(
          
         addSymbol: function(lastIdent, appendIt, atype )
         {
+            //print("Walker.addSymbol : " + lastIdent);
+            //print("Walker.curdoc: " + JSON.stringify(this.currentDoc, null,4));
             
             /*if (!this.currentDoc.tags.length) {
                 
@@ -754,18 +759,18 @@ Walker2 = XObject.define(
               
                 //print(this.currentDoc.toSource());
                  this.currentDoc = false;
-                print("SKIP ADD SYM:  it's private");
+                //print("SKIP ADD SYM:  it's private");
                 return;
             }
             
-            var token = this.ts.cur();
+            var token = this.ts.lookTok(0);
             if (typeof(appendIt) == 'undefined') {
                 appendIt= false;
             }
           //  print(this.currentDoc.toSource(););
             if (this.currentDoc.getTag('event').length) {
                 //?? why does it end up in desc - and not name/...
-                print(this.currentDoc.getTag('event')[0]);
+                //print(this.currentDoc.getTag('event')[0]);
                 lastIdent = '*' + this.currentDoc.getTag('event')[0].desc;
                 //lastIdent = '*' + lastIdent ;
             }
@@ -785,7 +790,11 @@ Walker2 = XObject.define(
                 }
                 s.push(lastIdent);
                 
+                //print("FULLSCOPE: " + JSON.stringify(s));
+                
+                
                 var s = s.join('|').split('|');
+                //print("FULLSCOPE: " + s);
                print("Walker:ADDSymbol: " + s.join('|') );
                 var _t = '';
                  _s = '';
@@ -803,17 +812,18 @@ Walker2 = XObject.define(
                     if (s[i].substring(0,6) == '$this$') {
                         var ts = s[i].split('=');
                         _t = ts[1];
+                        _s = ''; // ??? VERY QUESTIONABLE!!!
                         continue;
                     }
                     // when to use $this$ (probabl for events)
                     _s += _s.length ? '.' : '';
                     _s += s[i];
                 }
-                    
+                print("FULLSCOPE: s , t : " + _s +', ' + _t);
                 
                 /// calc scope!!
                 //print("ADDING SYMBOL: "+ s.join('|') +"\n"+ _s + "\n" +Script.prettyDump(this.currentDoc.toSource()));
-                
+                //print("Walker.addsymbol - add : " + _s);
                 if (appendIt && !lastIdent.length) {
                     
                     // append, and no symbol???
@@ -822,6 +832,7 @@ Walker2 = XObject.define(
                     if (this.currentDoc.getTag('class').length) {
                         _s = this.currentDoc.getTag('class')[0].desc;
                         var symbol = new Symbol(_s, [], "CONSTRUCTOR", this.currentDoc);
+                        Parser       = imports.Parser.Parser;
                         Parser.addSymbol(symbol);
                         this.symbols[_s] = symbol;
                         return;
@@ -834,10 +845,16 @@ Walker2 = XObject.define(
                     
                     _s = _s.replace(/\.prototype.*$/, '');
                     if (typeof(this.symbols[_s]) == 'undefined') {
-                        print("Symbol:" + _s);
-                        print(this.currentDoc.src);
-                        
-                        throw "Trying to append symbol, but no doc available";
+                        //print("Symbol:" + _s);
+                    //print(this.currentDoc.src);
+                        
+                        throw {
+                            name: "ArgumentError", 
+                            message: "Trying to append symbol '" + _s + "', but no doc available\n" +
+                                this.ts.lookTok(0).toString()
+                        };
+
+                     
                     }
                         
                     for (var i =0; i < this.currentDoc.tags.length;i++) {
@@ -847,22 +864,30 @@ Walker2 = XObject.define(
                     return;
                 }
             }    
+            //print("Walker.addsymbol - chkdup: " + _s);
             if (typeof(this.symbols[_s]) != 'undefined') {
                 
                 if (this.symbols[_s].comment.hasTags) {
                     // then existing comment doesnt has tags 
-                     throw "DUPLICATE Symbol " + _s;
+                    //throw {
+                    //    name: "ArgumentError", 
+                     //   message:"DUPLICATE Symbol " + _s + "\n" + token.toString()
+                    //};
+                    return;
                 }
                 // otherwise existing comment has tags - overwrite..
                 
                 
             }
+            //print("Walker.addsymbol - ATYPE: " + _s);
+
             if (typeof(atype) == "undefined") {
                 atype = 'OBJECT'; //this.currentDoc.getTag('class').length ? 'OBJECT' : 'FUNCTION';;
                }
             
+            //print("Walker.addsymbol - add : ");
             var symbol = new Symbol(_s, [], atype, this.currentDoc);
-            
+            Parser       = imports.Parser.Parser;
             Parser.addSymbol(symbol);
             this.symbols[_s] = symbol;