1 //<script type="text/javascript">
4 XObject = imports.XObject.XObject;
6 Options = imports.Options.Options;
10 * DocTag - represents a single A=b tag.
19 DocTag = XObject.define(
30 this.isOptional = false;
31 this.defaultValue = "";
33 if (typeof src != "undefined") {
51 var ret = { '*object' : 'DocTag' };
54 switch (typeof(this[i])) {
62 ret[i] = this[i]; continue;
64 print("unknown type:" + typeof(this[i]));
74 Populate the properties of this from the given tag src.
77 parse : function(src) {
78 if (typeof src != "string") throw "src must be a string not "+(typeof src);
81 src = this.nibbleTitle(src);
82 //if (JSDOC.PluginManager) {
83 // JSDOC.PluginManager.run("onDocTagSynonym", this);
86 src = this.nibbleType(src);
88 // only some tags are allowed to have names.
89 if (this.title == "param" ||
90 this.title == "property" ||
91 this.title == "cfg") {
92 // @config is deprecated
94 src = this.nibbleName(src);
95 // support @param name {Type} ...
97 src = this.nibbleType(src);
102 if (Options.LOG) Options.LOG.warn(e);
105 this.desc = src; // whatever is left
107 // example tags need to have whitespace preserved
108 if (this.title != "example") this.desc = this.desc.trim();
110 //if (JSDOC.PluginManager) {
111 // JSDOC.PluginManager.run("onDocTag", this);
116 Automatically called when this is stringified.
118 toString : function() {
124 Find and shift off the title of a tag.
128 nibbleTitle : function(src) {
129 if (typeof src != "string") throw "src must be a string not "+(typeof src);
131 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
133 if (parts && parts[1]) this.title = parts[1];
134 if (parts && parts[2]) src = parts[2];
141 Find and shift off the type of a tag.
142 @requires frame/String.js
146 nibbleType : function(src)
148 if (typeof src != "string") throw "src must be a string not "+(typeof src);
150 if (src.match(/^\s*\{/)) {
151 var typeRange = this.balance(src,"{", "}");
152 if (typeRange[1] == -1) {
153 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
155 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
156 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
157 src = src.substring(typeRange[1]+1);
165 Find and shift off the name of a tag.
166 @requires frame/String.js
170 nibbleName : function(src) {
171 if (typeof src != "string") throw "src must be a string not "+(typeof src);
176 if (src.charAt(0) == "[") {
177 var nameRange = this.balance(src,"[", "]");
178 if (nameRange[1] == -1) {
179 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
181 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
182 this.isOptional = true;
184 src = src.substring(nameRange[1]+1);
186 // has default value?
187 var nameAndValue = this.name.split("=");
188 if (nameAndValue.length) {
189 this.name = nameAndValue.shift().trim();
190 this.defaultValue = nameAndValue.join("=");
194 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
196 if (parts[1]) this.name = parts[1];
197 if (parts[2]) src = parts[2].trim();
205 balance : function(str, open, close) {
207 while (str.charAt(i) != open) {
208 if (i == str.length) return [-1, -1];
214 while (j < str.length) {
215 if (str.charAt(j) == open) balance++;
216 if (str.charAt(j) == close) balance--;
217 if (balance == 0) break;
219 if (j == str.length) return [-1, -1];
230 DocTag.fromDump = function(t)
232 var ns = new DocTag();
234 if (typeof(ns[i]) == "undefined") {
235 println("ERR:no default for DocTag:"+ i);