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])) {
61 ret[i] = this[i]; continue;
63 print("unknown type:" + typeof(this[i]));
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);
96 this.desc = src; // whatever is left
98 // example tags need to have whitespace preserved
99 if (this.title != "example") this.desc = this.desc.trim();
101 //if (JSDOC.PluginManager) {
102 // JSDOC.PluginManager.run("onDocTag", this);
107 Automatically called when this is stringified.
109 toString : function() {
115 Find and shift off the title of a tag.
119 nibbleTitle : function(src) {
120 if (typeof src != "string") throw "src must be a string not "+(typeof src);
122 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
124 if (parts && parts[1]) this.title = parts[1];
125 if (parts && parts[2]) src = parts[2];
132 Find and shift off the type of a tag.
133 @requires frame/String.js
137 nibbleType : function(src)
139 if (typeof src != "string") throw "src must be a string not "+(typeof src);
141 if (src.match(/^\s*\{/)) {
142 var typeRange = this.balance(src,"{", "}");
143 if (typeRange[1] == -1) {
144 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
146 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
147 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
148 src = src.substring(typeRange[1]+1);
156 Find and shift off the name of a tag.
157 @requires frame/String.js
161 nibbleName : function(src) {
162 if (typeof src != "string") throw "src must be a string not "+(typeof src);
167 if (src.charAt(0) == "[") {
168 var nameRange = this.balance(src,"[", "]");
169 if (nameRange[1] == -1) {
170 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
172 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
173 this.isOptional = true;
175 src = src.substring(nameRange[1]+1);
177 // has default value?
178 var nameAndValue = this.name.split("=");
179 if (nameAndValue.length) {
180 this.name = nameAndValue.shift().trim();
181 this.defaultValue = nameAndValue.join("=");
185 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
187 if (parts[1]) this.name = parts[1];
188 if (parts[2]) src = parts[2].trim();
196 balance : function(str, open, close) {
198 while (str.charAt(i) != open) {
199 if (i == str.length) return [-1, -1];
205 while (j < str.length) {
206 if (str.charAt(j) == open) balance++;
207 if (str.charAt(j) == close) balance--;
208 if (balance == 0) break;
210 if (j == str.length) return [-1, -1];
221 DocTag.fromDump = function(t)
223 var ns = new DocTag();
225 if (typeof(ns[i]) == "undefined") {
226 println("ERR:no default for DocTag:"+ i);