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") {
53 Populate the properties of this from the given tag src.
56 parse : function(src) {
57 if (typeof src != "string") throw "src must be a string not "+(typeof src);
60 src = this.nibbleTitle(src);
61 //if (JSDOC.PluginManager) {
62 // JSDOC.PluginManager.run("onDocTagSynonym", this);
65 src = this.nibbleType(src);
67 // only some tags are allowed to have names.
68 if (this.title == "param" || this.title == "property" || this.title == "cfg") { // @config is deprecated
69 src = this.nibbleName(src);
73 if (Options.LOG) Options.LOG.warn(e);
76 this.desc = src; // whatever is left
78 // example tags need to have whitespace preserved
79 if (this.title != "example") this.desc = this.desc.trim();
81 //if (JSDOC.PluginManager) {
82 // JSDOC.PluginManager.run("onDocTag", this);
87 Automatically called when this is stringified.
89 toString : function() {
95 Find and shift off the title of a tag.
99 nibbleTitle : function(src) {
100 if (typeof src != "string") throw "src must be a string not "+(typeof src);
102 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
104 if (parts && parts[1]) this.title = parts[1];
105 if (parts && parts[2]) src = parts[2];
112 Find and shift off the type of a tag.
113 @requires frame/String.js
117 nibbleType : function(src)
119 if (typeof src != "string") throw "src must be a string not "+(typeof src);
121 if (src.match(/^\s*\{/)) {
122 var typeRange = this.balance(src,"{", "}");
123 if (typeRange[1] == -1) {
124 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
126 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
127 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
128 src = src.substring(typeRange[1]+1);
136 Find and shift off the name of a tag.
137 @requires frame/String.js
141 nibbleName : function(src) {
142 if (typeof src != "string") throw "src must be a string not "+(typeof src);
147 if (src.charAt(0) == "[") {
148 var nameRange = this.balance(src,"[", "]");
149 if (nameRange[1] == -1) {
150 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
152 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
153 this.isOptional = true;
155 src = src.substring(nameRange[1]+1);
157 // has default value?
158 var nameAndValue = this.name.split("=");
159 if (nameAndValue.length) {
160 this.name = nameAndValue.shift().trim();
161 this.defaultValue = nameAndValue.join("=");
165 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
167 if (parts[1]) this.name = parts[1];
168 if (parts[2]) src = parts[2].trim();
176 balance : function(str, open, close) {
178 while (str.charAt(i) != open) {
179 if (i == str.length) return [-1, -1];
185 while (j < str.length) {
186 if (str.charAt(j) == open) balance++;
187 if (str.charAt(j) == close) balance--;
188 if (balance == 0) break;
190 if (j == str.length) return [-1, -1];
201 DocTag.fromDump = function(t)
203 var ns = new DocTag();
205 if (typeof(ns[i]) == "undefined") {
206 println("ERR:no default for DocTag:"+ i);