JSDOC/ScopeParser.vala
[gnome.introspection-doc-generator] / JSDOC / Collapse.vala
index 462d909..758a282 100644 (file)
@@ -42,48 +42,55 @@ namespace JSDOC {
                   // console.dump(ar);
                    
                }
+               
+               // put spaces into prefix of tokens..
     
-        spaces : function () {
-            var ar = [];
-            var pref = [];
+        void spaces () 
+        {
+            var ar = new Gee.ArrayList<Token>();
+            var pref =  new Gee.ArrayList<Token>();
             
-            var tok;
+
             
-            for (var i = 0; i < this.tokens.length; i ++) {
-                tok = this.tokens[i];
+            for (var i = 0; i < this.tokens.size; i ++) {
+                var tok = this.tokens[i];
                 if (tok.is("COMM") || tok.is("WHIT")) {
-                    pref.push(tok);
+                    pref.add(tok);
                     continue;
                 }
                 tok.prefix = '';
-                if (pref.length) {
-                    pref.forEach( function(e) {
-                        if (!e) {
-                            return;
-                        }
+                if (pref.size > 0) {
+                       foreach(var e in pref) {
                         tok.prefix += e.data;
-                    })
+                    }
+                    pref =  new Gee.ArrayList<Token>(); // reset pref..
                 }
                 
-                ar.push(tok);
-                pref=  [];
+                ar.add(tok);
+                
+
                 
             }
             this.tokens = ar;
             
-        },
-        collapse : function(ar) {
+        }
+        
+        
+        
+        Gee.ArrayList<Token>  collapse(Gee.ArrayList<Token>  ar) 
+        {
             
-            var st = new  TokenStream(ar);
-            var ret = [];
+            var st = new TokenStream(ar);
+            var ret = new Gee.ArrayList<Token>();
             
             while (true) {
                 var  tok = st.look(1,true);
-                if (!tok || !tok.is) {
+                if (tok == null) {
                   //  Seed.print(TokenStream.toString(ret));
                     return ret;
                 }
                 // console.log(tok.data);
+                
                 switch(tok.type) {
                     case "VOID": 
                         return ret; //EOF
@@ -107,39 +114,41 @@ namespace JSDOC {
                                 var start = st.cursor;
                                 st.next(1);
                                 var add = st.balance(tok.data);
-                                if (!add) {
-                                    console.dump(tok);
-                                    console.dump(start + '...' + st.cursor);
-                                    console.dump(st.tokens);
+                               // if (!add) {
+                                    //console.dump(tok);
+                                    //console.dump(start + '...' + st.cursor);
+                                    //console.dump(st.tokens);
                                  
-                                }
-                                if (add) {
-                                    add.shift();
+                                //}
+                                if (add.size > 0) {
+                                               add.remove_at(0);  // remove the first element... (as it's the 
                                 }
                                 //Seed.print("ADD");
                                 //Seed.print(JSON.stringify(add, null,4));
                                 
                                 
                                 
-                                var toks = add ? this.collapse(add) : [];
-                                tok.items = false;
-                                tok.props = false;
-                                
+                                var toks = add.size > 0 ? this.collapse(add) : add;
                                 
+                                tok.items = new Gee.ArrayList<Gee.ArrayList<Token>>(); //?? needed?
+                                tok.props = new Gee.HashMap<string,Gee.ArrayList<Token>>();
+                                 
                                 
-                                if (tok.data != '{') {
+                                if (tok.data != "{") {
                                     // paramters or array elements..
-                                    tok.items = this.toItems(toks, [',']);
+                                    tok.items = this.toItems(toks, ",");
                                 } else {
                                     // check for types.. it could be a list of statements.. or object
+                                    // format "{" "xXXX" ":" << looks for the ':'.. seems to work.. not sure if it's foolproof...
                                     
                                     var ost = new  TokenStream(toks);
                                     //console.dump(ost.look(2,true) );
                                     if (ost.look(2,true) && ost.look(2,true).data == ":") {
+                                               // object properties...
                                         tok.props = this.toProps(toks);
                                     } else {
                                         // list of statemetns..
-                                        tok.items = this.toItems(toks,[ ';', '{'] );;
+                                        tok.items = this.toItems(toks, ";{");;
                                     }
                                     
                                     
@@ -178,39 +187,41 @@ namespace JSDOC {
             
             
             
-        },
-        toItems : function(ar,sep)
+        }
+        // array of arrays of tokens
+        Gee.ArrayList<Gee.ArrayList<Token>>  toItems(Gee.ArrayList<Token>  ar, string sep)
         {
-            var ret = [];
-            var g = [];
+            var ret = new Gee.ArrayList<Gee.ArrayList<Token>>() ;
+            var g =  new Gee.ArrayList<Token>() ;
               
             for (var i = 0; i < ar.length; i ++) {
-                if (sep.indexOf(ar[i].data) < 0) {
-                    g.push(ar[i]);
+                if (sep.index_of(ar.get(i).data) < 0) {
+                    g.add(ar.get(i));
                     continue;
                 }
                 // var a=..., b =...
-                if ((ar[i].data != ';') && g.length && (g[0].name == "VAR")) {;
-                    g.push(ar[i]);
+                if ((ar.get(i).data != ";") && g.size> 0  && (g[0].name == "VAR")) {;
+                    g.add(ar.get(i));
                     continue;
                 }
                 
-                g.push(ar[i]);
-                ret.push(g);
-                g = [];
+                g.add(ar.get(i));
+                ret.add(g);
+                g =  new Gee.ArrayList<Token>() ;
                 
             }
             // last..
-            if (g.length) {
-                ret.push(g);
+            if (g.size > 0) {
+                ret.add(g);
             }
             return ret;
             
-        },
-        toProps : function(ar)
+        }
+        
+        Gee.HashMap<string,Gee.ArrayList<Token>> toProps (Gee.ArrayList<Token> ar)
         {
             
-            var ret = { }
+            var ret = new Gee.HashMap<string,Gee.ArrayList<Token>>();
                
             var g = { key : '', val: [] }