feat(visitor): add `node_fixer`
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/build-and-run unknown status Details
ci/woodpecker/pr/lint unknown status Details
ci/woodpecker/pr/test unknown status Details

This commit is contained in:
Aire-One 2023-11-12 17:48:28 +01:00
parent e7b938a074
commit 59b173f774
3 changed files with 61 additions and 2 deletions

View File

@ -13,6 +13,7 @@ local Map <const> = require("pl.Map")
local Module_Info <const> = require("awesomewmdtl.entity.Module_Info")
local module_dependencies <const> = require("awesomewmdtl.visitors.module_dependencies")
local type Node = require("awesomewmdtl.types.Node")
local node_fixer <const> = require("awesomewmdtl.visitors.node_fixer")
local property <const> = require("awesomewmdtl.property")
local scraper <const> = require("awesomewmdtl.scraper")
local stringx <const> = require("pl.stringx")
@ -130,6 +131,9 @@ end
-- Run the visitors
for _,root in dag.iter_modules(module_dag) do
ast.in_order_visitor(root, function(node: Node)
node_fixer.visit(node, root)
end)
ast.in_order_visitor(root, function(node: Node)
type_mapping.visit(node)
end)

View File

@ -18,8 +18,8 @@ local record Property
end
local property: Property = {
base_url = "https://awesomewm.org/apidoc",
-- base_url = "file:///usr/share/doc/awesome/doc",
-- base_url = "https://awesomewm.org/apidoc",
base_url = "file:///usr/share/doc/awesome/doc",
index_uri = "/index.html",
out_directory = "generated",
capi_modules = {

View File

@ -0,0 +1,55 @@
local type Node = require("awesomewmdtl.types.Node")
-- Teal doesn't have a `keyof` operator yet, so we have to do this manually.
-- Some keys shouldn't be changed, so we don't include them here.
local enum Node_Key
"token"
"name"
-- "children"
"types"
"parameters"
"return_types"
-- "module_path"
-- "dependencies"
-- "global"
end
-- Teal can't define nested Map types yet, so we have to define a type for the nested map.
local type New_Node = { Node_Key : any }
local type New_Node_By_Name = { string : New_Node }
-- This is a map of module paths to a map of node names to a map of node keys to new values.
-- This is used to fix nodes where Teal doesn't have a proper way to handle them.
-- EVERYTHING IN HERE IS TEMPORARY AND SHOULD BE REMOVED WHEN TEAL SUPPORTS IT.
-- EVERYTHING IN HERE IS TEMPORARY AND SHOULD BE REMOVED WHEN TEAL SUPPORTS IT.
-- EVERYTHING IN HERE IS TEMPORARY AND SHOULD BE REMOVED WHEN TEAL SUPPORTS IT.
local node_fixer <const>: { string : New_Node_By_Name } = {
["gears.surface"] = {
["apply_shape_bounding"] = {
parameters = {
{ token = "variable", name = "draw", types = { "any" } },
{ token = "variable", name = "shape", types = { "Gears_Shape_Function" } },
{ token = "variable", name = "...", types = { "any" } },
}
}
},
}
local record Node_Fixer
visit: function(node: Node, mod: Node)
end
function Node_Fixer.visit(node: Node, mod: Node)
if not (node_fixer[mod.module_path] and node_fixer[mod.module_path][node.name]) then
return
end
for k, v in pairs(node_fixer[mod.module_path][node.name] as { string : any }) do
-- Teal can't index `node` with our k,v
local n <const> = node as { string : any }
n[k] = v
end
end
return Node_Fixer