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;
62 print("unknown type:" + typeof(this[i]));
63 print(JSON.stringify(this));;
73 Populate the properties of this from the given tag src.
76 parse : function(src) {
77 if (typeof src != "string") throw "src must be a string not "+(typeof src);
80 src = this.nibbleTitle(src);
81 //if (JSDOC.PluginManager) {
82 // JSDOC.PluginManager.run("onDocTagSynonym", this);
85 src = this.nibbleType(src);
87 // only some tags are allowed to have names.
88 if (this.title == "param" || this.title == "property" || this.title == "cfg") { // @config is deprecated
89 src = this.nibbleName(src);
93 if (Options.LOG) Options.LOG.warn(e);
97 // if type == @cfg, and matches (|....|...)
100 if (this.title == "cfg" && src.match(/^\([^)]+\)/)) {
101 var m = src.match(/^\(([^)]+)\)/);
103 if (m[1].match(/\|/)) {
104 var opts = m[1].split(/\|/);
105 this.optvalues = opts;
106 src = src.substring(m[0].length).trim();
116 this.desc = src; // whatever is left
118 // example tags need to have whitespace preserved
119 if (this.title != "example") this.desc = this.desc.trim();
121 //if (JSDOC.PluginManager) {
122 // JSDOC.PluginManager.run("onDocTag", this);
127 Automatically called when this is stringified.
129 toString : function() {
135 Find and shift off the title of a tag.
139 nibbleTitle : function(src) {
140 if (typeof src != "string") throw "src must be a string not "+(typeof src);
142 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
144 if (parts && parts[1]) this.title = parts[1];
145 if (parts && parts[2]) src = parts[2];
152 Find and shift off the type of a tag.
153 @requires frame/String.js
157 nibbleType : function(src)
159 if (typeof src != "string") throw "src must be a string not "+(typeof src);
161 if (src.match(/^\s*\{/)) {
162 var typeRange = this.balance(src,"{", "}");
163 if (typeRange[1] == -1) {
164 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
166 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
167 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
168 src = src.substring(typeRange[1]+1);
176 Find and shift off the name of a tag.
177 @requires frame/String.js
181 nibbleName : function(src) {
182 if (typeof src != "string") throw "src must be a string not "+(typeof src);
187 if (src.charAt(0) == "[") {
188 var nameRange = this.balance(src,"[", "]");
189 if (nameRange[1] == -1) {
190 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
192 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
193 this.isOptional = true;
195 src = src.substring(nameRange[1]+1);
197 // has default value?
198 var nameAndValue = this.name.split("=");
199 if (nameAndValue.length) {
200 this.name = nameAndValue.shift().trim();
201 this.defaultValue = nameAndValue.join("=");
205 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
207 if (parts[1]) this.name = parts[1];
208 if (parts[2]) src = parts[2].trim();
216 balance : function(str, open, close) {
218 while (str.charAt(i) != open) {
219 if (i == str.length) return [-1, -1];
225 while (j < str.length) {
226 if (str.charAt(j) == open) balance++;
227 if (str.charAt(j) == close) balance--;
228 if (balance == 0) break;
230 if (j == str.length) return [-1, -1];
241 DocTag.fromDump = function(t)
243 var ns = new DocTag();
245 if (typeof(ns[i]) == "undefined") {
246 println("ERR:no default for DocTag:"+ i);