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(/^\(([^)]+)\)/);
101 if (m[1].match(/\|/)) {
102 var opts = m[1].split(/\|/);
103 this.optvalues = opts;
104 src = src.substring(m[0].length).trim();
115 this.desc = src; // whatever is left
117 // example tags need to have whitespace preserved
118 if (this.title != "example") this.desc = this.desc.trim();
120 //if (JSDOC.PluginManager) {
121 // JSDOC.PluginManager.run("onDocTag", this);
126 Automatically called when this is stringified.
128 toString : function() {
134 Find and shift off the title of a tag.
138 nibbleTitle : function(src) {
139 if (typeof src != "string") throw "src must be a string not "+(typeof src);
141 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
143 if (parts && parts[1]) this.title = parts[1];
144 if (parts && parts[2]) src = parts[2];
151 Find and shift off the type of a tag.
152 @requires frame/String.js
156 nibbleType : function(src)
158 if (typeof src != "string") throw "src must be a string not "+(typeof src);
160 if (src.match(/^\s*\{/)) {
161 var typeRange = this.balance(src,"{", "}");
162 if (typeRange[1] == -1) {
163 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
165 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
166 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
167 src = src.substring(typeRange[1]+1);
175 Find and shift off the name of a tag.
176 @requires frame/String.js
180 nibbleName : function(src) {
181 if (typeof src != "string") throw "src must be a string not "+(typeof src);
186 if (src.charAt(0) == "[") {
187 var nameRange = this.balance(src,"[", "]");
188 if (nameRange[1] == -1) {
189 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
191 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
192 this.isOptional = true;
194 src = src.substring(nameRange[1]+1);
196 // has default value?
197 var nameAndValue = this.name.split("=");
198 if (nameAndValue.length) {
199 this.name = nameAndValue.shift().trim();
200 this.defaultValue = nameAndValue.join("=");
204 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
206 if (parts[1]) this.name = parts[1];
207 if (parts[2]) src = parts[2].trim();
215 balance : function(str, open, close) {
217 while (str.charAt(i) != open) {
218 if (i == str.length) return [-1, -1];
224 while (j < str.length) {
225 if (str.charAt(j) == open) balance++;
226 if (str.charAt(j) == close) balance--;
227 if (balance == 0) break;
229 if (j == str.length) return [-1, -1];
240 DocTag.fromDump = function(t)
242 var ns = new DocTag();
244 if (typeof(ns[i]) == "undefined") {
245 println("ERR:no default for DocTag:"+ i);