feat(generator): implement module_init_definition
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-30 20:05:01 +01:00
parent a2a11a1379
commit 774be91098
3 changed files with 45 additions and 1 deletions

View File

@ -1,5 +1,6 @@
return {
global_env_def = require "generator.global_env_def",
teal_type_definitions = require "generator.teal_type_definitions",
module_init_definition = require "generator.module_init_definition",
snippets = require "generator.snippets",
teal_type_definitions = require "generator.teal_type_definitions",
}

View File

@ -0,0 +1,31 @@
local Map = require "pl.Map"
local template = require "pl.template"
local utils = require "utils"
local snippets = require "generator.snippets"
-- The long therm goal is to have so many `snippets.render_*` functions that
-- we can render the whole file with the smallest template possible.
local tmpl = [[
-- Auto generated file (Do not manually edit this file!)
return {
# for name, path in requires:iter() do
$(name) = require "$(path)",
# end -- /for
}
]]
local module = {}
function module.generate_teal(requires: Map<string, string>): string
local tmpl_args = {
ipairs = ipairs,
requires = requires,
snippets = snippets,
}
return utils.do_or_fail(template.substitute, tmpl, tmpl_args)
end
return module

View File

@ -125,3 +125,15 @@ filesystem.file_writer.write(
generator.global_env_def.generate_teal(global_env_def),
property.out_directory .. "/global_env.d.tl"
)
for module, children in tree:iter() do
local requires: Map<string, string> = Map()
for child in children:iter() do
local name = child:gmatch(".*%.(.*)$")()
requires:set(name, child)
end
filesystem.file_writer.write(
generator.module_init_definition.generate_teal(requires),
property.out_directory .. "/" .. module:gsub("%.", "/") .. ".d.tl"
)
end