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;
103 src = src.substring(m[0].length).trim();
112 this.desc = src; // whatever is left
114 // example tags need to have whitespace preserved
115 if (this.title != "example") this.desc = this.desc.trim();
117 //if (JSDOC.PluginManager) {
118 // JSDOC.PluginManager.run("onDocTag", this);
123 Automatically called when this is stringified.
125 toString : function() {
131 Find and shift off the title of a tag.
135 nibbleTitle : function(src) {
136 if (typeof src != "string") throw "src must be a string not "+(typeof src);
138 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
140 if (parts && parts[1]) this.title = parts[1];
141 if (parts && parts[2]) src = parts[2];
148 Find and shift off the type of a tag.
149 @requires frame/String.js
153 nibbleType : function(src)
155 if (typeof src != "string") throw "src must be a string not "+(typeof src);
157 if (src.match(/^\s*\{/)) {
158 var typeRange = this.balance(src,"{", "}");
159 if (typeRange[1] == -1) {
160 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
162 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
163 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
164 src = src.substring(typeRange[1]+1);
172 Find and shift off the name of a tag.
173 @requires frame/String.js
177 nibbleName : function(src) {
178 if (typeof src != "string") throw "src must be a string not "+(typeof src);
183 if (src.charAt(0) == "[") {
184 var nameRange = this.balance(src,"[", "]");
185 if (nameRange[1] == -1) {
186 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
188 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
189 this.isOptional = true;
191 src = src.substring(nameRange[1]+1);
193 // has default value?
194 var nameAndValue = this.name.split("=");
195 if (nameAndValue.length) {
196 this.name = nameAndValue.shift().trim();
197 this.defaultValue = nameAndValue.join("=");
201 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
203 if (parts[1]) this.name = parts[1];
204 if (parts[2]) src = parts[2].trim();
212 balance : function(str, open, close) {
214 while (str.charAt(i) != open) {
215 if (i == str.length) return [-1, -1];
221 while (j < str.length) {
222 if (str.charAt(j) == open) balance++;
223 if (str.charAt(j) == close) balance--;
224 if (balance == 0) break;
226 if (j == str.length) return [-1, -1];
237 DocTag.fromDump = function(t)
239 var ns = new DocTag();
241 if (typeof(ns[i]) == "undefined") {
242 println("ERR:no default for DocTag:"+ i);