JSDOC/Packer.js
[gnome.introspection-doc-generator] / JSDOC / Packer.js
index 26257ff..0c56f3b 100644 (file)
@@ -415,9 +415,8 @@ Packer.prototype = {
         sp.mungeSymboltree();
         this.timerPrint("Munged Sym tree");
         print(sp.warnings.join("\n"));
+        this.timerPrint("Compressed");
         
-        
-        print("keepwhite? " + JSON.stringify(this.keepWhite));
         var out = CompressWhite(new TokenStream(toks), this, this.keepWhite); // do not kill whitespace..
         
         
@@ -447,21 +446,77 @@ Packer.prototype = {
      * -> this file will need inserting at the start of the application....
      * -> we need to generate 2 files, 
      * -> a reference used to do the translation, and the _T file..
+     *
+     *
+     * We store the trsum on the token...
      * 
      */
     
     writeTranslateFile : function(fn, minfile, toks) 
     {
         
-        var map = {};
+        var map = {};  // 'string=> md5sum'
         var _this = this;
-        toks.forEach(function (t) {
-            if (t.type == 'STRN' && t.name == 'DOUBLE_QUOTE') {
-                var sval = t.data.substring(1,t.data.length-1);
-                var ffn = fn.substring(_this.prefix.length);
-                map[sval] = _this.md5(ffn + '-' + sval);
+        var t, last, next;
+        
+        
+        var tokfind =  function (i,dir) {
+            while (1) {
+                if ((dir < 0) && (i < 0)) {
+                    return false;
+                }
+                if ((dir > 0) && (i >= toks.length)) {
+                    return false;
+                }
+                i += dir;
+                if (toks[i].type != 'WHIT') {
+                    return toks[i];
+                }
             }
-        })
+            return false;
+            
+        }
+         
+        
+        for (var i=0;i<toks.length;i++) {
+            
+            t = toks[i];
+            if (t.type != 'STRN') {
+                continue;
+            }
+            if (t.name != 'DOUBLE_QUOTE') {
+                continue;
+            }
+            
+            last = tokfind(i,-1);
+            next = tokfind(i,+1);
+            
+            // we have to ignore key values on objects
+            
+            // defined by
+            // last == '{' or ',' and
+            // next == ':'
+            
+            if (next &&
+                next.type == 'PUNC' &&
+                next.data == ':' && 
+                last && 
+                last.type == 'PUNC' &&
+                (last.data == ',' || last.data == '{')
+            ){
+                continue; // found object key... - we can not translate these
+            }
+                
+            var sval = t.data.substring(1,t.data.length-1);
+            var ffn = fn.substring(_this.prefix.length);
+            
+            t.trsum = _this.md5(ffn + '-' + sval);
+            map[sval] = t.trsum;
+            
+            
+            
+        }
+        
         
         var transfile = minfile + '.lang.trans';
         var transmd5 = minfile + '.lang';
@@ -518,6 +573,12 @@ Packer.prototype = {
             return data;
         }
         
+        if (typeof(tok.trsum) == 'undefined') {
+            return data;
+        }
+        
+        return '_T["' + tok.trsum + '"]';
+        
         var sval = data.substring(1,data.length-1);
         // we do not clean up... quoting here!??!!?!?!?!?