Compare commits
2 Commits
2e72de2ea6
...
a169c6c74b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a169c6c74b | ||
|
|
78cf0eb980 |
35
init.lua
35
init.lua
@@ -8,6 +8,15 @@ local M = {}
|
||||
-- (`function M.foo`) — Lua treats them semantically identical.
|
||||
-- Returns: { public = ["foo","bar",...], private = ["_baz",...] }
|
||||
function M.parse_lua_surface(source_string)
|
||||
-- Strip Lua line-comments (-- to end-of-line) before pattern matching.
|
||||
-- This prevents false-positive matches inside commented-out forward-compat
|
||||
-- stubs (e.g. DEPRECATED-MVP placeholders).
|
||||
-- Block comments (--[[...]]) are not handled; not used in Sporel-lib code.
|
||||
-- Caveat: a literal "--" inside a string would also be stripped; acceptable
|
||||
-- for the lint-tool's purpose (false-negatives in pathological string cases
|
||||
-- are preferable to false-positives on commented stubs).
|
||||
local stripped = string.gsub(source_string, "%-%-[^\n]*", "")
|
||||
|
||||
local public = {}
|
||||
local private = {}
|
||||
local seen = {}
|
||||
@@ -23,12 +32,12 @@ function M.parse_lua_surface(source_string)
|
||||
end
|
||||
|
||||
-- Form 1: M.foo = function(...)
|
||||
for name in string.gmatch(source_string, "M%.([_%w]+)%s*=%s*function") do
|
||||
for name in string.gmatch(stripped, "M%.([_%w]+)%s*=%s*function") do
|
||||
classify(name)
|
||||
end
|
||||
|
||||
-- Form 2: function M.foo(...)
|
||||
for name in string.gmatch(source_string, "function%s+M%.([_%w]+)") do
|
||||
for name in string.gmatch(stripped, "function%s+M%.([_%w]+)") do
|
||||
classify(name)
|
||||
end
|
||||
|
||||
@@ -41,6 +50,8 @@ end
|
||||
-- Returns: { documented = ["bind","unbind",...] }
|
||||
function M.parse_readme_api(markdown_string)
|
||||
local documented = {}
|
||||
local seen = {}
|
||||
|
||||
-- Find "## API" section start (allow trailing whitespace/content)
|
||||
local api_start = string.find(markdown_string, "\n## API[%s\n]")
|
||||
if not api_start then
|
||||
@@ -50,10 +61,24 @@ function M.parse_readme_api(markdown_string)
|
||||
local api_end = string.find(markdown_string, "\n## ", api_start + 5)
|
||||
local section = string.sub(markdown_string, api_start, api_end or #markdown_string)
|
||||
|
||||
-- Match H3 headers: "### `[namespace.]name(...)`" — capture name portion
|
||||
for line in string.gmatch(section, "###%s+`[^.`]*%.?([_%w]+)%s*[%(`]") do
|
||||
table.insert(documented, line)
|
||||
-- Two-pass matching to handle both namespace-prefixed and namespace-less
|
||||
-- function-names in H3 headers.
|
||||
-- Pattern 1: namespaced — "### `ns.func(...)`" -> capture "func"
|
||||
for name in string.gmatch(section, "###%s+`[%w_]+%.([_%w]+)") do
|
||||
if not seen[name] then
|
||||
seen[name] = true
|
||||
table.insert(documented, name)
|
||||
end
|
||||
end
|
||||
-- Pattern 2: namespace-less — "### `func(...)`" -> capture "func"
|
||||
-- The seen-set prevents re-matching names already captured by pattern 1.
|
||||
for name in string.gmatch(section, "###%s+`([_%w]+)%s*[%(`]") do
|
||||
if not seen[name] then
|
||||
seen[name] = true
|
||||
table.insert(documented, name)
|
||||
end
|
||||
end
|
||||
|
||||
return { documented = documented }
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user