From f277ac1338532097d4a59f861e7bb92cebd1b836 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Sun, 7 Jan 2018 22:41:59 +0100 Subject: data/pandoc.lua: make Attr an AstElement Attr is an AST element, which is now reflected in the type hierarchy. --- data/pandoc.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'data') 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' -- cgit v1.2.3