-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast_node.lua
More file actions
56 lines (49 loc) · 964 Bytes
/
Copy pathast_node.lua
File metadata and controls
56 lines (49 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local M = {}
local node_mt = {}
node_mt.__index = node_mt
function M.new_node(s, node, ...)
return setmetatable({
line = s.line, col = s.col,
node,
...
}, node_mt)
end
function node_mt:get_location()
if self.line then
return self.line, self.col
end
return '?', '?'
end
M.node_types = {
['float'] = true,
['int'] = true,
['string'] = true,
['bool'] = true,
['nil'] = true,
['if'] = true,
['while'] = true,
['repeat'] = true,
['do'] = true,
['seq'] = true,
['comma'] = true,
['tuple'] = true,
['local'] = true,
['assign'] = true,
['binop'] = true,
['unop'] = true,
['function'] = true,
['call'] = true,
}
function M.assert_all_node_types_handled(tbl)
for k, v in pairs(M.node_types) do
if not tbls[k] then
error(('table does not handle node type `%s`'):format(k))
end
end
for k, v in pairs(tbl) do
if not M.node_types[k] then
error(('table handles non-existant node type `%s`'):format(k))
end
end
end
return M