feat(visitor): implement module_descendants
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/build-and-run Pipeline failed Details
ci/woodpecker/pr/test Pipeline was successful Details

This commit is contained in:
Aire-One 2024-01-02 18:25:05 +01:00
parent 879abd00a6
commit 577bb6373d
7 changed files with 65 additions and 21 deletions

View File

@ -22,6 +22,7 @@ describe("Teal type definition Printer", function()
{ {
children = {}, children = {},
dependencies = {}, dependencies = {},
descendants = {},
name = "Empty", name = "Empty",
token = "module", token = "module",
}, },
@ -53,6 +54,7 @@ describe("Teal type definition Printer", function()
}, },
}, },
dependencies = {}, dependencies = {},
descendants = {},
name = "Signal_Module", name = "Signal_Module",
token = "module", token = "module",
}, },
@ -79,6 +81,7 @@ describe("Teal type definition Printer", function()
} }
}, },
dependencies = {}, dependencies = {},
descendants = {},
name = "Property_Module", name = "Property_Module",
token = "module", token = "module",
}, },
@ -114,6 +117,7 @@ describe("Teal type definition Printer", function()
}, },
}, },
dependencies = {}, dependencies = {},
descendants = {},
name = "Function_Module", name = "Function_Module",
token = "module", token = "module",
}, },
@ -137,6 +141,7 @@ describe("Teal type definition Printer", function()
} }
}, },
dependencies = {}, dependencies = {},
descendants = {},
name = "Nested_Module", name = "Nested_Module",
token = "module", token = "module",
}, },
@ -158,6 +163,7 @@ describe("Teal type definition Printer", function()
dep = "dep", dep = "dep",
deeper = "path.dep.deeper", deeper = "path.dep.deeper",
}, },
descendants = {},
name = "Module", name = "Module",
token = "module", token = "module",
}, },
@ -197,6 +203,7 @@ describe("Teal type definition Printer", function()
name = "Timer", name = "Timer",
module_path = "gears.timer", module_path = "gears.timer",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
}, },
@ -251,6 +258,9 @@ describe("Teal type definition Printer", function()
name = "Widget", name = "Widget",
module_path = "wibox.widget", module_path = "wibox.widget",
dependencies = {}, dependencies = {},
descendants = {
Imagebox = "wibox.widget.imagebox",
},
global = false, global = false,
token = "module", token = "module",
}, },

View File

