PageRenderTime 17ms CodeModel.GetById 13ms 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. * @class Represents a tag within a doclet.
  12. * @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
  13. * @constructor
  14. * @param {string} src line(s) of text following the @ character
  15. */
  16. function DocTag(src) {
  17. /**
  18. * Like @title
  19. * @type string
  20. */
  21. this.title = "";
  22. /**
  23. * Like @title {type}
  24. * @type string
  25. */
  26. this.type = "";
  27. /**
  28. * Like @title {type}? name, though this is only recognized in tags with a title of "param" or "property."
  29. * @type string
  30. */
  31. this.name = "";
  32. /**
  33. * Like @title {type}? name? description goes here...
  34. * @type string
  35. */
  36. this.desc = "";
  37. if (typeof(src) != "undefined") {
  38. var parts = src.match(/^(\S+)(?:\s+\{\s*([\S\s]+?)\s*\})?\s*([\S\s]*\S)?/);
  39. this.title = (parts[1].toLowerCase() || "");
  40. this.type = (parts[2] || "");
  41. if (this.type) this.type = this.type.replace(/\s*(,|\|\|?)\s*/g, ", ");
  42. this.desc = (parts[3] || "");
  43. // should be @type foo but we'll accept @type {foo} too
  44. if (this.title == "type") {
  45. if (this.type) this.desc = this.type;
  46. // should be @type foo, bar, baz but we'll accept @type foo|bar||baz too
  47. if (this.desc) {
  48. this.desc = this.desc.replace(/\s*(,|\|\|?)\s*/g, ", ");
  49. }
  50. }
  51. var syn;
  52. if ((syn = DocTag.synonyms["="+this.title])) this.title = syn;
  53. if (this.desc) {
  54. if (this.title == "param") { // long tags like {type} [name] desc
  55. var m = this.desc.match(/^\s*(\[?)([a-zA-Z0-9.$_]+)(\]?)(?:\s+\{\s*([\S\s]+?)\s*\})?(?:\s+([\S\s]*\S))?/);
  56. if (m) {
  57. this.isOptional = (!!m[1] && !!m[3]); // bracketed name means optional
  58. this.name = (m[2] || "");
  59. this.type = (m[4] || this.type);
  60. this.desc = (m[5] || "");
  61. }
  62. }
  63. else if (this.title == "property") {
  64. m = this.desc.match(/^\s*([a-zA-Z0-9.$_]+)(?:\s+([\S\s]*\S))?/);
  65. if (m) {
  66. this.name = (m[1] || "");
  67. this.desc = (m[2] || "");
  68. }
  69. }
  70. else if (this.title == "config") {
  71. m = this.desc.match(/^\s*(\[?)([a-zA-Z0-9.$_]+)(\]?)(?:\s+([\S\s]*\S))?/);
  72. if (m) {
  73. this.isOptional = (!!m[1] && !!m[3]); // bracketed name means optional
  74. this.name = (m[2] || "");
  75. this.desc = (m[4] || "");
  76. }
  77. }
  78. }
  79. }
  80. }
  81. /**
  82. * Used to make various JsDoc tags compatible with JsDoc Toolkit.
  83. * @memberOf DocTag
  84. */
  85. DocTag.synonyms = {
  86. "=member": "memberof",
  87. "=description": "desc",
  88. "=exception": "throws",
  89. "=argument": "param",
  90. "=returns": "return",
  91. "=classdescription": "class",
  92. "=fileoverview": "overview",
  93. "=extends": "augments"
  94. }
  95. DocTag.prototype.toString = function() {
  96. return this.desc;
  97. }