Instance level methods should have a self parameter (#26) #28

Merged
Aire-One merged 1 commits from feat/#26 into master 2022-10-31 11:34:21 +01:00
4 changed files with 17 additions and 10 deletions

View File

@ -6,6 +6,8 @@ local record Module_Doc
Module_Doc: Module_Doc Module_Doc: Module_Doc
record_name: string
constructors: List<Function_Info.Function_Info> constructors: List<Function_Info.Function_Info>
methods: List<Function_Info.Function_Info> methods: List<Function_Info.Function_Info>
static_functions: List<Function_Info.Function_Info> static_functions: List<Function_Info.Function_Info>

View File

@ -8,7 +8,7 @@ local snippets = require "generator.snippets"
local tmpl = [[ local tmpl = [[
-- Auto generated file (Do not manually edit this file!) -- Auto generated file (Do not manually edit this file!)
local record $(mod_name) local record $(module.record_name)
# if #module.signals then # if #module.signals then
$(snippets.indent(snippets.render_enum("Signal", module.signals))) $(snippets.indent(snippets.render_enum("Signal", module.signals)))
@ -19,15 +19,14 @@ $(snippets.indent(snippets.render_record_functions(module.methods)))
# end -- /methods # end -- /methods
end end
return $(mod_name) return $(module.record_name)
]] ]]
local module = {} local module = {}
function module.generate_teal(mod: string, data: Module_Doc.Module_Doc): string function module.generate_teal(data: Module_Doc.Module_Doc): string
local tmpl_args = { local tmpl_args = {
ipairs = ipairs, ipairs = ipairs,
mod_name = mod,
module = data, module = data,
snippets = snippets, snippets = snippets,
} }

View File

@ -26,14 +26,13 @@ log:info("Finished Module List scrapping, found " .. #module_infos .. " modules"
local html = local html =
crawler.fetch(property.base_url .. "/widgets/wibox.widget.textbox.html") crawler.fetch(property.base_url .. "/widgets/wibox.widget.textbox.html")
local module_doc = scraper.module_doc.get_doc_from_page(html) local module_doc = scraper.module_doc.get_doc_from_page(html, "wibox.widget.textbox")
-- log:info(inspect { module_doc = module_doc }) -- log:info(inspect { module_doc = module_doc })
-- -- local items = scraper.get_doc_from_page(page) -- -- local items = scraper.get_doc_from_page(page)
-- -- log:info(inspect { items }) -- -- log:info(inspect { items })
local mod = "textbox"
filesystem.file_writer.write( filesystem.file_writer.write(
generator.teal_type_definitions.generate_teal(mod, module_doc), generator.teal_type_definitions.generate_teal(module_doc),
property.out_directory .. "/" .. mod .. ".d.tl" property.out_directory .. "/textbox.d.tl"
) )

View File

@ -90,7 +90,7 @@ end
local module = {} local module = {}
function module.get_doc_from_page(html: string): Module_Doc.Module_Doc function module.get_doc_from_page(html: string, module_name: string): Module_Doc.Module_Doc
local nodes = scraper_utils.extract_nodes(html, { local nodes = scraper_utils.extract_nodes(html, {
"h2.section-header", "h2.section-header",
"dl.function", "dl.function",
@ -101,6 +101,7 @@ function module.get_doc_from_page(html: string): Module_Doc.Module_Doc
end end
local module_doc = Module_Doc() local module_doc = Module_Doc()
module_doc.record_name = module_name:gsub(".*%.", ""):gsub("^%l", string.upper)
for i = 1, #nodes:get("h2.section-header") do for i = 1, #nodes:get("h2.section-header") do
local h2 = nodes:get("h2.section-header")[i] local h2 = nodes:get("h2.section-header")[i]
@ -116,7 +117,13 @@ function module.get_doc_from_page(html: string): Module_Doc.Module_Doc
elseif section_name == "Deprecated object properties" then elseif section_name == "Deprecated object properties" then
log:warn("Not implemented: Deprecated object properties") log:warn("Not implemented: Deprecated object properties")
elseif section_name == "Object methods" then elseif section_name == "Object methods" then
module_doc.methods = List(extract_section_functions(dl_html)) module_doc.methods = List(extract_section_functions(dl_html)):map(function(method: Function_Info.Function_Info): Function_Info.Function_Info
method.parameters:insert(1, {
name = "self",
types = List({ module_doc.record_name }),
})
return method
end)
elseif section_name == "Signals" then elseif section_name == "Signals" then
module_doc.signals = List(extract_section_signal(dl_html)) module_doc.signals = List(extract_section_signal(dl_html))
else else