feat(types): introduce new data structures
ci/woodpecker/pr/build Pipeline failed Details
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline failed Details

This commit is contained in:
Aire-One 2023-01-29 19:19:20 +01:00
parent e6cd4712fa
commit ee7f986465
4 changed files with 123 additions and 0 deletions

63
src/awesomewm.d.tl/ast.tl Normal file
View File

@ -0,0 +1,63 @@
local type Node = require("types.Node")
local basic_nodes <total>: { Node.Token : function(name: string): Node } = {
module = function(name: string): Node
return {
token = "module",
name = name,
children = {},
}
end,
record = function(name: string): Node
return {
token = "record",
name = name,
children = {},
}
end,
enum = function(name: string): Node
return {
token = "enum",
name = name,
children = {},
}
end,
identifier = function(name: string): Node
return {
token = "identifier",
name = name,
}
end,
variable = function(name: string): Node
return {
token = "variable",
name = name,
types = {},
}
end,
["function"] = function(name: string): Node
return {
token = "function",
name = name,
parameters = {},
return_types = {},
}
end,
metamethod = function(name: string): Node
return {
token = "metamethod",
name = name,
parameters = {},
return_types = {},
}
end,
}
local function create_node(token: Node.Token, name: string): Node
local node = basic_nodes[token](name)
return node
end
return {
create_node = create_node,
}

27
src/awesomewm.d.tl/dag.tl Normal file
View File

@ -0,0 +1,27 @@
local type Dag = require("types.Dag")
local type Node = require("types.Node")
local function init(): Dag
local dag <total>: Dag = {
nodes_by_module_name = {},
global_nodes = {},
}
return dag
end
local function insert(dag: Dag, module_name: string, node: Node)
if not dag.nodes_by_module_name[module_name] then
dag.nodes_by_module_name[module_name] = {}
end
table.insert(dag.nodes_by_module_name[module_name], node)
end
local function insert_global(dag: Dag, node: Node)
table.insert(dag.global_nodes, node)
end
return {
init = init,
insert = insert,
insert_global = insert_global,
}

View File

@ -0,0 +1,8 @@
local type Node = require("redo.ast.Node")
local record Dag
nodes_by_module_name: { string : { Node } }
global_nodes: { Node }
end
return Dag

View File

@ -0,0 +1,25 @@
local record Node
enum Token
"module" -- file root node, it is always a record and the generated .d.tl file returns it
"record"
"enum"
"identifier" -- blank token with only a name (used for enum values)
"variable"
"function"
"metamethod"
end
token: Token
name: string
-- for "module", "record", "enum"
children: { Node }
-- for "variable"
types: { string }
-- for "function" and "metamethod"
parameters: { Node }
return_types: { string }
end
return Node