JSDOC/ScopeParser.vala
[gnome.introspection-doc-generator] / JSDOC / ScopeParser.vala
index cbe46cd..778d2e9 100644 (file)
@@ -3,17 +3,35 @@
 
 namespace JSDOC {
 
+       public enum ScopeParserMode {
+               BUILDING_SYMBOL_TREE,
+               PASS2_SYMBOL_TREE
+       }
+
+
        public class ScopeParser : Object {
        
-       
+       TokenStream ts;
        Gee.ArrayList<string> warnings;
        
        bool debug = false;
        string[] idents;
        
+       
+    Scope global ;
+    ScopeParserMode mode;
+    //braceNesting : 0,
+    Gee.HashMap<int,Scope> indexedScopes;
+    bool munge =  true;
+
+       
+       
        public ScopeParser(TokenStream ts) {
                this.ts = ts; // {TokenStream}
                this.warnings = new Gee.ArrayList<string>();
+               this.globalScope = new  Scope(-1, false, -1, '');
+               this.indexedScopes = new Gee.HashMap<int,Scope>();
+               
                //this.indexedg = {};
                //this.timer = new Date() * 1;
                this.idents = { 
@@ -96,18 +114,12 @@ namespace JSDOC {
     
     // defaults should not be initialized here =- otherwise they get duped on new, rather than initalized..
     
-    ts : false,
-    global : false,
-    mode : "", //"BUILDING_SYMBOL_TREE",
-    braceNesting : 0,
-    indexedScopes : false,
-    munge: true,
-
+  
 
 
 
 
-    buildSymbolTree : function()
+    void buildSymbolTree()
     {
         //println("<PRE>");
         
@@ -118,15 +130,18 @@ namespace JSDOC {
         
         
         this.globalScope = new  Scope(-1, false, -1, '');
-        this.indexedScopes = { 0 : this.globalScope };
+        this.indexedScopes = new Gee.HashMap<int,Scope>();
+        this.indexedScopes.set(0, this.globalScope );
+        
+        this.mode = ScopeParserMode.BUILDING_SYMBOL_TREE;
         
-        this.mode = 'BUILDING_SYMBOL_TREE';
         this.parseScope(this.globalScope);
         
         //print("---------------END PASS 1 ---------------- ");
         
-    },
-    mungeSymboltree : function()
+    }
+    
+    void mungeSymboltree()
     {
 
         if (!this.munge) {
@@ -156,7 +171,7 @@ namespace JSDOC {
 
         this.ts.rewind();
         this.braceNesting = 0;
-        this.mode = 'PASS2_SYMBOL_TREE';
+        this.mode = ScopeParserMode.PASS2_SYMBOL_TREE;
         
         //println("MUNGING?");
         
@@ -166,39 +181,37 @@ namespace JSDOC {
         
         
         this.globalScope.munge();
-    },
+    }
 
 
-    log : function(str)
+    void log(string str)
     {
-        print ("                    ".substring(0, this.braceNesting*2) + str);
+        print(str);
+        //print ("                    ".substring(0, this.braceNesting*2) + str);
         
         //println("<B>LOG:</B>" + htmlescape(str) + "<BR/>\n");
-    },
-    logR : function(str)
+    }
+    void logR (string str)
     {
             //println("<B>LOG:</B>" + str + "<BR/>");
-    },
+    }
 
      
     
 
 
-    parseScope : function(scope) // parse a token stream..
+    void parseScope(Scope scope) // parse a token stream..
     {
         //this.timerPrint("parseScope EnterScope"); 
         //this.log(">>> ENTER SCOPE" + this.scopes.length);
-        var symbol;
-        var token;
-        
-        var identifier;
-
+       
         var expressionBraceNesting = this.braceNesting + 0;
         
         var parensNesting = 0;
         
-        var isObjectLitAr = [ false ];
-        var isInObjectLitAr;
+        var isObjectLitAr = new Gee.ArrayList<bool>();
+        isObjectLitAr.add(false);
+     
         
        
         //var scopeIndent = ''; 
@@ -210,8 +223,8 @@ namespace JSDOC {
         
         
         
-        token = this.ts.lookTok(1);
-        while (token) {
+        var token = this.ts.lookTok(1);
+        while (token != null) {
           //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
             //this.dumpToken(token , this.scopes, this.braceNesting);
             //print('SCOPE:' + token.toString());
@@ -230,20 +243,21 @@ namespace JSDOC {
                         token = this.ts.nextTok();
                         //!this.debug|| print( token.toString());
                        // print('SCOPE-VAR-VAL:' + JSON.stringify(token, null, 4));
-                        if (!token) { // can return false at EOF!
+                        if (token == null) { // can return false at EOF!
                             break;
                         }
-                        if (token.name == "VAR" || token.data == ',') { // kludge..
+                        if (token.name == "VAR" || token.data == ",") { // kludge..
                             continue;
                         }
                         //this.logR("parseScope GOT VAR  : <B>" + token.toString() + "</B>"); 
                         if (token.type != "NAME") {
-                            for(var i = Math.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) {
+                               
+                            for(var i = Int.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) {
                                 print(this.ts.tokens[i].toString());
                             }
                             
                             print( "var without ident");
-                            Seed.quit()
+                            Process.exit (0);
                         }