diff --git a/src/awesomewm.d.tl/generator/init.tl b/src/awesomewm.d.tl/generator/init.tl deleted file mode 100644 index 586a64b..0000000 --- a/src/awesomewm.d.tl/generator/init.tl +++ /dev/null @@ -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", -} diff --git a/src/awesomewm.d.tl/init.tl b/src/awesomewm.d.tl/init.tl index 3fcea57..5fa2966 100644 --- a/src/awesomewm.d.tl/init.tl +++ b/src/awesomewm.d.tl/init.tl @@ -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): Map> local tree: Map> = 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" ) diff --git a/src/awesomewm.d.tl/generator/global_env_def.tl b/src/awesomewm.d.tl/printer/global_env_def.tl similarity index 96% rename from src/awesomewm.d.tl/generator/global_env_def.tl rename to src/awesomewm.d.tl/printer/global_env_def.tl index 47387d6..79b9250 100644 --- a/src/awesomewm.d.tl/generator/global_env_def.tl +++ b/src/awesomewm.d.tl/printer/global_env_def.tl @@ -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. diff --git a/src/awesomewm.d.tl/printer/init.tl b/src/awesomewm.d.tl/printer/init.tl new file mode 100644 index 0000000..1787676 --- /dev/null +++ b/src/awesomewm.d.tl/printer/init.tl @@ -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"), +} diff --git a/src/awesomewm.d.tl/generator/module_init_definition.tl b/src/awesomewm.d.tl/printer/module_init_definition.tl similarity index 93% rename from src/awesomewm.d.tl/generator/module_init_definition.tl rename to src/awesomewm.d.tl/printer/module_init_definition.tl index 20d8ed4..dca48f5 100644 --- a/src/awesomewm.d.tl/generator/module_init_definition.tl +++ b/src/awesomewm.d.tl/printer/module_init_definition.tl @@ -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. diff --git a/src/awesomewm.d.tl/generator/snippets.tl b/src/awesomewm.d.tl/printer/snippets.tl similarity index 100% rename from src/awesomewm.d.tl/generator/snippets.tl rename to src/awesomewm.d.tl/printer/snippets.tl diff --git a/src/awesomewm.d.tl/generator/teal_type_definitions.tl b/src/awesomewm.d.tl/printer/teal_type_definition.tl similarity index 72% rename from src/awesomewm.d.tl/generator/teal_type_definitions.tl rename to src/awesomewm.d.tl/printer/teal_type_definition.tl index 39393d1..82c7fd7 100644 --- a/src/awesomewm.d.tl/generator/teal_type_definitions.tl +++ b/src/awesomewm.d.tl/printer/teal_type_definition.tl @@ -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 : { Node.Token : Node_Generator_Function } = { +local node_printer : { 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 : { 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 : { 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 : { 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 : { 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, }