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") {
50 if (Symbol.hide.indexOf(i) > -1) {
53 switch (typeof(this[i])) {
60 ret[i] = array2object(this[i],true);
65 ret[i] = this[i].toArray();
69 print("object? :" + i);
76 ret[i] = this[i]; continue;
78 print("unknown type:" + typeof(this[i]));
88 Populate the properties of this from the given tag src.
91 parse : function(src) {
92 if (typeof src != "string") throw "src must be a string not "+(typeof src);
95 src = this.nibbleTitle(src);
96 //if (JSDOC.PluginManager) {
97 // JSDOC.PluginManager.run("onDocTagSynonym", this);
100 src = this.nibbleType(src);
102 // only some tags are allowed to have names.
103 if (this.title == "param" || this.title == "property" || this.title == "cfg") { // @config is deprecated
104 src = this.nibbleName(src);
108 if (Options.LOG) Options.LOG.warn(e);
111 this.desc = src; // whatever is left
113 // example tags need to have whitespace preserved
114 if (this.title != "example") this.desc = this.desc.trim();
116 //if (JSDOC.PluginManager) {
117 // JSDOC.PluginManager.run("onDocTag", this);
122 Automatically called when this is stringified.
124 toString : function() {
130 Find and shift off the title of a tag.
134 nibbleTitle : function(src) {
135 if (typeof src != "string") throw "src must be a string not "+(typeof src);
137 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
139 if (parts && parts[1]) this.title = parts[1];
140 if (parts && parts[2]) src = parts[2];
147 Find and shift off the type of a tag.
148 @requires frame/String.js
152 nibbleType : function(src)
154 if (typeof src != "string") throw "src must be a string not "+(typeof src);
156 if (src.match(/^\s*\{/)) {
157 var typeRange = this.balance(src,"{", "}");
158 if (typeRange[1] == -1) {
159 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
161 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
162 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
163 src = src.substring(typeRange[1]+1);
171 Find and shift off the name of a tag.
172 @requires frame/String.js
176 nibbleName : function(src) {
177 if (typeof src != "string") throw "src must be a string not "+(typeof src);
182 if (src.charAt(0) == "[") {
183 var nameRange = this.balance(src,"[", "]");
184 if (nameRange[1] == -1) {
185 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
187 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
188 this.isOptional = true;
190 src = src.substring(nameRange[1]+1);
192 // has default value?
193 var nameAndValue = this.name.split("=");
194 if (nameAndValue.length) {
195 this.name = nameAndValue.shift().trim();
196 this.defaultValue = nameAndValue.join("=");
200 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
202 if (parts[1]) this.name = parts[1];
203 if (parts[2]) src = parts[2].trim();
211 balance : function(str, open, close) {
213 while (str.charAt(i) != open) {
214 if (i == str.length) return [-1, -1];
220 while (j < str.length) {
221 if (str.charAt(j) == open) balance++;
222 if (str.charAt(j) == close) balance--;
223 if (balance == 0) break;
225 if (j == str.length) return [-1, -1];
236 DocTag.fromDump = function(t)
238 var ns = new DocTag();
240 if (typeof(ns[i]) == "undefined") {
241 println("ERR:no default for DocTag:"+ i);