removed scrollbar from tables
added enabled property
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ testWorkflows
|
|||||||
todo.txt
|
todo.txt
|
||||||
Flexbox2.lua
|
Flexbox2.lua
|
||||||
markdown2.lua
|
markdown2.lua
|
||||||
|
BasaltDoc
|
||||||
@@ -31,6 +31,9 @@ BaseElement.defineProperty(BaseElement, "name", {default = "", type = "string"})
|
|||||||
--- @property eventCallbacks table BaseElement The event callbacks for the element
|
--- @property eventCallbacks table BaseElement The event callbacks for the element
|
||||||
BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"})
|
BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"})
|
||||||
|
|
||||||
|
--- @property enabled boolean BaseElement Whether the element is enabled or not
|
||||||
|
BaseElement.defineProperty(BaseElement, "enabled", {default = true, type = "boolean" })
|
||||||
|
|
||||||
--- Registers a new event listener for the element (on class level)
|
--- Registers a new event listener for the element (on class level)
|
||||||
--- @shortDescription Registers a new event listener for the element (on class level)
|
--- @shortDescription Registers a new event listener for the element (on class level)
|
||||||
--- @param class table The class to register
|
--- @param class table The class to register
|
||||||
@@ -215,6 +218,9 @@ end
|
|||||||
--- @return boolean? handled Whether the event was handled
|
--- @return boolean? handled Whether the event was handled
|
||||||
--- @protected
|
--- @protected
|
||||||
function BaseElement:dispatchEvent(event, ...)
|
function BaseElement:dispatchEvent(event, ...)
|
||||||
|
if self.get("enabled") == false then
|
||||||
|
return false
|
||||||
|
end
|
||||||
if self[event] then
|
if self[event] then
|
||||||
return self[event](self, ...)
|
return self[event](self, ...)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -226,27 +226,6 @@ function Table:render()
|
|||||||
string.rep(tHex[self.get("background")], self.get("width")))
|
string.rep(tHex[self.get("background")], self.get("width")))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #data > height - 2 then
|
|
||||||
local scrollbarHeight = height - 2
|
|
||||||
local thumbSize = math.max(1, math.floor(scrollbarHeight * (height - 2) / #data))
|
|
||||||
|
|
||||||
local maxScroll = #data - (height - 2) + 1
|
|
||||||
local scrollPercent = scrollOffset / maxScroll
|
|
||||||
local thumbPos = 2 + math.floor(scrollPercent * (scrollbarHeight - thumbSize))
|
|
||||||
|
|
||||||
if scrollOffset >= maxScroll then
|
|
||||||
thumbPos = height - thumbSize
|
|
||||||
end
|
|
||||||
|
|
||||||
for y = 2, height do
|
|
||||||
self:blit(self.get("width"), y, "\127", tHex[colors.gray], tHex[colors.gray])
|
|
||||||
end
|
|
||||||
|
|
||||||
for y = thumbPos, math.min(height, thumbPos + thumbSize - 1) do
|
|
||||||
self:blit(self.get("width"), y, "\127", tHex[colors.white], tHex[colors.white])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Table
|
return Table
|
||||||
@@ -99,7 +99,7 @@ VisualElement.registerEventCallback(VisualElement, "ClickUp", "mouse_up", "mouse
|
|||||||
VisualElement.registerEventCallback(VisualElement, "Drag", "mouse_drag", "mouse_click", "mouse_up")
|
VisualElement.registerEventCallback(VisualElement, "Drag", "mouse_drag", "mouse_click", "mouse_up")
|
||||||
VisualElement.registerEventCallback(VisualElement, "Scroll", "mouse_scroll")
|
VisualElement.registerEventCallback(VisualElement, "Scroll", "mouse_scroll")
|
||||||
VisualElement.registerEventCallback(VisualElement, "Enter", "mouse_enter", "mouse_move")
|
VisualElement.registerEventCallback(VisualElement, "Enter", "mouse_enter", "mouse_move")
|
||||||
VisualElement.registerEventCallback(VisualElement, "LeEave", "mouse_leave", "mouse_move")
|
VisualElement.registerEventCallback(VisualElement, "Leave", "mouse_leave", "mouse_move")
|
||||||
VisualElement.registerEventCallback(VisualElement, "Focus", "focus", "blur")
|
VisualElement.registerEventCallback(VisualElement, "Focus", "focus", "blur")
|
||||||
VisualElement.registerEventCallback(VisualElement, "Blur", "blur", "focus")
|
VisualElement.registerEventCallback(VisualElement, "Blur", "blur", "focus")
|
||||||
VisualElement.registerEventCallback(VisualElement, "Key", "key", "key_up")
|
VisualElement.registerEventCallback(VisualElement, "Key", "key", "key_up")
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ function Button.new()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Initializes the Button instance
|
||||||
--- @shortDescription Initializes the Button instance
|
--- @shortDescription Initializes the Button instance
|
||||||
--- @param props table The properties to initialize the element with
|
--- @param props table The properties to initialize the element with
|
||||||
--- @param basalt table The basalt instance
|
--- @param basalt table The basalt instance
|
||||||
|
|||||||
@@ -1,101 +1,81 @@
|
|||||||
local CommentExtractor = {}
|
local CommentExtractor = {}
|
||||||
|
|
||||||
--- Extracts comments with their associated code context
|
--- Extracts comment blocks that belong together
|
||||||
-- @param lines table The lines of the Lua file as a table of strings.
|
function CommentExtractor.extractBlocks(lines)
|
||||||
-- @return table A table containing comment blocks with context.
|
|
||||||
function CommentExtractor.extractComments(lines)
|
|
||||||
local blocks = {}
|
local blocks = {}
|
||||||
local currentCommentBlock = {}
|
local currentBlock = {
|
||||||
local i = 1
|
comments = {},
|
||||||
|
codeContext = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
local i = 1
|
||||||
while i <= #lines do
|
while i <= #lines do
|
||||||
local line = lines[i]:match("^%s*(.*)") -- Trim leading whitespace
|
local line = lines[i]
|
||||||
|
local trimmed = line:match("^%s*(.-)%s*$")
|
||||||
|
|
||||||
-- Check if this is a comment line
|
-- Check if this is a comment line
|
||||||
if line:find("^%-%-%-") or line:find("^%-%-") then
|
if trimmed:match("^%-%-%-") or trimmed:match("^%-%-") then
|
||||||
table.insert(currentCommentBlock, line)
|
table.insert(currentBlock.comments, trimmed)
|
||||||
elseif #currentCommentBlock > 0 then
|
elseif #currentBlock.comments > 0 then
|
||||||
-- We have accumulated comments, check if next non-empty line is code
|
-- We have comments, now look for the code that follows
|
||||||
local codeContext = nil
|
local codeLineIndex = CommentExtractor.findNextCodeLine(lines, i)
|
||||||
local j = i
|
if codeLineIndex then
|
||||||
|
local codeLine = lines[codeLineIndex]:match("^%s*(.-)%s*$")
|
||||||
-- Skip empty lines to find the actual code
|
currentBlock.codeContext = CommentExtractor.analyzeCode(codeLine, codeLineIndex)
|
||||||
while j <= #lines and lines[j]:match("^%s*$") do
|
|
||||||
j = j + 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if j <= #lines then
|
-- Save this block and start a new one
|
||||||
local codeLine = lines[j]:match("^%s*(.*)")
|
table.insert(blocks, currentBlock)
|
||||||
-- Check if it's a function, class, property, etc.
|
currentBlock = {comments = {}, codeContext = nil}
|
||||||
if codeLine:find("^function") or
|
|
||||||
codeLine:find("^local function") or
|
|
||||||
codeLine:find("^local%s+%w+%s*=") or
|
|
||||||
codeLine:find("^%w+%.%w+") then
|
|
||||||
codeContext = {
|
|
||||||
type = CommentExtractor.getCodeType(codeLine),
|
|
||||||
name = CommentExtractor.extractName(codeLine),
|
|
||||||
line = codeLine,
|
|
||||||
lineNumber = j
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add the comment block with its context
|
|
||||||
table.insert(blocks, {
|
|
||||||
comments = currentCommentBlock,
|
|
||||||
context = codeContext
|
|
||||||
})
|
|
||||||
|
|
||||||
currentCommentBlock = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handle any remaining comments
|
-- Handle remaining comments
|
||||||
if #currentCommentBlock > 0 then
|
if #currentBlock.comments > 0 then
|
||||||
table.insert(blocks, {
|
table.insert(blocks, currentBlock)
|
||||||
comments = currentCommentBlock,
|
|
||||||
context = nil
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return blocks
|
return blocks
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Determines the type of code (function, class, property, etc.)
|
--- Find the next non-empty code line
|
||||||
function CommentExtractor.getCodeType(codeLine)
|
function CommentExtractor.findNextCodeLine(lines, startIndex)
|
||||||
if codeLine:find("^function") or codeLine:find("^local function") then
|
for i = startIndex, #lines do
|
||||||
return "function"
|
local trimmed = lines[i]:match("^%s*(.-)%s*$")
|
||||||
elseif codeLine:find("^local%s+%w+%s*=%s*setmetatable") then
|
if trimmed ~= "" and not trimmed:match("^%-%-") then
|
||||||
return "class"
|
return i
|
||||||
elseif codeLine:find("^local%s+%w+%s*=") then
|
end
|
||||||
return "variable"
|
|
||||||
elseif codeLine:find("^%w+%.defineProperty") then
|
|
||||||
return "property_definition"
|
|
||||||
else
|
|
||||||
return "unknown"
|
|
||||||
end
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Extracts the name from a code line
|
--- Analyze what kind of code this is
|
||||||
function CommentExtractor.extractName(codeLine)
|
function CommentExtractor.analyzeCode(codeLine, lineNumber)
|
||||||
-- Function patterns
|
-- Function patterns
|
||||||
local funcName = codeLine:match("^function%s+([%w%.%:]+)")
|
if codeLine:match("^function%s+([%w%.%:]+)") then
|
||||||
if funcName then return funcName end
|
local name = codeLine:match("^function%s+([%w%.%:]+)")
|
||||||
|
return {type = "function", name = name, line = codeLine, lineNumber = lineNumber}
|
||||||
|
end
|
||||||
|
|
||||||
local localFuncName = codeLine:match("^local%s+function%s+([%w%.%:]+)")
|
if codeLine:match("^local%s+function%s+([%w%.%:]+)") then
|
||||||
if localFuncName then return localFuncName end
|
local name = codeLine:match("^local%s+function%s+([%w%.%:]+)")
|
||||||
|
return {type = "function", name = name, line = codeLine, lineNumber = lineNumber}
|
||||||
|
end
|
||||||
|
|
||||||
-- Variable/class patterns
|
-- Class/variable patterns
|
||||||
local varName = codeLine:match("^local%s+([%w_]+)%s*=")
|
if codeLine:match("^local%s+([%w_]+)%s*=%s*setmetatable") then
|
||||||
if varName then return varName end
|
local name = codeLine:match("^local%s+([%w_]+)%s*=")
|
||||||
|
return {type = "class", name = name, line = codeLine, lineNumber = lineNumber}
|
||||||
|
end
|
||||||
|
|
||||||
-- Method patterns
|
if codeLine:match("^local%s+([%w_]+)%s*=") then
|
||||||
local methodName = codeLine:match("^([%w%.%:]+)%s*=")
|
local name = codeLine:match("^local%s+([%w_]+)%s*=")
|
||||||
if methodName then return methodName end
|
return {type = "variable", name = name, line = codeLine, lineNumber = lineNumber}
|
||||||
|
end
|
||||||
|
|
||||||
return "unknown"
|
return {type = "unknown", name = "unknown", line = codeLine, lineNumber = lineNumber}
|
||||||
end
|
end
|
||||||
|
|
||||||
return CommentExtractor
|
return CommentExtractor
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
local CommentExtractor = require("parser.comment_extractor")
|
local CommentExtractor = require("parser.comment_extractor")
|
||||||
|
local TagParser = require("parser.tag_parser")
|
||||||
local MarkdownGenerator = require("parser.markdown_generator")
|
local MarkdownGenerator = require("parser.markdown_generator")
|
||||||
|
|
||||||
local Parser = {}
|
local Parser = {}
|
||||||
@@ -9,21 +10,23 @@ function Parser.extractComments(content)
|
|||||||
for line in content:gmatch("[^\r\n]+") do
|
for line in content:gmatch("[^\r\n]+") do
|
||||||
table.insert(lines, line)
|
table.insert(lines, line)
|
||||||
end
|
end
|
||||||
return CommentExtractor.extractComments(lines)
|
return CommentExtractor.extractBlocks(lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Generate markdown from comment blocks
|
--- Generate markdown from comment blocks
|
||||||
function Parser.generateMarkdown(commentBlocks)
|
function Parser.generateMarkdown(commentBlocks)
|
||||||
local parsedBlocks = {}
|
local markdown = {}
|
||||||
|
|
||||||
-- Parse each block using the appropriate parser
|
-- Parse each block and generate markdown
|
||||||
for _, block in ipairs(commentBlocks) do
|
for _, block in ipairs(commentBlocks) do
|
||||||
local parsedBlock = MarkdownGenerator.parseBlock(block)
|
local tags = TagParser.parseAllTags(block.comments)
|
||||||
table.insert(parsedBlocks, parsedBlock)
|
local blockMarkdown = MarkdownGenerator.generateBlock(block, tags)
|
||||||
|
if blockMarkdown and blockMarkdown ~= "" then
|
||||||
|
table.insert(markdown, blockMarkdown)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Generate markdown from parsed blocks
|
return table.concat(markdown, "\n\n")
|
||||||
return MarkdownGenerator.generateMarkdown(parsedBlocks)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Parser
|
return Parser
|
||||||
@@ -1,142 +1,143 @@
|
|||||||
local markdownGenerator = {}
|
local MarkdownGenerator = {}
|
||||||
local TagParserRegistry = require("parser.tag_parser_registry")
|
|
||||||
|
|
||||||
--- Determines which block parser should handle a given block
|
--- Generate markdown for a block
|
||||||
--- @param block table The comment block with context
|
function MarkdownGenerator.generateBlock(block, tags)
|
||||||
--- @return string|nil The block type that can handle this block
|
if not block.codeContext then
|
||||||
function markdownGenerator.detectBlockType(block)
|
return MarkdownGenerator.generateStandaloneComment(tags)
|
||||||
local blockParsers = TagParserRegistry.getAllBlocks()
|
|
||||||
|
|
||||||
for blockType, parser in pairs(blockParsers) do
|
|
||||||
if parser.canParse and parser.canParse(block) then
|
|
||||||
return blockType
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil -- No specific block parser found, use generic parsing
|
if block.codeContext.type == "function" then
|
||||||
end
|
return MarkdownGenerator.generateFunction(block.codeContext, tags)
|
||||||
|
elseif block.codeContext.type == "class" then
|
||||||
--- Parses a block using the appropriate block parser
|
return MarkdownGenerator.generateClass(block.codeContext, tags)
|
||||||
--- @param block table The comment block to parse
|
elseif block.codeContext.type == "variable" then
|
||||||
--- @return table The parsed block data
|
return MarkdownGenerator.generateVariable(block.codeContext, tags)
|
||||||
function markdownGenerator.parseBlock(block)
|
|
||||||
local blockType = markdownGenerator.detectBlockType(block)
|
|
||||||
|
|
||||||
if blockType then
|
|
||||||
local parser = TagParserRegistry.getBlock(blockType)
|
|
||||||
return parser.parse(block)
|
|
||||||
else
|
else
|
||||||
-- Generic parsing using individual tag parsers
|
return MarkdownGenerator.generateGeneric(block.codeContext, tags)
|
||||||
return markdownGenerator.parseGenericBlock(block)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Generic block parsing using individual tag parsers
|
--- Generate markdown for function
|
||||||
--- @param block table The comment block to parse
|
function MarkdownGenerator.generateFunction(context, tags)
|
||||||
--- @return table The parsed block data
|
|
||||||
function markdownGenerator.parseGenericBlock(block)
|
|
||||||
local parsedBlock = {
|
|
||||||
type = "generic",
|
|
||||||
tags = {},
|
|
||||||
content = {},
|
|
||||||
context = block.context
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line in ipairs(block.comments) do
|
|
||||||
local parsed = false
|
|
||||||
local tagParsers = TagParserRegistry.getAllTags()
|
|
||||||
|
|
||||||
-- Try each registered tag parser
|
|
||||||
for tagName, parser in pairs(tagParsers) do
|
|
||||||
local result = parser.parse(line)
|
|
||||||
if result then
|
|
||||||
table.insert(parsedBlock.tags, result)
|
|
||||||
parsed = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- If no tag parser matched, treat as regular content
|
|
||||||
if not parsed then
|
|
||||||
table.insert(parsedBlock.content, line)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return parsedBlock
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Converts parsed blocks to markdown
|
|
||||||
--- @param parsedBlocks table Array of parsed blocks
|
|
||||||
--- @return string The generated markdown
|
|
||||||
function markdownGenerator.generateMarkdown(parsedBlocks)
|
|
||||||
local markdown = {}
|
|
||||||
|
|
||||||
for _, block in ipairs(parsedBlocks) do
|
|
||||||
if block.type == "function" then
|
|
||||||
table.insert(markdown, markdownGenerator.generateFunctionMarkdown(block))
|
|
||||||
else
|
|
||||||
table.insert(markdown, markdownGenerator.generateGenericMarkdown(block))
|
|
||||||
end
|
|
||||||
table.insert(markdown, "") -- Empty line between blocks
|
|
||||||
end
|
|
||||||
|
|
||||||
return table.concat(markdown, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Generate markdown for function blocks
|
|
||||||
--- @param functionBlock table The parsed function block
|
|
||||||
--- @return string The generated markdown
|
|
||||||
function markdownGenerator.generateFunctionMarkdown(functionBlock)
|
|
||||||
local md = {}
|
local md = {}
|
||||||
|
|
||||||
table.insert(md, string.format("## Function: %s", functionBlock.name))
|
table.insert(md, string.format("### %s", context.name))
|
||||||
|
table.insert(md, "")
|
||||||
|
|
||||||
if functionBlock.shortDescription then
|
if tags.shortDescription then
|
||||||
table.insert(md, string.format("**Description:** %s", functionBlock.shortDescription))
|
table.insert(md, tags.shortDescription)
|
||||||
|
table.insert(md, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
if #functionBlock.params > 0 then
|
if #tags.description > 0 then
|
||||||
|
table.insert(md, table.concat(tags.description, " "))
|
||||||
|
table.insert(md, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
if #tags.params > 0 then
|
||||||
table.insert(md, "**Parameters:**")
|
table.insert(md, "**Parameters:**")
|
||||||
for _, param in ipairs(functionBlock.params) do
|
for _, param in ipairs(tags.params) do
|
||||||
table.insert(md, string.format("- `%s` (%s): %s", param.name, param.type, param.description))
|
table.insert(md, string.format("- `%s` (%s): %s", param.name, param.dataType, param.description))
|
||||||
end
|
end
|
||||||
|
table.insert(md, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
if #functionBlock.returns > 0 then
|
if #tags.returns > 0 then
|
||||||
table.insert(md, "**Returns:**")
|
table.insert(md, "**Returns:**")
|
||||||
for _, ret in ipairs(functionBlock.returns) do
|
for _, ret in ipairs(tags.returns) do
|
||||||
table.insert(md, string.format("- `%s` (%s): %s", ret.name, ret.type, ret.description))
|
table.insert(md, string.format("- `%s` (%s): %s", ret.name, ret.dataType, ret.description))
|
||||||
end
|
end
|
||||||
|
table.insert(md, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
if functionBlock.visibility ~= "public" then
|
if tags.visibility ~= "public" then
|
||||||
table.insert(md, string.format("**Visibility:** %s", functionBlock.visibility))
|
table.insert(md, string.format("**Visibility:** %s", tags.visibility))
|
||||||
|
table.insert(md, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(md, "\n")
|
return table.concat(md, "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Generate markdown for generic blocks
|
--- Generate markdown for class
|
||||||
--- @param block table The parsed generic block
|
function MarkdownGenerator.generateClass(context, tags)
|
||||||
--- @return string The generated markdown
|
|
||||||
function markdownGenerator.generateGenericMarkdown(block)
|
|
||||||
local md = {}
|
local md = {}
|
||||||
|
|
||||||
-- Generate markdown for tags
|
table.insert(md, string.format("## Class: %s", context.name))
|
||||||
if #block.tags > 0 then
|
if tags.class and tags.class.parent then
|
||||||
table.insert(md, "### Tags")
|
table.insert(md, string.format("*Extends: %s*", tags.class.parent))
|
||||||
for _, tag in ipairs(block.tags) do
|
end
|
||||||
table.insert(md, string.format("- **%s**: %s", tag.name, tag.description))
|
table.insert(md, "")
|
||||||
end
|
|
||||||
|
if tags.shortDescription then
|
||||||
|
table.insert(md, tags.shortDescription)
|
||||||
|
table.insert(md, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Generate markdown for content
|
if #tags.description > 0 then
|
||||||
if #block.content > 0 then
|
table.insert(md, table.concat(tags.description, " "))
|
||||||
table.insert(md, "### Content")
|
table.insert(md, "")
|
||||||
table.insert(md, table.concat(block.content, "\n"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(md, "\n\n")
|
return table.concat(md, "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
return markdownGenerator
|
--- Generate markdown for standalone comments or properties
|
||||||
|
function MarkdownGenerator.generateStandaloneComment(tags)
|
||||||
|
local md = {}
|
||||||
|
|
||||||
|
if #tags.properties > 0 then
|
||||||
|
for _, prop in ipairs(tags.properties) do
|
||||||
|
table.insert(md, string.format("**Property:** `%s` (%s) - %s", prop.name, prop.dataType, prop.description))
|
||||||
|
end
|
||||||
|
table.insert(md, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
if #tags.description > 0 then
|
||||||
|
table.insert(md, table.concat(tags.description, " "))
|
||||||
|
table.insert(md, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
return table.concat(md, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Generate markdown for variables
|
||||||
|
function MarkdownGenerator.generateVariable(context, tags)
|
||||||
|
local md = {}
|
||||||
|
|
||||||
|
table.insert(md, string.format("### %s", context.name))
|
||||||
|
table.insert(md, "")
|
||||||
|
|
||||||
|
if tags.shortDescription then
|
||||||
|
table.insert(md, tags.shortDescription)
|
||||||
|
table.insert(md, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
if #tags.description > 0 then
|
||||||
|
table.insert(md, table.concat(tags.description, " "))
|
||||||
|
table.insert(md, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
return table.concat(md, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Generate markdown for generic code
|
||||||
|
function MarkdownGenerator.generateGeneric(context, tags)
|
||||||
|
local md = {}
|
||||||
|
|
||||||
|
table.insert(md, string.format("### %s", context.name))
|
||||||
|
table.insert(md, "")
|
||||||
|
|
||||||
|
if tags.shortDescription then
|
||||||
|
table.insert(md, tags.shortDescription)
|
||||||
|
table.insert(md, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
if #tags.description > 0 then
|
||||||
|
table.insert(md, table.concat(tags.description, " "))
|
||||||
|
table.insert(md, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
return table.concat(md, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
return MarkdownGenerator
|
||||||
@@ -1,19 +1,117 @@
|
|||||||
local tagParser = {}
|
local TagParser = {}
|
||||||
|
|
||||||
local function parseTag(tagLine)
|
--- Parse all tags from a list of comment lines
|
||||||
local tag, content = tagLine:match("^%s*@(.-)%s*(.*)$")
|
function TagParser.parseAllTags(commentLines)
|
||||||
return tag, content
|
local tags = {
|
||||||
end
|
shortDescription = nil,
|
||||||
|
description = {},
|
||||||
|
params = {},
|
||||||
|
returns = {},
|
||||||
|
visibility = "public",
|
||||||
|
properties = {},
|
||||||
|
class = nil,
|
||||||
|
other = {}
|
||||||
|
}
|
||||||
|
|
||||||
function tagParser.parseTags(commentLines)
|
|
||||||
local tags = {}
|
|
||||||
for _, line in ipairs(commentLines) do
|
for _, line in ipairs(commentLines) do
|
||||||
local tag, content = parseTag(line)
|
local parsed = TagParser.parseSingleLine(line)
|
||||||
if tag then
|
if parsed then
|
||||||
tags[tag] = content
|
TagParser.addToTags(tags, parsed)
|
||||||
|
else
|
||||||
|
-- Regular description line
|
||||||
|
local desc = line:match("^%-*%s*(.+)$")
|
||||||
|
if desc and not desc:match("^@") then
|
||||||
|
table.insert(tags.description, desc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
end
|
end
|
||||||
|
|
||||||
return tagParser
|
--- Parse a single comment line for tags
|
||||||
|
function TagParser.parseSingleLine(line)
|
||||||
|
-- @shortDescription
|
||||||
|
local shortDesc = line:match("^%-*%s*@shortDescription%s+(.+)$")
|
||||||
|
if shortDesc then
|
||||||
|
return {type = "shortDescription", value = shortDesc}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- @param name type description
|
||||||
|
local paramName, paramType, paramDesc = line:match("^%-*%s*@param%s+(%S+)%s+(%S+)%s*(.*)$")
|
||||||
|
if paramName then
|
||||||
|
return {
|
||||||
|
type = "param",
|
||||||
|
name = paramName,
|
||||||
|
dataType = paramType,
|
||||||
|
description = paramDesc or ""
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- @return type name description
|
||||||
|
local returnType, returnName, returnDesc = line:match("^%-*%s*@return%s+(%S+)%s+(%S+)%s*(.*)$")
|
||||||
|
if returnType then
|
||||||
|
return {
|
||||||
|
type = "return",
|
||||||
|
dataType = returnType,
|
||||||
|
name = returnName or "",
|
||||||
|
description = returnDesc or ""
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- @property name type description
|
||||||
|
local propName, propType, propDesc = line:match("^%-*%s*@property%s+(%S+)%s+(%S+)%s*(.*)$")
|
||||||
|
if propName then
|
||||||
|
return {
|
||||||
|
type = "property",
|
||||||
|
name = propName,
|
||||||
|
dataType = propType,
|
||||||
|
description = propDesc or ""
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- @class name : parent
|
||||||
|
local className, parentClass = line:match("^%-*%s*@class%s+(%S+)%s*:%s*(%S+)")
|
||||||
|
if not className then
|
||||||
|
className = line:match("^%-*%s*@class%s+(%S+)")
|
||||||
|
end
|
||||||
|
if className then
|
||||||
|
return {
|
||||||
|
type = "class",
|
||||||
|
name = className,
|
||||||
|
parent = parentClass or nil
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Visibility tags
|
||||||
|
if line:match("^%-*%s*@private%s*$") then
|
||||||
|
return {type = "visibility", value = "private"}
|
||||||
|
end
|
||||||
|
|
||||||
|
if line:match("^%-*%s*@protected%s*$") then
|
||||||
|
return {type = "visibility", value = "protected"}
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Add parsed tag to the tags collection
|
||||||
|
function TagParser.addToTags(tags, parsed)
|
||||||
|
if parsed.type == "shortDescription" then
|
||||||
|
tags.shortDescription = parsed.value
|
||||||
|
elseif parsed.type == "param" then
|
||||||
|
table.insert(tags.params, parsed)
|
||||||
|
elseif parsed.type == "return" then
|
||||||
|
table.insert(tags.returns, parsed)
|
||||||
|
elseif parsed.type == "property" then
|
||||||
|
table.insert(tags.properties, parsed)
|
||||||
|
elseif parsed.type == "class" then
|
||||||
|
tags.class = parsed
|
||||||
|
elseif parsed.type == "visibility" then
|
||||||
|
tags.visibility = parsed.value
|
||||||
|
else
|
||||||
|
table.insert(tags.other, parsed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return TagParser
|
||||||
Reference in New Issue
Block a user