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 this.optvalues = false;
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" || this.title == "property" || this.title == "cfg") { // @config is deprecated
87 src = this.nibbleName(src);
91 if (Options.LOG) Options.LOG.warn(e);
95 // if type == @cfg, and matches (|....|...)
98 if (this.title == "cfg" && src.match(/^\([^)]+\)/)) {
99 var m = src.match(/^\(([^)]+)\)/);
100 if (m[1].match(/\|/)) {
101 var opts = m[1].split(/\|/);
102 this.optvalues = opts;
110 this.desc = src; // whatever is left
112 // example tags need to have whitespace preserved
113 if (this.title != "example") this.desc = this.desc.trim();
115 //if (JSDOC.PluginManager) {
116 // JSDOC.PluginManager.run("onDocTag", this);
121 Automatically called when this is stringified.
123 toString : function() {
129 Find and shift off the title of a tag.
133 nibbleTitle : function(src) {
134 if (typeof src != "string") throw "src must be a string not "+(typeof src);
136 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
138 if (parts && parts[1]) this.title = parts[1];
139 if (parts && parts[2]) src = parts[2];
146 Find and shift off the type of a tag.
147 @requires frame/String.js
151 nibbleType : function(src)
153 if (typeof src != "string") throw "src must be a string not "+(typeof src);
155 if (src.match(/^\s*\{/)) {
156 var typeRange = this.balance(src,"{", "}");
157 if (typeRange[1] == -1) {
158 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
160 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
161 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
162 src = src.substring(typeRange[1]+1);
170 Find and shift off the name of a tag.
171 @requires frame/String.js
175 nibbleName : function(src) {
176 if (typeof src != "string") throw "src must be a string not "+(typeof src);
181 if (src.charAt(0) == "[") {
182 var nameRange = this.balance(src,"[", "]");
183 if (nameRange[1] == -1) {
184 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
186 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
187 this.isOptional = true;
189 src = src.substring(nameRange[1]+1);
191 // has default value?
192 var nameAndValue = this.name.split("=");
193 if (nameAndValue.length) {
194 this.name = nameAndValue.shift().trim();
195 this.defaultValue = nameAndValue.join("=");
199 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
201 if (parts[1]) this.name = parts[1];
202 if (parts[2]) src = parts[2].trim();
210 balance : function(str, open, close) {
212 while (str.charAt(i) != open) {
213 if (i == str.length) return [-1, -1];
219 while (j < str.length) {
220 if (str.charAt(j) == open) balance++;
221 if (str.charAt(j) == close) balance--;
222 if (balance == 0) break;
224 if (j == str.length) return [-1, -1];
235 DocTag.fromDump = function(t)
237 var ns = new DocTag();
239 if (typeof(ns[i]) == "undefined") {
240 println("ERR:no default for DocTag:"+ i);