blob: cb493efaf9feead19d46d4d6708acbfb4ac7fb9c (
plain)
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
|
local m = {}
local function tableLenEqual(t, len)
for key, value in pairs(t) do
len = len - 1
if len < 0 then
return false
end
end
return true
end
local function isSingleNode(ast)
if type(ast) ~= 'table' then
return false
end
local len = #ast
return len == 1 and tableLenEqual(ast, len)
end
function m.expandSingle(ast)
if isSingleNode(ast) then
return ast[1]
end
return ast
end
return m
|