From 6e2ac5af5de7e363da38a789b4aa3eeed6611fb3 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Sun, 23 Oct 2022 21:07:18 +0200 Subject: [PATCH 1/5] build(types): add pl.stringx functions --- types/pl.d.tl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/pl.d.tl b/types/pl.d.tl index 171e19a..b88ecbc 100644 --- a/types/pl.d.tl +++ b/types/pl.d.tl @@ -832,6 +832,9 @@ local record pl rpartition: function(string, string): string, string, string at: function(string, number): string + indent: function(string, number, string): string + dedent: function(string): string + lines: function(string): function(): string title: function(string): string From 89f66119ee54426cd90b8813ee3fd812c23fc2a1 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Sun, 23 Oct 2022 21:07:49 +0200 Subject: [PATCH 2/5] build(types): fix scan_html indentation level --- types/web_sanitize/query/scan_html.d.tl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/types/web_sanitize/query/scan_html.d.tl b/types/web_sanitize/query/scan_html.d.tl index 05f0ae2..252bf67 100644 --- a/types/web_sanitize/query/scan_html.d.tl +++ b/types/web_sanitize/query/scan_html.d.tl @@ -1,14 +1,14 @@ local record Scanner record HTMLNode - tag: string - type: string | nil - num: number - self_closing: boolean | nil - attr: table - outer_html: function(self: HTMLNode): string - inner_html: function(self: HTMLNode): string - inner_text: function(self: HTMLNode): string - -- TODO : add replacement methods + tag: string + type: string | nil + num: number + self_closing: boolean | nil + attr: table + outer_html: function(self: HTMLNode): string + inner_html: function(self: HTMLNode): string + inner_text: function(self: HTMLNode): string + -- TODO : add replacement methods end record NodeStack From b1c3d806047cefef909bd92f103bc7d2534a9455 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Sun, 23 Oct 2022 21:09:22 +0200 Subject: [PATCH 3/5] feat(generator): improve `indent` implementation --- src/awesomewm.d.tl/generator/snippets.tl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/awesomewm.d.tl/generator/snippets.tl b/src/awesomewm.d.tl/generator/snippets.tl index ee98b22..3d848a6 100644 --- a/src/awesomewm.d.tl/generator/snippets.tl +++ b/src/awesomewm.d.tl/generator/snippets.tl @@ -1,17 +1,14 @@ local Function_Info = require "entity.Function_Info" local List = require "pl.List" -local utils = require "utils" +local stringx = require "pl.stringx" local template = require "pl.template" +local utils = require "utils" local snippets = {} function snippets.indent(str: string, level: number): string level = level or 1 - local ret = "" - for line in str:gmatch("[^\n]+") do - ret = ret .. string.rep(" ", level * 3) .. line .. "\n" - end - return ret + return stringx.rstrip(stringx.indent(str, level, string.rep(" ", 3))) end function snippets.render_typed_variable(name: string, types: List): string From 43cc531cc4171a95b92d82aaa1a8cc37a7a5df9b Mon Sep 17 00:00:00 2001 From: Aire-One Date: Sun, 23 Oct 2022 21:15:17 +0200 Subject: [PATCH 4/5] feat(scraper): scrap module Signals section --- src/awesomewm.d.tl/entity/Module_Doc.tl | 1 + src/awesomewm.d.tl/scraper/module_doc.tl | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/awesomewm.d.tl/entity/Module_Doc.tl b/src/awesomewm.d.tl/entity/Module_Doc.tl index a3efb86..67491cf 100644 --- a/src/awesomewm.d.tl/entity/Module_Doc.tl +++ b/src/awesomewm.d.tl/entity/Module_Doc.tl @@ -9,6 +9,7 @@ local record Module_Doc constructors: List methods: List static_functions: List + signals: List end local __Module_Doc: metatable = { diff --git a/src/awesomewm.d.tl/scraper/module_doc.tl b/src/awesomewm.d.tl/scraper/module_doc.tl index 8833020..495ba58 100644 --- a/src/awesomewm.d.tl/scraper/module_doc.tl +++ b/src/awesomewm.d.tl/scraper/module_doc.tl @@ -8,6 +8,10 @@ local utils = require "utils" local log = logger.log("scraper") +local function extract_node_text(node: scan.HTMLNode): string + return utils.sanitize_string(node:inner_text()) +end + local function extract_function_name(function_name_node: scan.HTMLNode): string return function_name_node and ((function_name_node.attr.name as string):gsub(".*:", "")) end @@ -20,9 +24,7 @@ local function extract_function_return_types(function_return_types_node: scan.HT local selector = "span.types .type" local html = function_return_types_node:outer_html() - return scraper_utils.scrape(html, selector, function(node: scan.HTMLNode): string - return utils.sanitize_string(node:inner_text()) - end) + return scraper_utils.scrape(html, selector, extract_node_text) end local function extract_section_functions(dl: string): { Function_Info.Function_Info } @@ -50,6 +52,12 @@ local function extract_section_functions(dl: string): { Function_Info.Function_I ) end +local function extract_section_signal(dl: string): { string } + local selector = "dt strong" + + return scraper_utils.scrape(dl, selector, extract_node_text) +end + local module = {} function module.get_doc_from_page(html: string): Module_Doc.Module_Doc @@ -80,7 +88,7 @@ function module.get_doc_from_page(html: string): Module_Doc.Module_Doc elseif section_name == "Object methods" then module_doc.methods = List(extract_section_functions(dl_html)) elseif section_name == "Signals" then - log:warn("Not implemented: Signals") + module_doc.signals = List(extract_section_signal(dl_html)) else error("Unknown section name: " .. section_name) end From 8cc37b127b8cc2134b120fb2eaed3e4940220ffd Mon Sep 17 00:00:00 2001 From: Aire-One Date: Sun, 23 Oct 2022 21:15:56 +0200 Subject: [PATCH 5/5] feat(generator): add record Signal enum --- src/awesomewm.d.tl/generator/snippets.tl | 18 ++++++++++++++++++ .../generator/teal_type_definitions.tl | 10 +++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/awesomewm.d.tl/generator/snippets.tl b/src/awesomewm.d.tl/generator/snippets.tl index 3d848a6..e3871ae 100644 --- a/src/awesomewm.d.tl/generator/snippets.tl +++ b/src/awesomewm.d.tl/generator/snippets.tl @@ -44,4 +44,22 @@ function snippets.render_record_functions(items: List): string + local tmpl = [[ +enum $(name) +$(indent(body)) +end +]] + + local tmpl_args = { + name = name, + body = values:map(function(value: string): string + return string.format('"%s"', value) + end):concat("\n"), + indent = snippets.indent, + } + + return utils.do_or_fail(template.substitute, tmpl, tmpl_args) +end + return snippets diff --git a/src/awesomewm.d.tl/generator/teal_type_definitions.tl b/src/awesomewm.d.tl/generator/teal_type_definitions.tl index 9c36f77..c9d75cd 100644 --- a/src/awesomewm.d.tl/generator/teal_type_definitions.tl +++ b/src/awesomewm.d.tl/generator/teal_type_definitions.tl @@ -8,15 +8,11 @@ local snippets = require "generator.snippets" local tmpl = [[ -- Auto generated file (Do not manually edit this file!) -# if module.signals then -local enum signals -# for _, signal in ipairs(module.signals) do - "$(signal.name)" -# end -end +local record $(mod_name) +# if #module.signals then +$(snippets.indent(snippets.render_enum("Signal", module.signals))) # end -- /signals -local record $(mod_name) # if #module.methods then -- Object methods $(snippets.indent(snippets.render_record_functions(module.methods)))