Small Docs test
This commit is contained in:
34
tools/BasaltDoc/parsers/classParser.lua
Normal file
34
tools/BasaltDoc/parsers/classParser.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
local helper = require("utils.helper")
|
||||
local logger = require("utils.logger")
|
||||
local classParser = {}
|
||||
|
||||
function classParser.parse(annotations, line)
|
||||
local classLine = helper.findAnnotationLine(annotations, "class")
|
||||
if not classLine then
|
||||
return nil
|
||||
end
|
||||
local name, extends = classLine:match("^%-%-%-?%s*@class%s*([%w_%.]+)%s*:?%s*([%w_%.]*)")
|
||||
|
||||
local class = {
|
||||
type = "class",
|
||||
name = name,
|
||||
extends = extends ~= "" and extends or nil,
|
||||
description = nil,
|
||||
properties = {},
|
||||
events = {},
|
||||
functions = {},
|
||||
skip = false
|
||||
}
|
||||
|
||||
if classParser.handlers then
|
||||
helper.applyAnnotations(annotations, class, classParser.handlers)
|
||||
end
|
||||
|
||||
return class
|
||||
end
|
||||
|
||||
function classParser.setHandlers(handlers)
|
||||
classParser.handlers = handlers
|
||||
end
|
||||
|
||||
return classParser
|
||||
37
tools/BasaltDoc/parsers/eventParser.lua
Normal file
37
tools/BasaltDoc/parsers/eventParser.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
local helper = require("utils.helper")
|
||||
local eventParser = {}
|
||||
|
||||
function eventParser.parse(annotations, line)
|
||||
local eventLine = helper.findAnnotationLine(annotations, "event")
|
||||
if not eventLine then return nil end
|
||||
local content = table.concat(annotations, " ")
|
||||
local name, params, desc = eventLine:match("^%-%-%-?%s*@event%s*([%w_]+)%s*({[^}]*})%s*(.*)")
|
||||
|
||||
if not name then
|
||||
name, desc = eventLine:match("^%-%-%-?%s*@event%s*([%w_]+)%s+(.*)")
|
||||
params = "{}"
|
||||
end
|
||||
|
||||
if not name then
|
||||
print("Warning: Could not parse @event annotation: " .. eventLine)
|
||||
return nil
|
||||
end
|
||||
|
||||
local evt = {
|
||||
type = "event",
|
||||
name = name,
|
||||
params = params or "{}",
|
||||
description = desc or ""
|
||||
}
|
||||
|
||||
helper.applyAnnotations(annotations, evt, eventParser.handlers)
|
||||
|
||||
return evt
|
||||
end
|
||||
|
||||
function eventParser.setHandlers(handlers)
|
||||
eventParser.handlers = handlers
|
||||
end
|
||||
|
||||
return eventParser
|
||||
|
||||
48
tools/BasaltDoc/parsers/functionParser.lua
Normal file
48
tools/BasaltDoc/parsers/functionParser.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
local helper = require("utils.helper")
|
||||
local functionParser = {}
|
||||
|
||||
function functionParser.parse(annotations, line)
|
||||
local name = line:match("^function%s+([%w_%.]+[:.]?[%w_]+)") or line:match("^function%s+([%w_]+)")
|
||||
if not name then
|
||||
print("Warning: Could not extract function name from line: " .. line)
|
||||
return nil
|
||||
end
|
||||
local f = {
|
||||
type = "function",
|
||||
name = name,
|
||||
description = nil,
|
||||
shortDescription = nil,
|
||||
params = {},
|
||||
returns = {},
|
||||
visibility = "public"
|
||||
}
|
||||
|
||||
if functionParser.handlers then
|
||||
helper.applyAnnotations(annotations, f, functionParser.handlers)
|
||||
end
|
||||
|
||||
local funcName = line:match("function ([%w_%.]+)")
|
||||
if funcName then
|
||||
if funcName:find(":") then
|
||||
f.name = funcName:match(":([%w_]+)")
|
||||
elseif funcName:find("%.") then
|
||||
f.name = funcName:match("%.([%w_]+)")
|
||||
else
|
||||
f.name = funcName
|
||||
end
|
||||
end
|
||||
|
||||
if line:match("function [%w_%.]+:") then
|
||||
f.static = false
|
||||
else
|
||||
f.static = true
|
||||
end
|
||||
|
||||
return f
|
||||
end
|
||||
|
||||
function functionParser.setHandlers(handlers)
|
||||
functionParser.handlers = handlers
|
||||
end
|
||||
|
||||
return functionParser
|
||||
21
tools/BasaltDoc/parsers/globalParser.lua
Normal file
21
tools/BasaltDoc/parsers/globalParser.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
local helper = require("utils.helper")
|
||||
local logger = require("utils.logger")
|
||||
local globalParser = {}
|
||||
|
||||
function globalParser.parse(annotations, line)
|
||||
local global = {
|
||||
description = nil
|
||||
}
|
||||
|
||||
if globalParser.handlers then
|
||||
helper.applyAnnotations(annotations, global, globalParser.handlers)
|
||||
end
|
||||
return global
|
||||
end
|
||||
|
||||
function globalParser.setHandlers(handlers)
|
||||
globalParser.handlers = handlers
|
||||
end
|
||||
|
||||
return globalParser
|
||||
|
||||
30
tools/BasaltDoc/parsers/propertyParser.lua
Normal file
30
tools/BasaltDoc/parsers/propertyParser.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
local helper = require("utils.helper")
|
||||
local propertyParser = {}
|
||||
|
||||
function propertyParser.parse(annotations, line)
|
||||
local propLine = helper.findAnnotationLine(annotations, "property")
|
||||
if not propLine then return nil end
|
||||
local content = table.concat(annotations, " ")
|
||||
local name, type, default, desc = propLine:match("^%-%-%-?%s*@property%s*([%w_]+)%s+([%w_|%[%]]+)%s+([^%s]+)%s*(.*)")
|
||||
if not name then
|
||||
print("Warning: Could not parse @property annotation: " .. propLine)
|
||||
return nil
|
||||
end
|
||||
local prop = {
|
||||
type = "property",
|
||||
name = name,
|
||||
propType = type or "any",
|
||||
default = default or "nil",
|
||||
description = desc or ""
|
||||
}
|
||||
|
||||
helper.applyAnnotations(annotations, prop, propertyParser.handlers)
|
||||
|
||||
return prop
|
||||
end
|
||||
|
||||
function propertyParser.setHandlers(handlers)
|
||||
propertyParser.handlers = handlers
|
||||
end
|
||||
|
||||
return propertyParser
|
||||
Reference in New Issue
Block a user