data/pandoc.lua: make Attr an AstElement
Attr is an AST element, which is now reflected in the type hierarchy.
This commit is contained in:
parent
967a54dea3
commit
f277ac1338
1 changed files with 7 additions and 9 deletions
|
@ -768,35 +768,33 @@ local to_alist = function (tbl)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Attr
|
-- Attr
|
||||||
M.Attr = {}
|
|
||||||
M.Attr._field_names = {identifier = 1, classes = 2, attributes = 3}
|
|
||||||
--- Create a new set of attributes (Attr).
|
--- Create a new set of attributes (Attr).
|
||||||
-- @function Attr
|
-- @function Attr
|
||||||
-- @tparam[opt] string identifier element identifier
|
-- @tparam[opt] string identifier element identifier
|
||||||
-- @tparam[opt] {string,...} classes element classes
|
-- @tparam[opt] {string,...} classes element classes
|
||||||
-- @tparam[opt] table attributes table containing string keys and values
|
-- @tparam[opt] table attributes table containing string keys and values
|
||||||
-- @return element attributes
|
-- @return element attributes
|
||||||
M.Attr.__call = function(t, identifier, classes, attributes)
|
M.Attr = AstElement:make_subtype'Attr'
|
||||||
|
M.Attr.constructor = function(identifier, classes, attributes)
|
||||||
identifier = identifier or ''
|
identifier = identifier or ''
|
||||||
classes = List:new(classes or {})
|
classes = List:new(classes or {})
|
||||||
attributes = setmetatable(to_alist(attributes or {}), AttributeList)
|
attributes = setmetatable(to_alist(attributes or {}), AttributeList)
|
||||||
local attr = {identifier, classes, attributes}
|
return {identifier, classes, attributes}
|
||||||
setmetatable(attr, t)
|
|
||||||
return attr
|
|
||||||
end
|
end
|
||||||
M.Attr.__index = function(t, k)
|
M.Attr.behavior._field_names = {identifier = 1, classes = 2, attributes = 3}
|
||||||
|
M.Attr.behavior.__index = function(t, k)
|
||||||
return rawget(t, k) or
|
return rawget(t, k) or
|
||||||
rawget(t, M.Attr._field_names[k]) or
|
rawget(t, M.Attr._field_names[k]) or
|
||||||
rawget(getmetatable(t), k)
|
rawget(getmetatable(t), k)
|
||||||
end
|
end
|
||||||
M.Attr.__newindex = function(t, k, v)
|
M.Attr.behavior.__newindex = function(t, k, v)
|
||||||
if M.Attr._field_names[k] then
|
if M.Attr._field_names[k] then
|
||||||
rawset(t, M.Attr._field_names[k], v)
|
rawset(t, M.Attr._field_names[k], v)
|
||||||
else
|
else
|
||||||
rawset(t, k, v)
|
rawset(t, k, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
setmetatable(M.Attr, M.Attr)
|
|
||||||
|
|
||||||
-- Citation
|
-- Citation
|
||||||
M.Citation = AstElement:make_subtype'Citation'
|
M.Citation = AstElement:make_subtype'Citation'
|
||||||
|
|
Loading…
Reference in a new issue