WIP: awesomerc.tl
should work #85
|
@ -1,3 +1,4 @@
|
||||||
return {
|
return {
|
||||||
source_dir = ".",
|
source_dir = ".",
|
||||||
|
global_env_def = "global_env_def",
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
local type Node = require("awesomewmdtl.types.Node")
|
local type Node = require("awesomewmdtl.types.Node")
|
||||||
|
|
||||||
local basic_nodes <total>: { Node.Token : function(name: string, ...: any): Node } = {
|
local basic_nodes <total>: { Node.Token : function(name: string, ...: any): Node } = {
|
||||||
module = function(name: string, module_path: string): Node
|
module = function(name: string, module_path: string, global: boolean): Node
|
||||||
return {
|
return {
|
||||||
token = "module",
|
token = "module",
|
||||||
|
global = global,
|
||||||
name = name,
|
name = name,
|
||||||
module_path = module_path,
|
module_path = module_path,
|
||||||
dependencies = {},
|
dependencies = {},
|
||||||
children = {},
|
children = {},
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
record = function(name: string): Node
|
record = function(name: string, global: boolean): Node
|
||||||
return {
|
return {
|
||||||
token = "record",
|
token = "record",
|
||||||
|
global = global,
|
||||||
name = name,
|
name = name,
|
||||||
children = {},
|
children = {},
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,18 @@ local function push_global_nodes(dag: Dag, nodes: { Node })
|
||||||
utils.spread(dag.global_nodes, nodes)
|
utils.spread(dag.global_nodes, nodes)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function iter_modules(dag: Dag): function(): string, Node
|
local function iter_modules(dag: Dag): (function(): string, Node)
|
||||||
return pairs(dag.modules)
|
return pairs(dag.modules)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function iter_global_nodes(dag: Dag): (function(): integer, Node)
|
||||||
|
return pairs(dag.global_nodes)
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
new = new,
|
new = new,
|
||||||
push_module = push_module,
|
push_module = push_module,
|
||||||
push_global_nodes = push_global_nodes,
|
push_global_nodes = push_global_nodes,
|
||||||
iter_modules = iter_modules,
|
iter_modules = iter_modules,
|
||||||
|
iter_global_nodes = iter_global_nodes,
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,8 +138,24 @@ for _,root in dag.iter_modules(module_dag) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Build the global module from dag.global_nodes
|
-- Build the global_env_def.d.tl module from module_dag.global_nodes
|
||||||
--- TODO : todo
|
local global_nodes_by_record_kind <const>: { string : { Node } } = {}
|
||||||
|
for _, node in dag.iter_global_nodes(module_dag) do
|
||||||
|
local record_kind = node.name:gmatch("[^%.]*")() -- get the most left part of the lua name path representation
|
||||||
|
if not global_nodes_by_record_kind[record_kind] then
|
||||||
|
global_nodes_by_record_kind[record_kind] = {}
|
||||||
|
end
|
||||||
|
table.insert(global_nodes_by_record_kind[record_kind], node)
|
||||||
|
end
|
||||||
|
local global_module_ast <const> = ast.create_node("module", "global_env_def", "global_env_def", true)
|
||||||
|
for record_kind, nodes in pairs(global_nodes_by_record_kind) do
|
||||||
|
local record_kind_node = ast.create_node("record", record_kind, true)
|
||||||
|
for _, node in ipairs(nodes) do
|
||||||
|
node.name = node.name:gsub(record_kind .. "%.", "")
|
||||||
|
table.insert(record_kind_node.children, node)
|
||||||
|
end
|
||||||
|
table.insert(global_module_ast.children, record_kind_node)
|
||||||
|
end
|
||||||
|
|
||||||
--- TODO : this is fun, but we need to do something with it
|
--- TODO : this is fun, but we need to do something with it
|
||||||
-- Write the DAG to a file
|
-- Write the DAG to a file
|
||||||
|
@ -159,5 +175,12 @@ for module_path, root in dag.iter_modules(module_dag) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Write global types definition to file
|
||||||
|
filesystem.file_writer.write(
|
||||||
|
printer.teal_type_definition.printer(global_module_ast),
|
||||||
|
property.out_directory .. "/global_env_def.d.tl"
|
||||||
|
)
|
||||||
|
|
||||||
do_module_init_definition(module_infos)
|
do_module_init_definition(module_infos)
|
||||||
log:info("Module init files generated")
|
log:info("Module init files generated")
|
||||||
|
|
|
@ -50,6 +50,11 @@ local print_children: function(node: Node): string
|
||||||
local node_printer <total>: { Node.Token : Node_Printer_Function } = {
|
local node_printer <total>: { Node.Token : Node_Printer_Function } = {
|
||||||
["module"] = {
|
["module"] = {
|
||||||
before_node = function(node: Node, indent_level: integer): string, integer
|
before_node = function(node: Node, indent_level: integer): string, integer
|
||||||
|
if node.global then
|
||||||
|
return render_code(
|
||||||
|
"-- This file was auto-generated.\n",
|
||||||
|
indent_level), indent_level
|
||||||
|
end
|
||||||
return render_code(
|
return render_code(
|
||||||
string.format(
|
string.format(
|
||||||
"-- This file was auto-generated.\n%s\nlocal record %s",
|
"-- This file was auto-generated.\n%s\nlocal record %s",
|
||||||
|
@ -61,6 +66,9 @@ local node_printer <total>: { Node.Token : Node_Printer_Function } = {
|
||||||
return render_code(print_children(node), indent_level), indent_level
|
return render_code(print_children(node), indent_level), indent_level
|
||||||
end,
|
end,
|
||||||
after_node = function(node: Node, indent_level: integer): string, integer
|
after_node = function(node: Node, indent_level: integer): string, integer
|
||||||
|
if node.global then
|
||||||
|
return "", indent_level
|
||||||
|
end
|
||||||
return render_code("end", indent_level - 1) ..
|
return render_code("end", indent_level - 1) ..
|
||||||
"\n" ..
|
"\n" ..
|
||||||
render_code(
|
render_code(
|
||||||
|
@ -73,7 +81,8 @@ local node_printer <total>: { Node.Token : Node_Printer_Function } = {
|
||||||
before_node = function(node: Node, indent_level: integer): string, integer
|
before_node = function(node: Node, indent_level: integer): string, integer
|
||||||
return render_code(
|
return render_code(
|
||||||
string.format(
|
string.format(
|
||||||
"record %s",
|
"%srecord %s",
|
||||||
|
node.global and "\nglobal " or "",
|
||||||
node.name),
|
node.name),
|
||||||
indent_level), indent_level + 1
|
indent_level), indent_level + 1
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -77,7 +77,7 @@ local function extract_function_parameters(table_html: string, function_name: st
|
||||||
"%s_%s",
|
"%s_%s",
|
||||||
utils.capitalize(function_name),
|
utils.capitalize(function_name),
|
||||||
utils.capitalize(name))
|
utils.capitalize(name))
|
||||||
table.insert(parameters_types, ast.create_node("record", record_name))
|
table.insert(parameters_types, ast.create_node("record", record_name, false))
|
||||||
is_populating_parameters_types = true
|
is_populating_parameters_types = true
|
||||||
field.types = { record_name }
|
field.types = { record_name }
|
||||||
end
|
end
|
||||||
|
@ -262,7 +262,7 @@ function module.get_doc_from_page(html: string, module_path: string): Node, { No
|
||||||
end
|
end
|
||||||
|
|
||||||
local record_name <const> = utils.capitalize((module_path:gsub(".*%.", "")))
|
local record_name <const> = utils.capitalize((module_path:gsub(".*%.", "")))
|
||||||
local module_root <const> = ast.create_node("module", record_name, module_path)
|
local module_root <const> = ast.create_node("module", record_name, module_path, false)
|
||||||
local other_nodes <const>: { Node } = {}
|
local other_nodes <const>: { Node } = {}
|
||||||
|
|
||||||
local module_signals_node <const> = ast.create_node("enum", "Signal")
|
local module_signals_node <const> = ast.create_node("enum", "Signal")
|
||||||
|
|
|
@ -24,6 +24,9 @@ local record Node
|
||||||
-- for "module"
|
-- for "module"
|
||||||
module_path: string
|
module_path: string
|
||||||
dependencies: { string : string } -- module_name -> module_path
|
dependencies: { string : string } -- module_name -> module_path
|
||||||
|
|
||||||
|
-- for "module" and "record"
|
||||||
|
global: boolean
|
||||||
end
|
end
|
||||||
|
|
||||||
return Node
|
return Node
|
||||||
|
|
Loading…
Reference in New Issue