feat: add parse_readme_api (S2 Phase 1)
Extracts H3-headers from README ## API section. Pattern handles
optional namespace-prefix (e.g. 'input.bind' -> 'bind'). Returns
{ documented = [...] } per spec section 4.2.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
22
init.lua
22
init.lua
@@ -18,4 +18,26 @@ function M.parse_lua_surface(source_string)
|
|||||||
return { public = public, private = private }
|
return { public = public, private = private }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Extracts documented function-names from README's "## API" section.
|
||||||
|
-- Parses H3-Headers like "### `input.bind(action_name, keys)`" → "bind".
|
||||||
|
-- Convention: H3 header opens with backtick, function-name follows after optional namespace-dot.
|
||||||
|
-- Returns: { documented = ["bind","unbind",...] }
|
||||||
|
function M.parse_readme_api(markdown_string)
|
||||||
|
local documented = {}
|
||||||
|
-- Find "## API" section start (allow trailing whitespace/content)
|
||||||
|
local api_start = string.find(markdown_string, "\n## API[%s\n]")
|
||||||
|
if not api_start then
|
||||||
|
return { documented = documented }
|
||||||
|
end
|
||||||
|
-- Find next H2 (terminate API section)
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
return { documented = documented }
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user