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])) {
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" || this.title == "property" || this.title == "cfg") { // @config is deprecated
90 src = this.nibbleName(src);
94 if (Options.LOG) Options.LOG.warn(e);
97 this.desc = src; // whatever is left
99 // example tags need to have whitespace preserved
100 if (this.title != "example") this.desc = this.desc.trim();
102 //if (JSDOC.PluginManager) {
103 // JSDOC.PluginManager.run("onDocTag", this);
108 Automatically called when this is stringified.
110 toString : function() {
116 Find and shift off the title of a tag.
120 nibbleTitle : function(src) {
121 if (typeof src != "string") throw "src must be a string not "+(typeof src);
123 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
125 if (parts && parts[1]) this.title = parts[1];
126 if (parts && parts[2]) src = parts[2];
133 Find and shift off the type of a tag.
134 @requires frame/String.js
138 nibbleType : function(src)
140 if (typeof src != "string") throw "src must be a string not "+(typeof src);
142 if (src.match(/^\s*\{/)) {
143 var typeRange = this.balance(src,"{", "}");
144 if (typeRange[1] == -1) {
145 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
147 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
148 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
149 src = src.substring(typeRange[1]+1);
157 Find and shift off the name of a tag.
158 @requires frame/String.js
162 nibbleName : function(src) {
163 if (typeof src != "string") throw "src must be a string not "+(typeof src);
168 if (src.charAt(0) == "[") {
169 var nameRange = this.balance(src,"[", "]");
170 if (nameRange[1] == -1) {
171 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
173 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
174 this.isOptional = true;
176 src = src.substring(nameRange[1]+1);
178 // has default value?
179 var nameAndValue = this.name.split("=");
180 if (nameAndValue.length) {
181 this.name = nameAndValue.shift().trim();
182 this.defaultValue = nameAndValue.join("=");
186 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
188 if (parts[1]) this.name = parts[1];
189 if (parts[2]) src = parts[2].trim();
197 balance : function(str, open, close) {
199 while (str.charAt(i) != open) {
200 if (i == str.length) return [-1, -1];
206 while (j < str.length) {
207 if (str.charAt(j) == open) balance++;
208 if (str.charAt(j) == close) balance--;
209 if (balance == 0) break;
211 if (j == str.length) return [-1, -1];
222 DocTag.fromDump = function(t)
224 var ns = new DocTag();
226 if (typeof(ns[i]) == "undefined") {
227 println("ERR:no default for DocTag:"+ i);