JSDOC/ScopeParser.js
[gnome.introspection-doc-generator] / JSDOC / ScopeParser.js
index db6b880..74c404d 100644 (file)
@@ -132,6 +132,9 @@ ScopeParser.prototype = {
         
         this.mode = 'BUILDING_SYMBOL_TREE';
         this.parseScope(this.globalScope);
+        
+        print("---------------END PASS 1 ---------------- ");
+        
     },
     mungeSymboltree : function()
     {
@@ -175,7 +178,9 @@ ScopeParser.prototype = {
 
     log : function(str)
     {
-          //println("<B>LOG:</B>" + htmlescape(str) + "<BR/>\n");
+        print ("                    ".substring(0, this.braceNesting*2) + str);
+        
+        //println("<B>LOG:</B>" + htmlescape(str) + "<BR/>\n");
     },
     logR : function(str)
     {
@@ -197,7 +202,7 @@ ScopeParser.prototype = {
         var identifier;
 
         var expressionBraceNesting = this.braceNesting;
-        var bracketNesting = 0;
+        
         var parensNesting = 0;
         
         var isObjectLitAr = [ false ];
@@ -207,7 +212,10 @@ ScopeParser.prototype = {
         while (token) {
           //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
              
-            !this.debug|| print(token.type + '.' + token.name+ ":" + token.data);
+            this.log(token.data);
+            if (token.type == 'NAME') {
+            //    print('*' + token.data);
+            }
             switch(token.type + '.' + token.name) {
                 case "KEYW.VAR":
                 case "KEYW.CONST": // not really relivant as it's only mozzy that does this.
@@ -253,7 +261,9 @@ ScopeParser.prototype = {
                         if (token.name == "IN") {
                             break;
                         } else {
+                            //var bn = this.braceNesting;
                             this.parseExpression();
+                            //this.braceNesting = bn;
                             //this.logR("parseScope DONE  : <B>ParseExpression</B> - tok is:" + this.ts.lookT(0).toString()); 
                             
                             token = this.ts.lookTok(1);
@@ -266,26 +276,35 @@ ScopeParser.prototype = {
                     break;
                 case "KEYW.FUNCTION":
                     //println("<i>"+token.data+"</i>");
+                     var bn = this.braceNesting;
                     this.parseFunctionDeclaration();
+                     this.braceNesting = bn;
                     break;
 
-                case "KEYW.LEFT_CURLY": // {
+                case "PUNC.LEFT_CURLY": // {
                     //println("<i>"+token.data+"</i>");
                     isObjectLitAr.push(false);
-                    print(">>>>>> OBJLIT PUSH(false)");
                     this.braceNesting++;
+                    
+                    //print(">>>>>> OBJLIT PUSH(false)" + this.braceNesting);
                     break;
 
-                case "KEYW.RIGHT_CURLY": // }
+                case "PUNC.RIGHT_CURLY": // }
                     //println("<i>"+token.data+"</i>");
                     this.braceNesting--;
                     isObjectLitAr.pop();
-                    print(">>>>>> OBJLIT POP(false)");
-                        //assert braceNesting >= scope.getBraceNesting();
-                    if (this.braceNesting == scope.braceN) {
+                    //print(">>>>>> OBJLIT POP"+ this.braceNesting);
+                        //assert braceNesting >= scope.getBra ceNesting();
+                    
+                    if (this.braceNesting < expressionBraceNesting) {
                         var ls = this.scopes.pop();
                         ls.getUsedSymbols();
-                        print("<<<<<<<EXIT SCOPE" +this.scopes.length);
+                        // eat symbol if we are currently at { 
+                        if (this.ts.look(0).data == '{') {
+                            this.ts.nextTok();
+                        }
+                        
+                        //print("<<<<<<<EXIT SCOPE" +this.scopes.length);
                         return;
                     }
                     break;
@@ -323,7 +342,7 @@ ScopeParser.prototype = {
                         // then we are in an object lit.. -> we need to flag the brace as such...
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
-                        print(">>>>>> OBJLIT PUSH(true)");
+                        //print(">>>>>> OBJLIT REPUSH(true)");
                     }
                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
                     
@@ -354,7 +373,7 @@ ScopeParser.prototype = {
                     if ((this.ts.lookTok(-1).data == "{") && (this.ts.lookTok(1).data == ":")) {
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
-                        print(">>>>>> OBJLIT PUSH(true)");
+                        //print(">>>>>> OBJLIT REPUSH(true)");
                         //println("<i>"+token.data+"</i>");
                         break;
                     }
@@ -483,7 +502,7 @@ ScopeParser.prototype = {
             currentScope = this.scopes[this.scopes.length-1];
             
             //println("<i>"+token.data+"</i>");
-            !this.debug|| print ("EXP" + token.toString());
+            this.log("EXP:" + token.data);
             switch (token.type) {
                 case 'PUNC':
                     switch(token.data) {
@@ -502,14 +521,15 @@ ScopeParser.prototype = {
 
                         case '{': //Token.LC:
                             isObjectLitAr.push(false);
-                            print(">>>>> OBJ PUSH(false)");
+                            
                             this.braceNesting++;
+                            ///print(">>>>> EXP PUSH(false)"+this.braceNesting);
                             break;
 
                         case '}': //Token.RC:
                             this.braceNesting--;
                             isObjectLitAr.pop();
-                            print(">>>>> OBJ POP");    
+                            //print(">>>>> EXP POP" + this.braceNesting);    
                            // assert braceNesting >= expressionBraceNesting;
                             break;
 
@@ -536,7 +556,7 @@ ScopeParser.prototype = {
                         // then we are in an object lit.. -> we need to flag the brace as such...
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
-                        print(">>>>> OBJ PUSH(true)");
+                        //print(">>>>> EXP PUSH(true)");
                     }
                     
                     
@@ -566,7 +586,7 @@ ScopeParser.prototype = {
                         // then we are in an object lit.. -> we need to flag the brace as such...
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
-                         print(">>>>> OBJ PUSH(true)");
+                         //print(">>>>> EXP  PUSH(true)");
                         break;
                     }
                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
@@ -719,7 +739,7 @@ ScopeParser.prototype = {
             this.indexedScopes[this.ts.cursor] = fnScope;
             
         } else {
-            //println("FETCHING SCOPE" + this.ts.cursor);
+            //qln("FETCHING SCOPE" + this.ts.cursor);
             fnScope = this.indexedScopes[this.ts.cursor];
           
         }