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

View File

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

View File

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

View File

@ -11,6 +11,7 @@ local List <const> = require("pl.List")
local logger <const> = require("awesomewmdtl.logger")
local Module_Info <const> = require("awesomewmdtl.entity.Module_Info")
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 node_fixer <const> = require("awesomewmdtl.visitors.node_fixer")
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)
module_dependencies.visit(node, root, module_dag)
end)
ast.in_order_visitor(root, function(node: Node)
module_descendants.visit(node)
end)
end
-- 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 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
if not types or #types == 0 then
return ""
@ -113,10 +96,7 @@ local node_printer <total>: { Node.Token : Node_Printer_Function } = {
render_require(
utils.merge_map(
node.dependencies,
utils.pipe(
get_package_descendants,
nodes_to_string_map)(node) as { string : string } -- pipe needs to be promoted
)), -- last require statement will have a newline
node.descendants)), -- last require statement will have a newline
node.name),
indent_level), indent_level + 1
end,

View File

@ -31,6 +31,7 @@ local record Node
-- for "module"
module_path: string
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"
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