1 //<script type="text/javascript">
4 XObject = imports.XObject.XObject;
6 DocTag = imports.DocTag.DocTag;
8 * DocTag - represents a single A=b tag.
13 DocTag = XObject.define(
18 this.isOptional = false;
19 this.defaultValue = "";
21 if (typeof src != "undefined") {
37 return JSDOC.toQDump(t, 'JSDOC.DocTag.fromDump({', '})', new JSDOC.DocTag());
43 Populate the properties of this from the given tag src.
46 parse : function(src) {
47 if (typeof src != "string") throw "src must be a string not "+(typeof src);
50 src = this.nibbleTitle(src);
51 if (JSDOC.PluginManager) {
52 JSDOC.PluginManager.run("onDocTagSynonym", this);
55 src = this.nibbleType(src);
57 // only some tags are allowed to have names.
58 if (this.title == "param" || this.title == "property" || this.title == "cfg") { // @config is deprecated
59 src = this.nibbleName(src);
63 if (JSDOC.opt.LOG) JSDOC.opt.LOG.warn(e);
66 this.desc = src; // whatever is left
68 // example tags need to have whitespace preserved
69 if (this.title != "example") this.desc = this.desc.trim();
71 if (JSDOC.PluginManager) {
72 JSDOC.PluginManager.run("onDocTag", this);
77 Automatically called when this is stringified.
79 toString : function() {
85 Find and shift off the title of a tag.
89 nibbleTitle : function(src) {
90 if (typeof src != "string") throw "src must be a string not "+(typeof src);
92 var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
94 if (parts && parts[1]) this.title = parts[1];
95 if (parts && parts[2]) src = parts[2];
102 Find and shift off the type of a tag.
103 @requires frame/String.js
107 nibbleType : function(src) {
108 if (typeof src != "string") throw "src must be a string not "+(typeof src);
110 if (src.match(/^\s*\{/)) {
111 var typeRange = src.balance("{", "}");
112 if (typeRange[1] == -1) {
113 throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
115 this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
116 this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
117 src = src.substring(typeRange[1]+1);
125 Find and shift off the name of a tag.
126 @requires frame/String.js
130 nibbleName : function(src) {
131 if (typeof src != "string") throw "src must be a string not "+(typeof src);
136 if (src.charAt(0) == "[") {
137 var nameRange = src.balance("[", "]");
138 if (nameRange[1] == -1) {
139 throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
141 this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
142 this.isOptional = true;
144 src = src.substring(nameRange[1]+1);
146 // has default value?
147 var nameAndValue = this.name.split("=");
148 if (nameAndValue.length) {
149 this.name = nameAndValue.shift().trim();
150 this.defaultValue = nameAndValue.join("=");
154 var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
156 if (parts[1]) this.name = parts[1];
157 if (parts[2]) src = parts[2].trim();
167 JSDOC.DocTag.fromDump = function(t)
169 var ns = new JSDOC.DocTag();
171 if (typeof(ns[i]) == "undefined") {
172 println("ERR:no default for DocTag:"+ i);