PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/jsdoc_toolkit-1.4.0/app/DocTag.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 110 lines | 60 code | 13 blank | 37 comment | 32 complexity | a752e255557d6b0956c0d6e306fa5ae0 MD5 | raw file
  1/**
  2 * @fileOverview
  3 * @name DocTag
  4 * @author Michael Mathews micmath@gmail.com
  5 * @url $HeadURL: http://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-1.4.0/app/DocTag.js $
  6 * @revision $Id: DocTag.js 334 2007-11-13 19:52:49Z micmath $
  7 * @license <a href="http://en.wikipedia.org/wiki/MIT_License">X11/MIT License</a>
  8 *          (See the accompanying README file for full details.)
  9 */
 10 
 11 /**
 12  * @class Represents a tag within a doclet.
 13  * @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
 14  * @constructor
 15  * @param {string} src line(s) of text following the @ character
 16  */
 17function DocTag(src) {
 18	/**
 19	 * Like @title
 20	 * @type string
 21	 */
 22	this.title = "";
 23	
 24	/**
 25	 * Like @title {type}
 26	 * @type string
 27	 */
 28	this.type = "";
 29	
 30	/**
 31	 * Like @title {type}? name, though this is only recognized in tags with a title of "param" or "property."
 32	 * @type string
 33	 */
 34	this.name = "";
 35	
 36	/**
 37	 * Like @title {type}? name? description goes here...
 38	 * @type string
 39	 */
 40	this.desc = "";
 41	
 42	if (typeof(src) != "undefined") {
 43		var parts = src.match(/^(\S+)(?:\s+\{\s*([\S\s]+?)\s*\})?\s*([\S\s]*\S)?/);
 44		
 45		this.title = (parts[1].toLowerCase() || "");
 46		this.type = (parts[2] || "");
 47	
 48		if (this.type) this.type = this.type.replace(/\s*(,|\|\|?)\s*/g, ", ");
 49		this.desc = (parts[3] || "");
 50		
 51		// should be @type foo but we'll accept @type {foo} too
 52		if (this.title == "type") {
 53			if (this.type) this.desc = this.type;
 54			
 55			// should be @type foo, bar, baz but we'll accept @type foo|bar||baz too
 56			if (this.desc) {
 57				this.desc = this.desc.replace(/\s*(,|\|\|?)\s*/g, ", ");
 58			}
 59		}
 60		
 61		var syn;
 62		if ((syn = DocTag.synonyms["="+this.title])) this.title = syn;
 63		
 64		if (this.desc) {
 65			if (this.title == "param") { // long tags like {type} [name] desc
 66				var m = this.desc.match(/^\s*(\[?)([a-zA-Z0-9.$_]+)(\]?)(?:\s+\{\s*([\S\s]+?)\s*\})?(?:\s+([\S\s]*\S))?/);
 67				if (m) {
 68					this.isOptional = (!!m[1] && !!m[3]); // bracketed name means optional
 69					this.name = (m[2] || "");
 70					this.type = (m[4] || this.type);
 71					this.desc = (m[5] || "");
 72				}
 73			}
 74			else if (this.title == "property") {
 75				m = this.desc.match(/^\s*([a-zA-Z0-9.$_]+)(?:\s+([\S\s]*\S))?/);
 76				if (m) {
 77					this.name = (m[1] || "");
 78					this.desc = (m[2] || "");
 79				}
 80			}
 81			else if (this.title == "config") {
 82				m = this.desc.match(/^\s*(\[?)([a-zA-Z0-9.$_]+)(\]?)(?:\s+([\S\s]*\S))?/);
 83				if (m) {
 84					this.isOptional = (!!m[1] && !!m[3]); // bracketed name means optional
 85					this.name = (m[2] || "");
 86					this.desc = (m[4] || "");
 87				}
 88			}
 89		}
 90	}
 91}
 92
 93/**
 94 * Used to make various JsDoc tags compatible with JsDoc Toolkit.
 95 * @memberOf DocTag
 96 */
 97DocTag.synonyms = {
 98	"=member":             "memberof",
 99	"=description":        "desc",
100	"=exception":          "throws",
101	"=argument":           "param",
102	"=returns":            "return",
103	"=classdescription":   "class",
104	"=fileoverview":       "overview",
105	"=extends":            "augments"
106}
107
108DocTag.prototype.toString = function() {
109	return this.desc;
110}