PageRenderTime 427ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/jsdoc_tk_gui/setup/jsDoc/DocTag.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 109 lines | 59 code | 13 blank | 37 comment | 31 complexity | 3815fdfde26a600c1edb53d56af39b64 MD5 | raw file
  1. /**
  2. * @fileOverview
  3. * @name DocTag
  4. * @author Michael Mathews micmath@gmail.com
  5. * @url $HeadURL: https://jsdoc-toolkit.googlecode.com/svn/branches/jsdoc_tk_gui/setup/app/DocTag.js $
  6. * @revision $Id: DocTag.js 313 2007-11-11 22:01:03Z sebastien.bordes $
  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))?/);
  56. if (m) {
  57. this.isOptional = (!!m[1] && !!m[3]); // bracketed name means optional
  58. this.name = (m[2] || "");
  59. this.desc = (m[4] || "");
  60. }
  61. }
  62. else if (this.title == "property") {
  63. m = this.desc.match(/^\s*([a-zA-Z0-9.$_]+)(?:\s+([\S\s]*\S))?/);
  64. if (m) {
  65. this.name = (m[1] || "");
  66. this.desc = (m[2] || "");
  67. }
  68. }
  69. else if (this.title == "config") {
  70. m = this.desc.match(/^\s*(\[?)([a-zA-Z0-9.$_]+)(\]?)(?:\s+([\S\s]*\S))?/);
  71. if (m) {
  72. this.isOptional = (!!m[1] && !!m[3]); // bracketed name means optional
  73. this.name = (m[2] || "");
  74. this.desc = (m[4] || "");
  75. }
  76. }
  77. }
  78. }
  79. }
  80. /**
  81. * Used to make various JsDoc tags compatible with JsDoc Toolkit.
  82. * @memberOf DocTag
  83. */
  84. DocTag.synonyms = {
  85. "=member": "memberof",
  86. "=description": "desc",
  87. "=exception": "throws",
  88. "=argument": "param",
  89. "=returns": "return",
  90. "=classdescription": "class",
  91. "=fileoverview": "overview",
  92. "=extends": "augments"
  93. }
  94. DocTag.prototype.toString = function() {
  95. return this.desc;
  96. }