feat(scraper): detect function parameters table
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/build Pipeline was successful Details

This commit is contained in:
Aire-One 2022-11-04 19:46:10 +01:00
parent cfa32b7199
commit 0bea4723b5
1 changed files with 35 additions and 10 deletions

View File

@ -27,19 +27,44 @@ local function extract_item_name(item_name_node: scan.HTMLNode): string
end
local function extract_function_parameters(function_parameters_node: scan.HTMLNode): { Function_Info.Parameter }
local query_selectors = {
name = "span.parameter",
types = "span.types"
}
local current_record_parameter: string = nil
return scraper_utils.scrape_tuples(
return scraper_utils.scrape(
function_parameters_node:outer_html(),
{ query_selectors.name, query_selectors.types },
function(nodes: { string : scan.HTMLNode | nil }): Function_Info.Parameter
return {
name = extract_node_text(nodes[query_selectors.name]),
types = parse_parameter_types(extract_node_text(nodes[query_selectors.types])),
"tr",
function(line_node: scan.HTMLNode): Function_Info.Parameter
if line_node.attr ~= nil and line_node.attr.class == "see_also_sublist" then
log:debug("subtable found, skipping")
return nil
end
local query_selectors = {
name = "span.parameter",
types = "span.types"
}
return scraper_utils.scrape_tuples(
line_node:outer_html(),
{ query_selectors.name, query_selectors.types },
function(nodes: { string : scan.HTMLNode | nil }): Function_Info.Parameter
local name = extract_node_text(nodes[query_selectors.name] as scan.HTMLNode)
local types = parse_parameter_types(extract_node_text(nodes[query_selectors.types] as scan.HTMLNode))
if types == List({ "table" }) then
local record_name = utils.capitalize(name)
current_record_parameter = record_name
return {
name = name,
types = List({ record_name }),
}
end
return {
name = name,
types = types,
}
end
)[1]
end
)
end