JSDOC/Scope.js
[gnome.introspection-doc-generator] / JSDOC / ScopeParser.js
index 143cbd7..3b53561 100644 (file)
@@ -9,7 +9,7 @@ Scope = imports['JSDOC/Scope.js'].Scope;
 */
 
 ScopeParser = function(ts) {
-    this.ts = ts;
+    this.ts = ts; // {TokenStream}
     this.warnings = [];
     this.scopes = [];
     this.indexedScopes = {};
@@ -201,27 +201,27 @@ ScopeParser.prototype = {
         var isObjectLitAr = [ false ];
         
         this.scopes.push(scope);
-        token = this.ts.lookT();
+        token = this.ts.lookTok();
         while (token) {
           //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
              
             //println("START<i>"+token.data+"</i>");
-            switch(token.tokN) {
-                case Script.TOKvar:
-                case Script.TOKconst:
+            switch(token.type + '.' + token.name) {
+                case "KEYW.VAR":
+                case "KEYW.CONST": // not really relivant as it's only mozzy that does this.
                     
                     //this.log("parseScope GOT VAR/CONST : " + token.toString()); 
                     while (true) {
-                        token = this.ts.nextT();
+                        token = this.ts.nextTok();
                         
-                        if (token.tokN == Script.TOKvar) { // kludge..
+                        if (token.name == "var") { // kludge..
                             continue;
                         }
                         if (!token) { // can return false at EOF!
                             break;
                         }
                         //this.logR("parseScope GOT VAR  : <B>" + token.toString() + "</B>"); 
-                        if (!token.isType('identifier')) {
+                        if (!token.type =="NAME") {
                             println(token.toString());
                             throw "var without ident";
                         }
@@ -231,45 +231,45 @@ ScopeParser.prototype = {
                             identifier = scope.getIdentifier(token.data) ;
                             
                             if (identifier == false) {
-                                scope.declareIdentifier(token.data,token);
+                                scope.declareIdentifier(token.data, token);
                             } else {
                                 token.identifier = identifier;
                                 this.warn("The variable " + symbol + " has already been declared in the same scope...");
                             }
                         }
 
-                        token = this.ts.nextT();
+                        token = this.ts.nextTok();
                         /*
                         assert token.getType() == Token.SEMI ||
                                 token.getType() == Token.ASSIGN ||
                                 token.getType() == Token.COMMA ||
                                 token.getType() == Token.IN;
                         */
-                        if (token.isType('in')) {
+                        if (token.name == "IN") {
                             break;
                         } else {
                             this.parseExpression();
                             //this.logR("parseScope DONE  : <B>ParseExpression</B> - tok is:" + this.ts.lookT(0).toString()); 
                             
                             
-                            if (this.ts.lookT(0).isType('semicolon')) {
+                            if (this.ts.lookTok(0).data == ';') {
                                 break;
                             }
                         }
                     }
                     break;
-                case Script.TOKfunction:
+                case "KEYW.FUNCTION":
                     //println("<i>"+token.data+"</i>");
                     this.parseFunctionDeclaration();
                     break;
 
-                case Script.TOKlbrace: // {
+                case "KEYW.LEFT_CURLY": // {
                     //println("<i>"+token.data+"</i>");
                     isObjectLitAr.push(false);
                     this.braceNesting++;
                     break;
 
-                case Script.TOKrbrace: // }
+                case "KEYW.RIGHT_CURLY": // }
                     //println("<i>"+token.data+"</i>");
                     this.braceNesting--;
                     isObjectLitAr.pop();
@@ -281,7 +281,7 @@ ScopeParser.prototype = {
                     }
                     break;
 
-                case Script.TOKwith:
+                case "KEYW.WITH":
                     //println("<i>"+token.data+"</i>");   
                     if (this.mode == "BUILDING_SYMBOL_TREE") {
                         // Inside a 'with' block, it is impossible to figure out
@@ -294,7 +294,7 @@ ScopeParser.prototype = {
                     }
                     break;
 
-                case Script.TOKcatch:
+                case "KEYW.CATCH":
                     //println("<i>"+token.data+"</i>");
                     this.parseCatch();
                     break;
@@ -307,16 +307,18 @@ ScopeParser.prototype = {
                         break;
                 */
                 
-                case Script.TOKstring: // used for object lit detection..
+                case "STRN.DOUBLE_QUOTE": // used for object lit detection..
+                case "STRN.SINGLE_QUOTE":
                     //println("<i>"+token.data+"</i>");
-                    if (this.ts.lookT(-1).isType('lbrace') && this.ts.lookT(1).isType('colon')) {
+                    if (this.ts.lookTok(-1).data == '{' && this.ts.lookTok(1).data == ':') {
                         // then we are in an object lit.. -> we need to flag the brace as such...
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
                     }
                     var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
-                    if (isInObjectLitAr &&  this.ts.lookT(1).isType('colon') &&
-                        ( this.ts.lookT(-11).isType('lbrace') ||  this.ts.lookT(-1).isType('comma'))) {
+                    
+                    if (isInObjectLitAr &&  this.ts.lookTok(1).data == ':' &&
+                        ( this.ts.lookTok(-1).data == '{'  ||  this.ts.lookTok(-1).data == ':' )) {
                         // see if we can replace..
                         // remove the quotes..
                         // should do a bit more checking!!!! (what about wierd char's in the string..
@@ -334,11 +336,14 @@ ScopeParser.prototype = {
                     break;
                 
                 
-                
-                case Script.TOKidentifier:
+                default: 
+                    if ((token.type != "NAME") && (token.type != "KEYW")){
+                        break;
+                    }
+                    // got identifier..
                     
                     // look for  { ** : <- indicates obj literal.. ** this could occur with numbers ..
-                    if ((this.ts.lookT(-1).tokN ==Script.TOKlbrace) && (this.ts.lookT(1).tokN == Script.TOKcolon)) {
+                    if ((this.ts.lookTok(-1).data == "{") && (this.ts.lookTok(1).data == ":")) {
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
                         //println("<i>"+token.data+"</i>");
@@ -346,7 +351,7 @@ ScopeParser.prototype = {
                     }
                     var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
                     
-                    if (isInObjectLitAr && (this.ts.lookT(1).tokN == Script.TOKcolon) && (this.ts.lookT(-1).tokN == Script.TOKcomma)) {
+                    if (isInObjectLitAr && (this.ts.lookTok(1).data == ":") && (this.ts.lookTok(-1).data == ",")) {
                         // skip, it's an object lit key..
                         //println("<i>"+token.data+"</i>");
                         break;
@@ -355,7 +360,7 @@ ScopeParser.prototype = {
                     
                     // skip anyting with "." before it..!!
                     
-                    if (this.ts.lookT(-1).isType('dot')) {
+                    if (this.ts.lookTok(-1).data(".")) {
                         // skip, it's an object prop.
                         //println("<i>"+token.data+"</i>");
                         break;
@@ -371,7 +376,7 @@ ScopeParser.prototype = {
 
                         if (symbol == "eval") {
                             // look back one and see if we can find a comment!!!
-                            if (this.ts.look(-1).isDoc()) {
+                            if (this.ts.look(-1).type == "COMM") {
                                 // look for eval:var:noreplace\n
                                 var _t = this;
                                 this.ts.look(-1).data.replace(/eval:var:([a-z_]+)/ig, function(m, a) {
@@ -408,7 +413,7 @@ ScopeParser.prototype = {
                         
                         if (identifier == false) {
 // BUG!find out where builtin is defined...
-                            if (symbol.length <= 3 && JSDOC.Scope.builtin.indexOf(symbol) < 0) {
+                            if (symbol.length <= 3 &&  Scope.builtin.indexOf(symbol) < 0) {
                                 // Here, we found an undeclared and un-namespaced symbol that is
                                 // 3 characters or less in length. Declare it in the global scope.
                                 // We don't need to declare longer symbols since they won't cause
@@ -425,18 +430,13 @@ ScopeParser.prototype = {
                        
                     }
                     break;
-                //case Script.TOKsemicolon':
-                    //println("<br/>");
-                //    break;
-                default:
-                    //println("<i>"+token.data+"</i>");
-                    break;
+                
                 
             } // end switch
             
             
             //this.timerPrint("parseScope TOK : " + token.toString()); 
-            token = this.ts.nextT();
+            token = this.ts.nextTok();
             //if (this.ts.nextT()) break;
             
         }
@@ -459,7 +459,7 @@ ScopeParser.prototype = {
         var parensNesting = 0;
 
         var isObjectLitAr = [ false ];
-        while (token = this.ts.lookT()) {
+        while (token = this.ts.lookTok()) {
      
 
             
@@ -467,10 +467,10 @@ ScopeParser.prototype = {
             
             //println("<i>"+token.data+"</i>");
             
-            switch (token.type) {
+            switch (token.data.toUpperCase()) {
 
-                case 'semicolon':
-                case 'comma':
+                case ';':
+                case ',':
                     if (this.braceNesting == expressionBraceNesting &&
                             bracketNesting == 0 &&
                             parensNesting == 0) {
@@ -478,43 +478,43 @@ ScopeParser.prototype = {
                     }
                     break;
 
-                case 'function':
+                case 'FUNCTION':
                     this.parseFunctionDeclaration();
                     break;
 
-                case 'lbrace': //Token.LC:
+                case '{': //Token.LC:
                     isObjectLitAr.push(false);
                     
                     this.braceNesting++;
                     break;
 
-                case 'rbrace': //Token.RC:
+                case '}': //Token.RC:
                     this.braceNesting--;
                     isObjectLitAr.pop();
                     
                    // assert braceNesting >= expressionBraceNesting;
                     break;
 
-                case 'lbracket': //Token.LB:
+                case '[': //Token.LB:
                     bracketNesting++;
                     break;
 
-                case 'rbracket': //Token.RB:
+                case ']': //Token.RB:
                     bracketNesting--;
                     break;
 
-                case 'lparen': //Token.LP:
+                case '(': //Token.LP:
                     parensNesting++;
                     break;
 
-                case 'rparen': //Token.RP:
+                case ')': //Token.RP:
                     parensNesting--;
                     break;
-                    
-                    
+            }
+            switch(token.type) {
                    
-                case 'string': // used for object lit detection..
-                    if (this.ts.lookT(-1).isType('lbrace') && this.ts.lookT(1).isType('colon')) {
+                case 'STRN': // used for object lit detection..
+                    if (this.ts.lookTok(-1).data == "{" && this.ts.lookTok(1).data == ":" ) {
                         // then we are in an object lit.. -> we need to flag the brace as such...
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
@@ -523,8 +523,8 @@ ScopeParser.prototype = {
                     
                      
                     var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
-                    if (isInObjectLitAr &&  this.ts.lookT(1).isType('colon') &&
-                        ( this.ts.lookT(-11).isType('lbrace') ||  this.ts.lookT(-1).isType('comma'))) {
+                    if (isInObjectLitAr &&  this.ts.lookTok(1).data == ":"  &&
+                        ( this.ts.lookTok(-1).data == "{"  ||  this.ts.lookTok(-1).data == "," )) {
                         // see if we can replace..
                         // remove the quotes..
                         var str = token.data.substring(1,token.data.length-1);
@@ -548,20 +548,21 @@ ScopeParser.prototype = {
                     }
                     break;
                 */
-                case 'identifier':
+                case 'NAME':
+                case 'KEYW':
                     symbol = token.data;
-                    if (this.ts.lookT(-1).isType('lbrace') && this.ts.lookT(1).isType('colon')) {
+                    if (this.ts.lookTok(-1).data == "{"  && this.ts.lookTok(1).data == ":") {
                         // then we are in an object lit.. -> we need to flag the brace as such...
                         isObjectLitAr.pop();
                         isObjectLitAr.push(true);
                         break;
                     }
                     var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
-                    if (isInObjectLitAr && this.ts.lookT(-1).isType('comma') && this.ts.lookT(1).isType('colon')) {
+                    if (isInObjectLitAr && this.ts.lookTok(-1).data == "," && this.ts.lookTok(1).data == ":") {
                         break;
                     }
                     
-                    if (this.ts.lookT(-1).isType('dot')) {
+                    if (this.ts.lookTok(-1).data == ".") {
                         //skip '.'
                         break;
                     }
@@ -574,7 +575,7 @@ ScopeParser.prototype = {
                     if (this.mode == 'BUILDING_SYMBOL_TREE') {
 
                         if (symbol == "eval") {
-                            if (this.ts.look(-1).isDoc()) {
+                            if (this.ts.look(-1).type == 'COMM') {
                                 // look for eval:var:noreplace\n
                                 var _t = this;
                                 this.ts.look(-1).data.replace(/eval:var:([a-z]+)/ig, function(m, a) {
@@ -603,7 +604,7 @@ ScopeParser.prototype = {
                         //println("<B>??</B>");
                         if (identifier == false) {
 
-                            if (symbol.length <= 3 && JSDOC.Scope.builtin.indexOf(symbol) < 0) {
+                            if (symbol.length <= 3 &&  Scope.builtin.indexOf(symbol) < 0) {
                                 // Here, we found an undeclared and un-namespaced symbol that is
                                 // 3 characters or less in length. Declare it in the global scope.
                                 // We don't need to declare longer symbols since they won't cause
@@ -624,7 +625,7 @@ ScopeParser.prototype = {
                     }
                     break;
             }
-            if (!this.ts.nextT()) break;
+            if (!this.ts.nextTok()) break;
         }
     },
 
@@ -638,9 +639,9 @@ ScopeParser.prototype = {
 
         //token = getToken(-1);
         //assert token.getType() == Token.CATCH;
-        token = this.ts.nextT();
+        token = this.ts.nextTok();
         //assert token.getType() == Token.LP; (
-        token = this.ts.nextT();
+        token = this.ts.nextTok();
         //assert token.getType() == Token.NAME;
         
         symbol = token.data;
@@ -657,7 +658,7 @@ ScopeParser.prototype = {
             identifier.refcount++;
         }
 
-        token = this.ts.nextT();
+        token = this.ts.nextTok();
         //assert token.getType() == Token.RP; // )
     },
     
@@ -665,15 +666,15 @@ ScopeParser.prototype = {
     {
 
         var symbol;
-        var  token;
+        var token;
         var currentScope  = false; 
         var fnScope = false;
         var identifier;
         //this.logR("<B>PARSING FUNCTION</B>");
         currentScope = this.scopes[this.scopes.length-1];
 
-        token = this.ts.nextT();
-        if (token.isType('identifier')) {
+        token = this.ts.nextTok();
+        if (token.type == "NAME") {
             if (this.mode == 'BUILDING_SYMBOL_TREE') {
                 // Get the name of the function and declare it in the current scope.
                 symbol = token.data;
@@ -682,7 +683,7 @@ ScopeParser.prototype = {
                 }
                 currentScope.declareIdentifier(symbol,token);
             }
-            token =  this.ts.nextT();
+            token =  this.ts.nextTok();
         }
 
         //assert token.getType() == Token.LP;
@@ -700,12 +701,12 @@ ScopeParser.prototype = {
         
         // Parse function arguments.
         var argpos = 0;
-        while (!this.ts.lookT().isType('rparen')) { //(token = consumeToken()).getType() != Token.RP) {
-            token = this.ts.nextT();
+        while (!this.ts.lookTok().data == ')') { //(token = consumeToken()).getType() != Token.RP) {
+            token = this.ts.nextTok();
            
             //assert token.getType() == Token.NAME ||
             //        token.getType() == Token.COMMA;
-            if (token.isType('identifier') && this.mode == 'BUILDING_SYMBOL_TREE') {
+            if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
                 symbol = token.data;
                 identifier = fnScope.declareIdentifier(symbol,token);
                 if (symbol == "$super" && argpos == 0) {
@@ -716,12 +717,12 @@ ScopeParser.prototype = {
             }
         }
 
-        token = this.ts.nextT();
+        token = this.ts.nextTok();
         // assert token.getType() == Token.LC;
         this.braceNesting++;
 
-        token = this.ts.nextT();
-        if (token.isType('string') && this.ts.lookT(1).isType('semicolon')) {
+        token = this.ts.nextTok();
+        if (token.type == "STRN" && this.ts.lookTok(1).data == ';') {
             /*
             
             NOT SUPPORTED YET!?!!?!
@@ -806,4 +807,4 @@ ScopeParser.prototype = {
         }
         return false;
     }
-});
\ No newline at end of file
+};
\ No newline at end of file