summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2018-01-07 22:41:59 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2018-01-07 22:41:59 +0100
commitf277ac1338532097d4a59f861e7bb92cebd1b836 (patch)
tree2c8446ba3368daaa9a8a0e79fbc1f507694476d9
parent967a54dea30c6e7ff0ea8eb9f4ee41a12167b475 (diff)
data/pandoc.lua: make Attr an AstElement
Attr is an AST element, which is now reflected in the type hierarchy.
-rw-r--r--data/pandoc.lua16
1 files changed, 7 insertions, 9 deletions
diff --git a/data/pandoc.lua b/data/pandoc.lua
index a069dcb50..d487ac7c9 100644
--- a/data/pandoc.lua
+++ b/data/pandoc.lua
@@ -768,35 +768,33 @@ local to_alist = function (tbl)
end
-- Attr
-M.Attr = {}
-M.Attr._field_names = {identifier = 1, classes = 2, attributes = 3}
+
--- Create a new set of attributes (Attr).
-- @function Attr
-- @tparam[opt] string identifier element identifier
-- @tparam[opt] {string,...} classes element classes
-- @tparam[opt] table attributes table containing string keys and values
-- @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 ''
classes = List:new(classes or {})
attributes = setmetatable(to_alist(attributes or {}), AttributeList)
- local attr = {identifier, classes, attributes}
- setmetatable(attr, t)
- return attr
+ return {identifier, classes, attributes}
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
rawget(t, M.Attr._field_names[k]) or
rawget(getmetatable(t), k)
end
-M.Attr.__newindex = function(t, k, v)
+M.Attr.behavior.__newindex = function(t, k, v)
if M.Attr._field_names[k] then
rawset(t, M.Attr._field_names[k], v)
else
rawset(t, k, v)
end
end
-setmetatable(M.Attr, M.Attr)
-- Citation
M.Citation = AstElement:make_subtype'Citation'