JSDOC/TokenReader.js
[gnome.introspection-doc-generator] / JSDOC / DocTag.js
index d9fa27b..b7f25ca 100644 (file)
@@ -13,6 +13,12 @@ Options = imports.Options.Options;
  
  
 DocTag = XObject.define(
+
+/**
+ * @constructor
+ * @arg {String} src
+ */
+
     function(src) {
         this.title        = "";
         this.type         = "";
@@ -20,6 +26,7 @@ DocTag = XObject.define(
         this.isOptional   = false;
         this.defaultValue = "";
         this.desc         = "";
+        this.optvalues    = false;
         if (typeof src != "undefined") {
             this.parse(src);
         }
@@ -33,12 +40,42 @@ DocTag = XObject.define(
         isOptional : false,
         defaultValue : '',
         desc : '',
-        /* qdump needed for cahcing?
-        toQDump  :function(t)
+        /**
+         * serialize..
+         */
+        toJSON :function(t)
         {
-            return JSDOC.toQDump(t, 'JSDOC.DocTag.fromDump({', '})', new JSDOC.DocTag());
-        } ,
-        */
+            var ret = { '*object' : 'DocTag' };
+            
+            for (var i in this) {
+                if (i == 'optvalues') { 
+                    ret[i] = this.optvalues;
+                    continue;
+                }
+                
+                switch (typeof(this[i])) {
+                    case 'function':
+                       continue;
+                       continue;
+                        
+                    case 'string':
+                    case 'number':
+                    case 'boolean':                    
+                        ret[i] = this[i]; continue;
+                        
+                        
+                        
+                    default:
+                        
+                        print("unknown type: (" + i + ")"  + typeof(this[i]));
+                        this.toJSON = null;
+                        print(JSON.stringify(this));;
+                        Seed.quit();
+                   }
+            }
+            return ret;
+        },
+        
 
 
         /**
@@ -65,6 +102,26 @@ DocTag = XObject.define(
                 if (Options.LOG) Options.LOG.warn(e);
                 else throw e;
             }
+            
+            // if type == @cfg, and matches (|....|...)
+            
+            src = src.trim();
+            if (this.title == "cfg" && src.match(/^\([^)]+\)/)) {
+                var m = src.match(/^\(([^)]+)\)/);
+                print(m);
+                if (m[1].match(/\|/)) {
+                    var opts = m[1].trim().split(/\s*\|\s*/);
+                    this.optvalues = opts;
+                    src = src.substring(m[0].length).trim();
+                    print(src);
+                    
+                    
+                }
+                
+                
+            }
+            
+            
             this.desc = src; // whatever is left
             
             // example tags need to have whitespace preserved
@@ -111,7 +168,7 @@ DocTag = XObject.define(
             if (typeof src != "string") throw "src must be a string not "+(typeof src);
             
             if (src.match(/^\s*\{/)) {
-                var typeRange = src.balance("{", "}");
+                var typeRange = this.balance(src,"{", "}");
                 if (typeRange[1] == -1) {
                     throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
                 }
@@ -137,7 +194,7 @@ DocTag = XObject.define(
             
             // is optional?
             if (src.charAt(0) == "[") {
-                var nameRange = src.balance("[", "]");
+                var nameRange = this.balance(src,"[", "]");
                 if (nameRange[1] == -1) {
                     throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
                 }
@@ -163,7 +220,30 @@ DocTag = XObject.define(
             }  
 
             return src;
-        }
+        },
+        
+        balance : function(str, open, close) {
+            var i = 0;
+            while (str.charAt(i) != open) {
+                if (i == str.length) return [-1, -1];
+                i++;
+            }
+            
+            var j = i+1;
+            var balance = 1;
+            while (j < str.length) {
+                if (str.charAt(j) == open) balance++;
+                if (str.charAt(j) == close) balance--;
+                if (balance == 0) break;
+                j++;
+                if (j == str.length) return [-1, -1];
+            }
+            
+            return [i, j];
+}
+
+        
+        
 });
 
 // cached support?