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") {
42 /* qdump needed for cahcing?
45 return JSDOC.toQDump(t, 'JSDOC.DocTag.fromDump({', '})', new JSDOC.DocTag());
51 Populate the properties of this from the given tag src.
54 parse : function(src) {
55 if (typeof src != "string") throw "src must be a string not "+(typeof src);
58 src = this.nibbleTitle(src);
59 //if (JSDOC.PluginManager) {
60 // JSDOC.PluginManager.run("onDocTagSynonym", this);
63 src = this.nibbleType(src);
65 // only some tags are allowed to have names.
66 if (this.title == "param" || this.title == "property" || this.title == "cfg") { // @config is deprecated
67 src = this.nibbleName(src);
71 if (Options.LOG) Options.LOG.warn(e);
74 this.desc = src; // whatever is left
76 // example tags need to have whitespace preserved
77 if (this.title != "example") this.desc = this.desc.trim();
79 //if (JSDOC.PluginManager) {
80 // JSDOC.PluginManager.run("onDocTag", this);
85 Automatically called when this is stringified.
87 toString : function() {
93 Find and shift off the title of a tag.
97 nibbleTitle : function(src) {
98 if (typeof src != "string") throw "src must be a string not "+(typeof src);
100 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
102 if (parts && parts[1]) this.title = parts[1];
103 if (parts && parts[2]) src = parts[2];
110 Find and shift off the type of a tag.
111 @requires frame/String.js
115 nibbleType : function(src)
117 if (typeof src != "string") throw "src must be a string not "+(typeof src);
119 if (src.match(/^\s*\{/)) {
120 var typeRange = this.balance(src,"{", "}");
121 if (typeRange[1] == -1) {
122 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
124 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
125 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
126 src = src.substring(typeRange[1]+1);
134 Find and shift off the name of a tag.
135 @requires frame/String.js
139 nibbleName : function(src) {
140 if (typeof src != "string") throw "src must be a string not "+(typeof src);
145 if (src.charAt(0) == "[") {
146 var nameRange = this.balance(src,"[", "]");
147 if (nameRange[1] == -1) {
148 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
150 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
151 this.isOptional = true;
153 src = src.substring(nameRange[1]+1);
155 // has default value?
156 var nameAndValue = this.name.split("=");
157 if (nameAndValue.length) {
158 this.name = nameAndValue.shift().trim();
159 this.defaultValue = nameAndValue.join("=");
163 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
165 if (parts[1]) this.name = parts[1];
166 if (parts[2]) src = parts[2].trim();
174 balance : function(str, open, close) {
176 while (str.charAt(i) != open) {
177 if (i == str.length) return [-1, -1];
183 while (j < str.length) {
184 if (str.charAt(j) == open) balance++;
185 if (str.charAt(j) == close) balance--;
186 if (balance == 0) break;
188 if (j == str.length) return [-1, -1];
199 DocTag.fromDump = function(t)
201 var ns = new DocTag();
203 if (typeof(ns[i]) == "undefined") {
204 println("ERR:no default for DocTag:"+ i);