JSDOC/Packer.js
[gnome.introspection-doc-generator] / JSDOC / Packer.js
index aebd8a3..8f7edff 100644 (file)
@@ -78,7 +78,7 @@ Packer = function(cfg)
     if ((typeof(cfg.tmpDir) != 'undefined') && (!cfg.cleanup)) {
         this.cleanup = false; // do not clean up files.. = as tmpdir is set.
     }
-    this.tmpFiles = [];
     this.timer =  new Date() * 1;
     this.packAll();
  
@@ -104,7 +104,6 @@ Packer.prototype = {
     
     translateJson : '', // json based list of strings in all files.
    
-    tmpFiles : false, // list of temporary files - cleaned up at end..
     /**
      * @prop cleanup {Boolean} (optional) clean up temp files after done - 
      *    Defaults to false if you set tmpDir, otherwise true.
@@ -167,6 +166,9 @@ Packer.prototype = {
             
             print("COMPRESSING ");
             //var codeComp = pack(str, 10, 0, 0);
+            if (File.exists(minfile)) {
+                File.remove(minfile);
+            }
             var str = File.read(files);
             var str = this.pack(str, files, minfile);
             if (str.length) {
@@ -181,47 +183,59 @@ Packer.prototype = {
             
                
             print("MERGING LANGUAGE");
-            File.write(outpath, "if (typeof(_T) == 'undefined') { _T={};}\n");
+            File.write(this.target, "if (typeof(_T) == 'undefined') { _T={};}\n");
+            
             
-            var transfileAll =  bpath + '/_translation_.js';
-            File.write(transfileAll, "");
-            for(var i=0; i < files.length; i++)  {
-                var transfile= bpath + '/' +files[i].substr(spath.length+1).replace(/\//g, '.') +'.lang.trans';
-                var transmd5 = bpath + '/' +files[i].substr(spath.length+1).replace(/\//g, '.') +'.lang';
+            File.write(this.translateJson, "");
+            for(var i=0; i < this.files.length; i++)  {
+                var file = this.files[i];
+                var transfile= this.tmpDir + '/' +file.replace(/\//g, '.') +'.lang.trans';
+                var transmd5 = this.tmpDir  + '/' +file.replace(/\//g, '.') +'.lang';
                 if (File.exists(transmd5)) {
                     var str = File.read(transmd5);
                     if (str.length) {
-                        File.append(outpath, str + "\n");
+                        File.append(this.target, str + "\n");
+                    }
+                    if (this.cleanup) {
+                        File.remove(transmd5);
                     }
                 }
                 if (File.exists(transfile)) {
                     var str = File.read(transfile);
                     if (str.length) {
-                        File.append(transfileAll, str);
+                        File.append(this.translateJson, str);
+                    }
+                    if (this.cleanup) {
+                        File.remove(transfile);
                     }
                 }
                 
                
             }
         }
+        
         print("MERGING SOURCE");
         
         for(var i=0; i < files.length; i++)  {
-         
-            var minfile = bpath + '/' +files[i].substr(spath.length+1).replace(/\//g, '.');
+            
+            var minfile = bpath + '/' + this.files.replace(/\//g, '.');
+            
+            
             if (!File.exists(minfile)) {
                 continue;
             }
             var str = File.read(minfile);
             print("using MIN FILE  "+ minfile);
             if (str.length) {
-                File.append(outpath, str + "\n");
+                File.append(this.target, str + "\n");
+            }
+            if (this.cleanup) {
+                File.remove(minfile);
             }
+            
         }
         
-        
-        //File.append(dout, "\n");// end the function 
-        
+         
     
     
     },
@@ -237,15 +251,15 @@ Packer.prototype = {
     pack : function (str,fn,minfile)
     {
     
-        var tr = new  TokenReader();
+        var tr = new  TokenReader(  { keepDocs :true, keepWhite : true,  keepComments : true, sepIdents : true });
         this.timerPrint("START" + fn);
         
         // we can load translation map here...
         
-        var toks = tr.tokenize(str,false); // dont merge xxx + . + yyyy etc.
+        var toks = tr.tokenize(new TextStream(str)); // dont merge xxx + . + yyyy etc.
         
         // at this point we can write a language file...
-        if (this.translate) {
+        if (this.translateJson) {
             this.writeTranslateFile(fn, minfile, tr.translateMap);
         }
         
@@ -253,12 +267,9 @@ Packer.prototype = {
         
         // and replace if we are generating a different language..
         
-        
-        
-        
         this.timerPrint("Tokenized");
         //return;//
-        var sp = new ScopeParser(new TokenStream(toks, str.length));
+        var sp = new ScopeParser(new TokenStream(toks));
         this.timerPrint("Converted to Parser");
         sp.packer = this;
         sp.buildSymbolTree();
@@ -270,6 +281,19 @@ Packer.prototype = {
         this.timerPrint("Compressed");
         return out;
         
+        
+        
+     
+    var ts = new   TokenStream(toks);
+   // ts.dump();
+    var sp = new  ScopeParser(ts);
+    sp.buildSymbolTree();
+    sp.mungeSymboltree();
+    print(sp.warnings.join("\n"));
+    var out =  CompressWhite(sp.ts);
+    return out;
+        
+        
     },
     
     timerPrint: function (str) {