@ -27,6 +27,7 @@ describe("Scrap documentation", function()
name = "Empty", name = "Empty",
module_path = "empty", module_path = "empty",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -90,6 +91,7 @@ describe("Scrap documentation", function()
name = "Property_signal", name = "Property_signal",
module_path = "property_signal", module_path = "property_signal",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -204,6 +206,7 @@ describe("Scrap documentation", function()
name = "Property_enum", name = "Property_enum",
module_path = "property_enum", module_path = "property_enum",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -247,6 +250,7 @@ describe("Scrap documentation", function()
name = "Property_string", name = "Property_string",
module_path = "property_string", module_path = "property_string",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -315,6 +319,7 @@ describe("Scrap documentation", function()
name = "Tag", name = "Tag",
module_path = "awful.tag", module_path = "awful.tag",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -368,6 +373,7 @@ describe("Scrap documentation", function()
name = "Signal", name = "Signal",
module_path = "signal", module_path = "signal",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -464,6 +470,7 @@ describe("Scrap documentation", function()
name = "Awesome", name = "Awesome",
module_path = "awesome", module_path = "awesome",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -592,6 +599,7 @@ describe("Scrap documentation", function()
name = "Screen", name = "Screen",
module_path = "awful.screen", module_path = "awful.screen",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -684,6 +692,7 @@ describe("Scrap documentation", function()
name = "Table", name = "Table",
module_path = "gears.table", module_path = "gears.table",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -777,6 +786,7 @@ describe("Scrap documentation", function()
name = "Client", name = "Client",
module_path = "awful.client", module_path = "awful.client",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -821,6 +831,7 @@ describe("Scrap documentation", function()
name = "Client", name = "Client",
module_path = "awful.client", module_path = "awful.client",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
}, },
@ -879,6 +890,7 @@ describe("Scrap documentation", function()
name = "Awesome", name = "Awesome",
module_path = "awesome", module_path = "awesome",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))
@ -921,6 +933,7 @@ describe("Scrap documentation", function()
name = "Timer", name = "Timer",
module_path = "gears.timer", module_path = "gears.timer",
dependencies = {}, dependencies = {},
descendants = {},
global = false, global = false,
token = "module", token = "module",
})) }))

View File

@ -8,6 +8,7 @@ local basic_nodes <total>: { Node.Token : function(name: string, ...: any): Node
name = name, name = name,
module_path = module_path, module_path = module_path,
dependencies = {}, dependencies = {},
descendants = {},
children = {}, children = {},
} }
end, end,

View File

@ -11,6 +11,7 @@ local List <const> = require("pl.List")
local logger <const> = require("awesomewmdtl.logger") local logger <const> = require("awesomewmdtl.logger")
local Module_Info <const> = require("awesomewmdtl.entity.Module_Info") local Module_Info <const> = require("awesomewmdtl.entity.Module_Info")
local module_dependencies <const> = require("awesomewmdtl.visitors.module_dependencies") local module_dependencies <const> = require("awesomewmdtl.visitors.module_dependencies")
local module_descendants <const> = require("awesomewmdtl.visitors.module_descendants")
local type Node = require("awesomewmdtl.types.Node") local type Node = require("awesomewmdtl.types.Node")
local node_fixer <const> = require("awesomewmdtl.visitors.node_fixer") local node_fixer <const> = require("awesomewmdtl.visitors.node_fixer")
local property <const> = require("awesomewmdtl.property") local property <const> = require("awesomewmdtl.property")
@ -91,6 +92,9 @@ for root in dag.iter_modules(module_dag) do
ast.in_order_visitor(root, function(node: Node) ast.in_order_visitor(root, function(node: Node)
module_dependencies.visit(node, root, module_dag) module_dependencies.visit(node, root, module_dag)
end) end)
ast.in_order_visitor(root, function(node: Node)
module_descendants.visit(node)
end)
end end
-- Build the global_env_def.d.tl module from module_dag.global_nodes -- Build the global_env_def.d.tl module from module_dag.global_nodes

View File

@ -8,23 +8,6 @@ local log = logger.log("scraper")
local GEN_TEXT <const> = "-- This file was auto-generated.\n" local GEN_TEXT <const> = "-- This file was auto-generated.\n"
local function get_package_descendants(node: Node): { Node }
return utils.filter(
node.children,
function(child: Node): boolean
return child.token == "module"
end
)
end
local function nodes_to_string_map(nodes: { Node }): { string : string }
local map <const>: { string : string } = {}
for _, node in ipairs(nodes) do
map[node.name] = node.module_path
end
return map
end
local function render_types(types: { string }, separator: string, with_colon_prefix: boolean): string local function render_types(types: { string }, separator: string, with_colon_prefix: boolean): string
if not types or #types == 0 then if not types or #types == 0 then
return "" return ""
@ -113,10 +96,7 @@ local node_printer <total>: { Node.Token : Node_Printer_Function } = {
render_require( render_require(
utils.merge_map( utils.merge_map(
node.dependencies, node.dependencies,
utils.pipe( node.descendants)), -- last require statement will have a newline
get_package_descendants,
nodes_to_string_map)(node) as { string : string } -- pipe needs to be promoted
)), -- last require statement will have a newline
node.name), node.name),
indent_level), indent_level + 1 indent_level), indent_level + 1
end, end,

View File

@ -31,6 +31,7 @@ local record Node
-- for "module" -- for "module"
module_path: string module_path: string
dependencies: { string : string } -- module_name -> module_path dependencies: { string : string } -- module_name -> module_path
descendants: { string : string } -- modules in children that should be written in the final type definition. module_name -> module_path
-- for "module", "record", "type" -- for "module", "record", "type"
global: boolean global: boolean

View File

@ -0,0 +1,35 @@
local type Node = require("awesomewmdtl.types.Node")
local function get_descendants_module(node: Node): { string : string }
local descendants_by_name: { string : string } = {}
for _, descendant in ipairs(node.children) do
if descendant.token == "module" then
descendants_by_name[descendant.name] = descendant.module_path
end
end
return descendants_by_name
end
local record Module_Descendants
visit: function(node: Node)
end
function Module_Descendants.visit(node: Node)
if node.token ~= "module" then
return
end
local descendants_by_name = get_descendants_module(node)
for _, descendant in ipairs(node.children) do
if descendant.token ~= "module" and descendants_by_name[descendant.name] then
descendants_by_name[descendant.name] = nil
end
end
node.descendants = descendants_by_name
end
return Module_Descendants