From b4fee9f3feab67bd85aeaab0e48eb9296cdb5e95 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Sun, 30 Oct 2022 18:27:09 +0100 Subject: [PATCH] fix(scraper): add self parameter to Object Methods This also introduce a way to manage the record_name from the Module_Doc. --- src/awesomewm.d.tl/entity/Module_Doc.tl | 2 ++ src/awesomewm.d.tl/generator/teal_type_definitions.tl | 7 +++---- src/awesomewm.d.tl/init.tl | 7 +++---- src/awesomewm.d.tl/scraper/module_doc.tl | 11 +++++++++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/awesomewm.d.tl/entity/Module_Doc.tl b/src/awesomewm.d.tl/entity/Module_Doc.tl index 67491cf..d8a687e 100644 --- a/src/awesomewm.d.tl/entity/Module_Doc.tl +++ b/src/awesomewm.d.tl/entity/Module_Doc.tl @@ -6,6 +6,8 @@ local record Module_Doc Module_Doc: Module_Doc + record_name: string + constructors: List methods: List static_functions: List diff --git a/src/awesomewm.d.tl/generator/teal_type_definitions.tl b/src/awesomewm.d.tl/generator/teal_type_definitions.tl index c9d75cd..c96d66f 100644 --- a/src/awesomewm.d.tl/generator/teal_type_definitions.tl +++ b/src/awesomewm.d.tl/generator/teal_type_definitions.tl @@ -8,7 +8,7 @@ local snippets = require "generator.snippets" local tmpl = [[ -- Auto generated file (Do not manually edit this file!) -local record $(mod_name) +local record $(module.record_name) # if #module.signals then $(snippets.indent(snippets.render_enum("Signal", module.signals))) @@ -19,15 +19,14 @@ $(snippets.indent(snippets.render_record_functions(module.methods))) # end -- /methods end -return $(mod_name) +return $(module.record_name) ]] 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 = { ipairs = ipairs, - mod_name = mod, module = data, snippets = snippets, } diff --git a/src/awesomewm.d.tl/init.tl b/src/awesomewm.d.tl/init.tl index 3f61763..9486a88 100644 --- a/src/awesomewm.d.tl/init.tl +++ b/src/awesomewm.d.tl/init.tl @@ -26,14 +26,13 @@ log:info("Finished Module List scrapping, found " .. #module_infos .. " modules" local 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 }) -- -- local items = scraper.get_doc_from_page(page) -- -- log:info(inspect { items }) -local mod = "textbox" filesystem.file_writer.write( - generator.teal_type_definitions.generate_teal(mod, module_doc), - property.out_directory .. "/" .. mod .. ".d.tl" + generator.teal_type_definitions.generate_teal(module_doc), + property.out_directory .. "/textbox.d.tl" ) diff --git a/src/awesomewm.d.tl/scraper/module_doc.tl b/src/awesomewm.d.tl/scraper/module_doc.tl index 5d93513..80f74b3 100644 --- a/src/awesomewm.d.tl/scraper/module_doc.tl +++ b/src/awesomewm.d.tl/scraper/module_doc.tl @@ -90,7 +90,7 @@ end 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, { "h2.section-header", "dl.function", @@ -101,6 +101,7 @@ function module.get_doc_from_page(html: string): Module_Doc.Module_Doc end 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 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 log:warn("Not implemented: Deprecated object properties") 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 module_doc.signals = List(extract_section_signal(dl_html)) else -- 2.40.1