WIP: awesomerc.tl should work #85

Draft
Aire-One wants to merge 40 commits from feat/#58 into master
2 changed files with 51 additions and 9 deletions
Showing only changes of commit 2e2e74745d - Show all commits

View File

@ -937,4 +937,39 @@ describe("Scrap documentation", function()
global = false,
token = "module",
}))
it("should produce Variable for content in the Fields section", test(
[[
<h2 class="section-header "><a name="Fields"></a>Fields</h2>
<dl class="function">
<dt>
<a class="copy-link js-copy-link" name="primary" href="#primary">🔗</a>
<strong><span class="function_modname">screen.</span>primary</strong>
<span class="proptype"><span class="summary_type">screen</span></span>
<span class="baseclass"></span>
</dt>
<dd></dd>
</dl>
]],
"field_variable",
{
children = {
{
children = {},
name = "Signal",
token = "enum",
},
{
name = "primary",
types = { "screen" },
token = "variable",
}
},
name = "Field_variable",
module_path = "field_variable",
dependencies = {},
descendants = {},
global = false,
token = "module",
}))
end)

View File

@ -34,7 +34,7 @@ local function extract_item_name(item_name_node: scan.HTMLNode): string, string
end
local module_name_node <const> = scraper_utils.find(item_name_node:outer_html(), "span.function_modname")[1]
local module_name = module_name_node and module_name_node:inner_text():gsub("[%.:]$", "")
local name <const> = item_name_node:inner_text():gsub("^.*[%.:](.+)%s*[%(%{].*[%)%}]", "%1")
local name <const> = item_name_node:inner_text():gsub("(.+)[%(%{].*$", "%1"):gsub("^.*[%.:](.+)", "%1")
return utils.sanitize_string(name), module_name and utils.sanitize_string(module_name) or nil
end
@ -174,11 +174,11 @@ local function extract_section_functions(dl: string, module_name: string | nil):
return functions, other_functions
end
local function extract_section_variables(dl: string): { Node }, { string }
local function extract_section_variables(dl: string, with_constraint: boolean): { Node }, { string }
local query_selectors <const>: { string : string } = {
variable_name = "dt strong",
variable_summary_type = "dt span.summary_type",
variable_property_constraint = "dd span.property_type",
variable_property_constraint = with_constraint and "dd span.property_type",
}
local variables <const>: { Node } = {}
@ -194,11 +194,13 @@ local function extract_section_variables(dl: string): { Node }, { string }
if #node.types == 1 and node.types[1] == "string" then
log:debug("extract variable string with constraints, this is an enum", { name = node.name })
local type_enum <const> = ast.create_node("enum", utils.capitalize(node.name))
for _, constraint in ipairs(extract_property_constraints(nodes[query_selectors.variable_property_constraint])) do
table.insert(
type_enum.children,
ast.create_node("identifier", (constraint:gsub("&quot;", "")))
)
if with_constraint then
for _, constraint in ipairs(extract_property_constraints(nodes[query_selectors.variable_property_constraint])) do
table.insert(
type_enum.children,
ast.create_node("identifier", (constraint:gsub("&quot;", "")))
)
end
end
if #type_enum.children == 0 then
log:debug("Enum has no children, get back to variable", { name = node.name })
@ -235,6 +237,7 @@ end
local enum Section
"Constructors"
"Static module functions"
"Fields"
"Object properties"
"Object methods"
"Signals"
@ -259,8 +262,12 @@ local section_scrapers <total>: { Section : function(html: string, record_name:
local static_functions, other_functions = extract_section_functions(html, module_name)
return static_functions, other_functions, {}
end,
["Fields"] = function(html: string): { Node }, { Node }, { string }
local fields = extract_section_variables(html)
return fields, {}, {}
end,
["Object properties"] = function(html: string): { Node }, { Node }, { string }
local properties, signals = extract_section_variables(html)
local properties, signals = extract_section_variables(html, true)
return properties, {}, signals
end,
["Object methods"] = function(html: string, record_name: string): { Node }, { Node }, { string }