1 //<script type="text/javascript">
4 XObject = imports.XObject.XObject;
6 Options = imports.Options.Options;
10 * DocTag - represents a single A=b tag.
15 DocTag = XObject.define(
26 this.isOptional = false;
27 this.defaultValue = "";
29 if (typeof src != "undefined") {
47 var ret = { '*object' : 'DocTag' };
50 switch (typeof(this[i])) {
58 ret[i] = this[i]; continue;
60 print("unknown type:" + typeof(this[i]));
70 Populate the properties of this from the given tag src.
73 parse : function(src) {
74 if (typeof src != "string") throw "src must be a string not "+(typeof src);
77 src = this.nibbleTitle(src);
78 //if (JSDOC.PluginManager) {
79 // JSDOC.PluginManager.run("onDocTagSynonym", this);
82 src = this.nibbleType(src);
84 // only some tags are allowed to have names.
85 if (this.title == "param" ||
86 this.title == "property" ||
87 this.title == "cfg") {
88 // @config is deprecated
90 src = this.nibbleName(src);
91 // support @param name {Type} ...
93 src = this.nibbleType(src);
98 if (Options.LOG) Options.LOG.warn(e);
101 this.desc = src; // whatever is left
103 // example tags need to have whitespace preserved
104 if (this.title != "example") this.desc = this.desc.trim();
106 //if (JSDOC.PluginManager) {
107 // JSDOC.PluginManager.run("onDocTag", this);
112 Automatically called when this is stringified.
114 toString : function() {
120 Find and shift off the title of a tag.
124 nibbleTitle : function(src) {
125 if (typeof src != "string") throw "src must be a string not "+(typeof src);
127 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
129 if (parts && parts[1]) this.title = parts[1];
130 if (parts && parts[2]) src = parts[2];
137 Find and shift off the type of a tag.
138 @requires frame/String.js
142 nibbleType : function(src)
144 if (typeof src != "string") throw "src must be a string not "+(typeof src);
146 if (src.match(/^\s*\{/)) {
147 var typeRange = this.balance(src,"{", "}");
148 if (typeRange[1] == -1) {
149 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
151 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
152 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
153 src = src.substring(typeRange[1]+1);
161 Find and shift off the name of a tag.
162 @requires frame/String.js
166 nibbleName : function(src) {
167 if (typeof src != "string") throw "src must be a string not "+(typeof src);
172 if (src.charAt(0) == "[") {
173 var nameRange = this.balance(src,"[", "]");
174 if (nameRange[1] == -1) {
175 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
177 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
178 this.isOptional = true;
180 src = src.substring(nameRange[1]+1);
182 // has default value?
183 var nameAndValue = this.name.split("=");
184 if (nameAndValue.length) {
185 this.name = nameAndValue.shift().trim();
186 this.defaultValue = nameAndValue.join("=");
190 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
192 if (parts[1]) this.name = parts[1];
193 if (parts[2]) src = parts[2].trim();
201 balance : function(str, open, close) {
203 while (str.charAt(i) != open) {
204 if (i == str.length) return [-1, -1];
210 while (j < str.length) {
211 if (str.charAt(j) == open) balance++;
212 if (str.charAt(j) == close) balance--;
213 if (balance == 0) break;
215 if (j == str.length) return [-1, -1];
226 DocTag.fromDump = function(t)
228 var ns = new DocTag();
230 if (typeof(ns[i]) == "undefined") {
231 println("ERR:no default for DocTag:"+ i);