feat(Entity): implement basic type fixer
ci/woodpecker/pr/build Pipeline was successful Details
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details

This commit is contained in:
Aire-One 2022-12-14 18:41:57 +01:00
parent b423280215
commit 2f96bd0a85
3 changed files with 40 additions and 8 deletions

View File

@ -15,6 +15,8 @@ local record Module_Doc
properties: List<Variable_Info.Variable_Info>
static_functions: List<Function_Info.Function_Info>
signals: List<string>
fixup: function(Module_Doc)
end
local __Module_Doc: metatable<Module_Doc> = {
@ -25,6 +27,12 @@ local __Module_Doc: metatable<Module_Doc> = {
properties = List(),
static_functions = List(),
signals = List(),
fixup = function(self: Module_Doc)
for p in self.properties:iter() do
p:fixup()
end
end,
}
end,
}

View File

@ -1,6 +1,15 @@
local List = require "pl.List"
local Map = require "pl.Map"
local type_fix: Map<string, string> = Map({
bool = "boolean",
client = "Client",
image = "Image",
int = "integer",
screen = "Screen",
tag = "Tag",
})
local record Type_Info
metamethod __call: function(Type_Info, record_name: string): Type_Info
@ -11,19 +20,26 @@ local record Type_Info
-- Map : name -> type
-- We can't use Variable_Info here because it's a circular dependency.
record_entries: Map<string, List<Type_Info>> | nil
fixup: function(self: Type_Info)
end
local __Type_Info: metatable<Type_Info> = {
__call = function(_self: Type_Info, record_name: string): Type_Info
if record_name ~= nil then
return {
name = record_name,
record_entries = Map()
}
end
return {
name = "",
record_entries = nil,
name = record_name and record_name or "",
record_entries = record_name and Map() or nil,
fixup = function(self: Type_Info)
self.name = type_fix:get(self.name) or self.name
if self.record_entries then
for _, types in (self.record_entries as Map<string, List<Type_Info>>):iter() do
for t in types:iter() do
t:fixup()
end
end
end
end
}
end,
}

View File

@ -10,6 +10,8 @@ local record Variable_Info
types: List<Type_Info.Type_Info>
constraints: List<string>
fixup: function(self: Variable_Info)
end
local __Variable_Info: metatable<Variable_Info> = {
@ -19,6 +21,12 @@ local __Variable_Info: metatable<Variable_Info> = {
return {
name = name,
types = types,
fixup = function(self: Variable_Info)
for t in self.types:iter() do
t:fixup()
end
end,
}
end,
}