WIP: awesomerc.tl
should work #85
|
@ -55,6 +55,14 @@ local basic_nodes <total>: { Node.Token : function(name: string, ...: any): Node
|
||||||
return_types = {},
|
return_types = {},
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
|
type = function(name: string, types: { string }, global: boolean): Node
|
||||||
|
return {
|
||||||
|
token = "type",
|
||||||
|
global = global,
|
||||||
|
name = name,
|
||||||
|
types = types,
|
||||||
|
}
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local function create_node(token: Node.Token, name: string, ...: any): Node
|
local function create_node(token: Node.Token, name: string, ...: any): Node
|
||||||
|
|
|
@ -148,6 +148,11 @@ for _, node in dag.iter_global_nodes(module_dag) do
|
||||||
table.insert(global_nodes_by_record_kind[record_kind], node)
|
table.insert(global_nodes_by_record_kind[record_kind], node)
|
||||||
end
|
end
|
||||||
local global_module_ast <const> = ast.create_node("module", "global_env_def", "global_env_def", true)
|
local global_module_ast <const> = ast.create_node("module", "global_env_def", "global_env_def", true)
|
||||||
|
-- Declare global types
|
||||||
|
table.insert(global_module_ast.children, ast.create_node("type", "Color", { "any" }, true))
|
||||||
|
table.insert(global_module_ast.children, ast.create_node("type", "Surface", { "any" }, true))
|
||||||
|
table.insert(global_module_ast.children, ast.create_node("type", "Cairo_Context", { "any" }, true))
|
||||||
|
table.insert(global_module_ast.children, ast.create_node("type", "Image", { "any" }, true))
|
||||||
for record_kind, nodes in pairs(global_nodes_by_record_kind) do
|
for record_kind, nodes in pairs(global_nodes_by_record_kind) do
|
||||||
local record_kind_node = ast.create_node("record", record_kind, true)
|
local record_kind_node = ast.create_node("record", record_kind, true)
|
||||||
for _, node in ipairs(nodes) do
|
for _, node in ipairs(nodes) do
|
||||||
|
|
|
@ -6,11 +6,14 @@ local utils = require("awesomewmdtl.utils")
|
||||||
|
|
||||||
local log = logger.log("scraper")
|
local log = logger.log("scraper")
|
||||||
|
|
||||||
local function render_types(types: { string }): string
|
local function render_types(types: { string }, no_colon: boolean): string
|
||||||
if not types or #types == 0 then
|
if not types or #types == 0 then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
return ": " .. table.concat(types, " | ")
|
return string.format(
|
||||||
|
"%s%s",
|
||||||
|
no_colon and "" or ": ",
|
||||||
|
table.concat(types, " | "))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function dedent(str: string): string
|
local function dedent(str: string): string
|
||||||
|
@ -142,7 +145,18 @@ local node_printer <total>: { Node.Token : Node_Printer_Function } = {
|
||||||
on_node = function(): string, integer
|
on_node = function(): string, integer
|
||||||
log:warn("Metamethods are not supported yet")
|
log:warn("Metamethods are not supported yet")
|
||||||
end,
|
end,
|
||||||
}
|
},
|
||||||
|
["type"] = {
|
||||||
|
on_node = function(node: Node, indent_level: integer): string, integer
|
||||||
|
return render_code(
|
||||||
|
string.format(
|
||||||
|
"%stype %s = %s",
|
||||||
|
node.global and "\nglobal " or "",
|
||||||
|
node.name,
|
||||||
|
render_types(node.types, true)),
|
||||||
|
indent_level), indent_level
|
||||||
|
end,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_teal(node: Node, indent_level: integer | nil): string
|
function print_teal(node: Node, indent_level: integer | nil): string
|
||||||
|
|
|
@ -7,6 +7,7 @@ local record Node
|
||||||
"variable"
|
"variable"
|
||||||
"function"
|
"function"
|
||||||
"metamethod"
|
"metamethod"
|
||||||
|
"type"
|
||||||
end
|
end
|
||||||
token: Token
|
token: Token
|
||||||
name: string
|
name: string
|
||||||
|
@ -14,7 +15,7 @@ local record Node
|
||||||
-- for "module", "record", "enum"
|
-- for "module", "record", "enum"
|
||||||
children: { Node }
|
children: { Node }
|
||||||
|
|
||||||
-- for "variable"
|
-- for "variable" and "type"
|
||||||
types: { string }
|
types: { string }
|
||||||
|
|
||||||
-- for "function" and "metamethod"
|
-- for "function" and "metamethod"
|
||||||
|
@ -25,7 +26,7 @@ local record Node
|
||||||
module_path: string
|
module_path: string
|
||||||
dependencies: { string : string } -- module_name -> module_path
|
dependencies: { string : string } -- module_name -> module_path
|
||||||
|
|
||||||
-- for "module" and "record"
|
-- for "module", "record", "type"
|
||||||
global: boolean
|
global: boolean
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue