chore: rename Generator -> Printer

This commit is contained in:
Aire-One 2023-05-08 23:24:59 +02:00
parent 3bf9ac4ebd
commit ba51f09e47
7 changed files with 32 additions and 32 deletions

View File

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

View File

@ -4,7 +4,7 @@ end
local crawler = require "crawler"
local filesystem = require "filesystem"
local generator = require "generator"
local printer = require "printer"
local List = require "pl.List"
local logger = require "logger"
local Map = require "pl.Map"
@ -42,7 +42,7 @@ local function module_lists(
end
-- The module's children list produced can contain duplicates.
-- We ignore them for now because they are dismissed when building a Map for the generator.
-- We ignore them for now because they are dismissed when building a Map for the printer.
local function modules_tree(modules: List<Module_Info.Module_Info>): Map<string, List<string>>
local tree: Map<string, List<string>> = Map()
for module in modules:iter() do
@ -79,7 +79,7 @@ end
-- module_doc:fixup()
-- module_doc:populate_requires()
-- filesystem.file_writer.write(
-- generator.teal_type_definitions.generate_teal(module_doc),
-- printer.teal_type_definitions.generate_teal(module_doc),
-- output_path
-- )
-- end
@ -128,7 +128,7 @@ end
-- global_env_def:append(module_doc)
-- end
-- filesystem.file_writer.write(
-- generator.global_env_def.generate_teal(global_env_def),
-- printer.global_env_def.generate_teal(global_env_def),
-- property.out_directory .. "/global_env.d.tl"
-- )
@ -140,7 +140,7 @@ end
-- requires:set(name, child)
-- end
-- filesystem.file_writer.write(
-- generator.module_init_definition.generate_teal(requires),
-- printer.module_init_definition.generate_teal(requires),
-- property.out_directory .. "/" .. stringx.split(module, "."):slice(1, -1):join("/") .. "/init.d.tl"
-- )
-- end
@ -156,6 +156,6 @@ log:info(logger.message_with_metadata("Finished", {
}))
filesystem.file_writer.write(
generator.teal_type_definitions.generate_teal(module_ast),
printer.teal_type_definition.printer(module_ast),
property.out_directory .. "/" .. "generated_from_ast" .. ".d.tl"
)

View File

@ -2,7 +2,7 @@ local List = require "pl.List"
local Module_Doc = require "entity.Module_Doc"
local template = require "pl.template"
local utils = require "utils"
local snippets = require "generator.snippets"
local snippets = require "printer.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.

View File

@ -0,0 +1,6 @@
return {
global_env_def = require("printer.global_env_def"),
module_init_definition = require("printer.module_init_definition"),
snippets = require("printer.snippets"),
teal_type_definition = require("printer.teal_type_definition"),
}

View File

@ -1,7 +1,7 @@
local Map = require "pl.Map"
local template = require "pl.template"
local utils = require "utils"
local snippets = require "generator.snippets"
local snippets = require "printer.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.

View File

@ -20,23 +20,23 @@ local function render_types(types: { string }): string
return ": " .. concatenate_strings(types)
end
local record Node_Generator_Function
local record Node_Printer_Function
on_node: function(node: Node): string
before_node: nil | function(node: Node): string
after_node: nil | function(node: Node): string
end
-- pre-declare functions to prevent forward reference errors
local generate_teal: function(node: Node): string
local generate_children: function(node: Node): string
local print_teal: function(node: Node): string
local print_children: function(node: Node): string
local node_generator <total>: { Node.Token : Node_Generator_Function } = {
local node_printer <total>: { Node.Token : Node_Printer_Function } = {
["module"] = {
before_node = function(node: Node): string
return "-- This file was auto-generated.\n\nlocal record " .. node.name .. "\n"
end,
on_node = function(node: Node): string
return generate_children(node)
return print_children(node)
end,
after_node = function(node: Node): string
return "end\n\nreturn " .. node.name
@ -47,7 +47,7 @@ local node_generator <total>: { Node.Token : Node_Generator_Function } = {
return "local record " .. node.name
end,
on_node = function(node: Node): string
return generate_children(node)
return print_children(node)
end,
after_node = function(): string
return "end"
@ -58,7 +58,7 @@ local node_generator <total>: { Node.Token : Node_Generator_Function } = {
return "enum " .. node.name .. "\n"
end,
on_node = function(node: Node): string
return generate_children(node)
return print_children(node)
end,
after_node = function(): string
return "end"
@ -78,7 +78,7 @@ local node_generator <total>: { Node.Token : Node_Generator_Function } = {
on_node = function(node: Node): string
local args = {}
for _, parameter in ipairs(node.parameters) do
table.insert(args, generate_teal(parameter))
table.insert(args, print_teal(parameter))
end
return node.name .. ": function(" .. table.concat(args, ", ") .. ")" .. render_types(node.return_types)
end,
@ -90,27 +90,27 @@ local node_generator <total>: { Node.Token : Node_Generator_Function } = {
}
}
function generate_teal(node: Node): string
local generator = node_generator[node.token]
function print_teal(node: Node): string
local printer = node_printer[node.token]
local generated = ""
if generator.before_node then
generated = (generator.before_node as function(node: Node): string)(node)
if printer.before_node then
generated = (printer.before_node as function(node: Node): string)(node)
end
generated = generated .. generator.on_node(node)
if generator.after_node then
generated = generated .. (generator.after_node as function(node: Node): string)(node)
generated = generated .. printer.on_node(node)
if printer.after_node then
generated = generated .. (printer.after_node as function(node: Node): string)(node)
end
return generated
end
function generate_children(node: Node): string
function print_children(node: Node): string
local generated = ""
for _, child in ast.iter_children(node) do
generated = generated .. generate_teal(child) .. "\n"
generated = generated .. print_teal(child) .. "\n"
end
return generated
end
return {
generate_teal = generate_teal,
printer = print_teal,
}