From bebe4a6901efccd295b1679162a9419a52da1fe8 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Tue, 4 Oct 2022 20:47:46 +0200 Subject: [PATCH] fix(entities): implement entities --- src/awesomewm.d.tl/entities/Function_Info.tl | 12 ++++++++++-- src/awesomewm.d.tl/entities/Module_Doc.tl | 17 +++++++++++++---- src/awesomewm.d.tl/entities/Module_Info.tl | 14 ++++++++++++-- src/awesomewm.d.tl/scraper/module_doc.tl | 6 +++--- src/awesomewm.d.tl/scraper/module_info_list.tl | 4 ++-- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/awesomewm.d.tl/entities/Function_Info.tl b/src/awesomewm.d.tl/entities/Function_Info.tl index 4e20839..5106411 100644 --- a/src/awesomewm.d.tl/entities/Function_Info.tl +++ b/src/awesomewm.d.tl/entities/Function_Info.tl @@ -8,14 +8,22 @@ end local record Function_Info metamethod __call: function(Function_Info): Function_Info + Function_Info: Function_Info + name: string parameters: List return_types: List - append_parameter: function(self: Function_Info, parameter: string) + append_parameter: function(self: Function_Info, name: string, type: string) append_return_type: function(self: Function_Info, return_type: string) end +local __Function_Info: metatable = { + __call = function(self: Function_Info): Function_Info + return self + end, +} + function Function_Info:append_parameter(name: string, type: string) self.parameters:append { name = name, @@ -27,4 +35,4 @@ function Function_Info:append_return_type(return_type: string) self.return_types:append(return_type) end -return Function_Info +return setmetatable({} as Function_Info, __Function_Info) diff --git a/src/awesomewm.d.tl/entities/Module_Doc.tl b/src/awesomewm.d.tl/entities/Module_Doc.tl index 165b31f..004fd9e 100644 --- a/src/awesomewm.d.tl/entities/Module_Doc.tl +++ b/src/awesomewm.d.tl/entities/Module_Doc.tl @@ -4,9 +4,18 @@ local List = require "pl.List" local record Module_Doc metamethod __call: function(Module_Doc): Module_Doc - constructors: List - methods: List - static_functions: List + Module_Doc: Module_Doc + + constructors: List + methods: List + static_functions: List end -return Module_Doc +local __Module_Doc: metatable = { + __call = function(self: Module_Doc): Module_Doc + return self + end, +} + +return setmetatable({} as Module_Doc, __Module_Doc) + diff --git a/src/awesomewm.d.tl/entities/Module_Info.tl b/src/awesomewm.d.tl/entities/Module_Info.tl index 9c2380d..aa38ca3 100644 --- a/src/awesomewm.d.tl/entities/Module_Info.tl +++ b/src/awesomewm.d.tl/entities/Module_Info.tl @@ -1,8 +1,18 @@ local record Module_Info - metamethod __call: function(Module_Info, name: string, uri: string): Module_Info + metamethod __call: function(self: Module_Info, name: string, uri: string): Module_Info + + Module_Info: Module_Info name: string uri: string end -return Module_Info +local __Module_Info: metatable = { + __call = function(self: Module_Info, name: string, uri: string): Module_Info + self.name = name + self.uri = uri + return self + end, +} + +return setmetatable({} as Module_Info, __Module_Info) diff --git a/src/awesomewm.d.tl/scraper/module_doc.tl b/src/awesomewm.d.tl/scraper/module_doc.tl index 12a272d..528f737 100644 --- a/src/awesomewm.d.tl/scraper/module_doc.tl +++ b/src/awesomewm.d.tl/scraper/module_doc.tl @@ -22,7 +22,7 @@ local function extract_function_return_types(function_return_types_node: scan.HT end) end -local function extract_section_functions(dl: string): { Function_Info } +local function extract_section_functions(dl: string): { Function_Info.Function_Info } local query_selectors = { function_name = "dt a", function_return_type = "dd ol", @@ -31,7 +31,7 @@ local function extract_section_functions(dl: string): { Function_Info } return scraper_utils.scrape_tuples( dl, { query_selectors.function_name, query_selectors.function_return_type }, - function(nodes: { string : scan.HTMLNode | nil }): Function_Info + function(nodes: { string : scan.HTMLNode | nil }): Function_Info.Function_Info local function_info = Function_Info() function_info.name = @@ -49,7 +49,7 @@ end local module = {} -function module.get_doc_from_page(html: string): Module_Doc +function module.get_doc_from_page(html: string): Module_Doc.Module_Doc local nodes = scraper_utils.extract_nodes(html, { "h2.section-header", "dl.function", diff --git a/src/awesomewm.d.tl/scraper/module_info_list.tl b/src/awesomewm.d.tl/scraper/module_info_list.tl index 8efbb09..21ecda9 100644 --- a/src/awesomewm.d.tl/scraper/module_info_list.tl +++ b/src/awesomewm.d.tl/scraper/module_info_list.tl @@ -7,7 +7,7 @@ local module = {} local MODULE_A_TAG_QUERY_SELECTOR = "div#navigation ul li a" -local function extract_module_info(node: scan.HTMLNode): Module_Info +local function extract_module_info(node: scan.HTMLNode): Module_Info.Module_Info local name = utils.sanitize_string(node:inner_text()) local uri = node.attr.href as string @@ -18,7 +18,7 @@ local function extract_module_info(node: scan.HTMLNode): Module_Info return Module_Info(name, uri) end -function module.get_modules_from_index(html: string): { Module_Info } +function module.get_modules_from_index(html: string): { Module_Info.Module_Info } return scraper_utils.scrape( html, MODULE_A_TAG_QUERY_SELECTOR,