1 //<script type="text/javascript">
4 XObject = imports.XObject.XObject;
6 Options = imports.Options.Options;
10 * DocTag - represents a single A=b tag.
16 DocTag = XObject.define(
27 this.isOptional = false;
28 this.defaultValue = "";
30 if (typeof src != "undefined") {
48 var ret = { '*object' : 'DocTag' };
51 switch (typeof(this[i])) {
59 ret[i] = this[i]; continue;
61 print("unknown type:" + typeof(this[i]));
71 Populate the properties of this from the given tag src.
74 parse : function(src) {
75 if (typeof src != "string") throw "src must be a string not "+(typeof src);
78 src = this.nibbleTitle(src);
79 //if (JSDOC.PluginManager) {
80 // JSDOC.PluginManager.run("onDocTagSynonym", this);
83 src = this.nibbleType(src);
85 // only some tags are allowed to have names.
86 if (this.title == "param" ||
87 this.title == "property" ||
88 this.title == "cfg") {
89 // @config is deprecated
91 src = this.nibbleName(src);
92 // support @param name {Type} ...
94 src = this.nibbleType(src);
99 if (Options.LOG) Options.LOG.warn(e);
102 this.desc = src; // whatever is left
104 // example tags need to have whitespace preserved
105 if (this.title != "example") this.desc = this.desc.trim();
107 //if (JSDOC.PluginManager) {
108 // JSDOC.PluginManager.run("onDocTag", this);
113 Automatically called when this is stringified.
115 toString : function() {
121 Find and shift off the title of a tag.
125 nibbleTitle : function(src) {
126 if (typeof src != "string") throw "src must be a string not "+(typeof src);
128 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
130 if (parts && parts[1]) this.title = parts[1];
131 if (parts && parts[2]) src = parts[2];
138 Find and shift off the type of a tag.
139 @requires frame/String.js
143 nibbleType : function(src)
145 if (typeof src != "string") throw "src must be a string not "+(typeof src);
147 if (src.match(/^\s*\{/)) {
148 var typeRange = this.balance(src,"{", "}");
149 if (typeRange[1] == -1) {
150 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
152 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
153 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
154 src = src.substring(typeRange[1]+1);
162 Find and shift off the name of a tag.
163 @requires frame/String.js
167 nibbleName : function(src) {
168 if (typeof src != "string") throw "src must be a string not "+(typeof src);
173 if (src.charAt(0) == "[") {
174 var nameRange = this.balance(src,"[", "]");
175 if (nameRange[1] == -1) {
176 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
178 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
179 this.isOptional = true;
181 src = src.substring(nameRange[1]+1);
183 // has default value?
184 var nameAndValue = this.name.split("=");
185 if (nameAndValue.length) {
186 this.name = nameAndValue.shift().trim();
187 this.defaultValue = nameAndValue.join("=");
191 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
193 if (parts[1]) this.name = parts[1];
194 if (parts[2]) src = parts[2].trim();
202 balance : function(str, open, close) {
204 while (str.charAt(i) != open) {
205 if (i == str.length) return [-1, -1];
211 while (j < str.length) {
212 if (str.charAt(j) == open) balance++;
213 if (str.charAt(j) == close) balance--;
214 if (balance == 0) break;
216 if (j == str.length) return [-1, -1];
227 DocTag.fromDump = function(t)
229 var ns = new DocTag();
231 if (typeof(ns[i]) == "undefined") {
232 println("ERR:no default for DocTag:"+ i);