From 2f96bd0a8567c78a0bfc00023b76fe443f0748d8 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Wed, 14 Dec 2022 18:41:57 +0100 Subject: [PATCH] feat(Entity): implement basic type fixer --- src/awesomewm.d.tl/entity/Module_Doc.tl | 8 ++++++ src/awesomewm.d.tl/entity/Type_Info.tl | 32 ++++++++++++++++------ src/awesomewm.d.tl/entity/Variable_Info.tl | 8 ++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/awesomewm.d.tl/entity/Module_Doc.tl b/src/awesomewm.d.tl/entity/Module_Doc.tl index 2d4495f..4e7a6b7 100644 --- a/src/awesomewm.d.tl/entity/Module_Doc.tl +++ b/src/awesomewm.d.tl/entity/Module_Doc.tl @@ -15,6 +15,8 @@ local record Module_Doc properties: List static_functions: List signals: List + + fixup: function(Module_Doc) end local __Module_Doc: metatable = { @@ -25,6 +27,12 @@ local __Module_Doc: metatable = { properties = List(), static_functions = List(), signals = List(), + + fixup = function(self: Module_Doc) + for p in self.properties:iter() do + p:fixup() + end + end, } end, } diff --git a/src/awesomewm.d.tl/entity/Type_Info.tl b/src/awesomewm.d.tl/entity/Type_Info.tl index 1aa2b1e..7a6ba90 100644 --- a/src/awesomewm.d.tl/entity/Type_Info.tl +++ b/src/awesomewm.d.tl/entity/Type_Info.tl @@ -1,6 +1,15 @@ local List = require "pl.List" local Map = require "pl.Map" +local type_fix: Map = 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> | nil + + fixup: function(self: Type_Info) end local __Type_Info: metatable = { __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>):iter() do + for t in types:iter() do + t:fixup() + end + end + end + end } end, } diff --git a/src/awesomewm.d.tl/entity/Variable_Info.tl b/src/awesomewm.d.tl/entity/Variable_Info.tl index 0469f2d..03f169e 100644 --- a/src/awesomewm.d.tl/entity/Variable_Info.tl +++ b/src/awesomewm.d.tl/entity/Variable_Info.tl @@ -10,6 +10,8 @@ local record Variable_Info types: List constraints: List + + fixup: function(self: Variable_Info) end local __Variable_Info: metatable = { @@ -19,6 +21,12 @@ local __Variable_Info: metatable = { return { name = name, types = types, + + fixup = function(self: Variable_Info) + for t in self.types:iter() do + t:fixup() + end + end, } end, }