PageRenderTime 470ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/山火-ヤギの咆哮-/lib/lua/lua/luadoc/taglet/standard/tags.lua

https://gitlab.com/kokeiro001/YamabiYagiNoHoko
Lua | 171 lines | 161 code | 4 blank | 6 comment | 6 complexity | 73fd26693a6d4b25f3349006117041e3 MD5 | raw file
  1. -------------------------------------------------------------------------------
  2. -- Handlers for several tags
  3. -- @release $Id: tags.lua,v 1.8 2007/09/05 12:39:09 tomas Exp $
  4. -------------------------------------------------------------------------------
  5. local luadoc = require "luadoc"
  6. local util = require "luadoc.util"
  7. local string = require "string"
  8. local table = require "table"
  9. local assert, type, tostring = assert, type, tostring
  10. module "luadoc.taglet.standard.tags"
  11. -------------------------------------------------------------------------------
  12. local function author (tag, block, text)
  13. block[tag] = block[tag] or {}
  14. if not text then
  15. luadoc.logger:warn("author `name' not defined [["..text.."]]: skipping")
  16. return
  17. end
  18. table.insert (block[tag], text)
  19. end
  20. -------------------------------------------------------------------------------
  21. -- Set the class of a comment block. Classes can be "module", "function",
  22. -- "table". The first two classes are automatic, extracted from the source code
  23. local function class (tag, block, text)
  24. block[tag] = text
  25. end
  26. -------------------------------------------------------------------------------
  27. local function copyright (tag, block, text)
  28. block[tag] = text
  29. end
  30. -------------------------------------------------------------------------------
  31. local function description (tag, block, text)
  32. block[tag] = text
  33. end
  34. -------------------------------------------------------------------------------
  35. local function field (tag, block, text)
  36. if block["class"] ~= "table" then
  37. luadoc.logger:warn("documenting `field' for block that is not a `table'")
  38. end
  39. block[tag] = block[tag] or {}
  40. local _, _, name, desc = string.find(text, "^([_%w%.]+)%s+(.*)")
  41. assert(name, "field name not defined")
  42. table.insert(block[tag], name)
  43. block[tag][name] = desc
  44. end
  45. -------------------------------------------------------------------------------
  46. -- Set the name of the comment block. If the block already has a name, issue
  47. -- an error and do not change the previous value
  48. local function name (tag, block, text)
  49. if block[tag] and block[tag] ~= text then
  50. luadoc.logger:error(string.format("block name conflict: `%s' -> `%s'", block[tag], text))
  51. end
  52. block[tag] = text
  53. end
  54. -------------------------------------------------------------------------------
  55. -- Processes a parameter documentation.
  56. -- @param tag String with the name of the tag (it must be "param" always).
  57. -- @param block Table with previous information about the block.
  58. -- @param text String with the current line beeing processed.
  59. local function param (tag, block, text)
  60. block[tag] = block[tag] or {}
  61. -- TODO: make this pattern more flexible, accepting empty descriptions
  62. local _, _, name, desc = string.find(text, "^([_%w%.]+)%s+(.*)")
  63. if not name then
  64. luadoc.logger:warn("parameter `name' not defined [["..text.."]]: skipping")
  65. return
  66. end
  67. local i = table.foreachi(block[tag], function (i, v)
  68. if v == name then
  69. return i
  70. end
  71. end)
  72. if i == nil then
  73. luadoc.logger:warn(string.format("documenting undefined parameter `%s'", name))
  74. table.insert(block[tag], name)
  75. end
  76. block[tag][name] = desc
  77. end
  78. -------------------------------------------------------------------------------
  79. local function release (tag, block, text)
  80. block[tag] = text
  81. end
  82. -------------------------------------------------------------------------------
  83. local function ret (tag, block, text)
  84. tag = "ret"
  85. if type(block[tag]) == "string" then
  86. block[tag] = { block[tag], text }
  87. elseif type(block[tag]) == "table" then
  88. table.insert(block[tag], text)
  89. else
  90. block[tag] = text
  91. end
  92. end
  93. -------------------------------------------------------------------------------
  94. -- @see ret
  95. local function see (tag, block, text)
  96. -- see is always an array
  97. block[tag] = block[tag] or {}
  98. -- remove trailing "."
  99. text = string.gsub(text, "(.*)%.$", "%1")
  100. local s = util.split("%s*,%s*", text)
  101. table.foreachi(s, function (_, v)
  102. table.insert(block[tag], v)
  103. end)
  104. end
  105. -------------------------------------------------------------------------------
  106. -- @see ret
  107. local function usage (tag, block, text)
  108. if type(block[tag]) == "string" then
  109. block[tag] = { block[tag], text }
  110. elseif type(block[tag]) == "table" then
  111. table.insert(block[tag], text)
  112. else
  113. block[tag] = text
  114. end
  115. end
  116. -------------------------------------------------------------------------------
  117. local handlers = {}
  118. handlers["author"] = author
  119. handlers["class"] = class
  120. handlers["copyright"] = copyright
  121. handlers["description"] = description
  122. handlers["field"] = field
  123. handlers["name"] = name
  124. handlers["param"] = param
  125. handlers["release"] = release
  126. handlers["return"] = ret
  127. handlers["see"] = see
  128. handlers["usage"] = usage
  129. -------------------------------------------------------------------------------
  130. function handle (tag, block, text)
  131. if not handlers[tag] then
  132. luadoc.logger:error(string.format("undefined handler for tag `%s'", tag))
  133. return
  134. end
  135. -- assert(handlers[tag], string.format("undefined handler for tag `%s'", tag))
  136. return handlers[tag](tag, block, text)
  137. end