git.iko.soy/typeable/pandoc
on master help sign in
data/pandoc.lua: make Attr an AstElement

Attr is an AST element, which is now reflected in the type hierarchy.

commitf277ac1338532097d4a59f861e7bb92cebd1b836 authorAlbert Krewinkel <albert@zeitkraut.de> dateSun 7 Jan 2018, 22:41 (9 years ago) parent967a54d
1 file changed+7−9
data/pandoc.lua+7−9
data/pandoc.lua+7−9
@@ -768,35 +768,33 @@ local to_alist = function (tbl)
768768end
769769
770770-- Attr
771−M.Attr = {}
772−M.Attr._field_names = {identifier = 1, classes = 2, attributes = 3}
771+
773772--- Create a new set of attributes (Attr).
774773-- @function Attr
775774-- @tparam[opt] string identifier element identifier
776775-- @tparam[opt] {string,...} classes element classes
777776-- @tparam[opt] table attributes table containing string keys and values
778777-- @return element attributes
779−M.Attr.__call = function(t, identifier, classes, attributes)
778+M.Attr = AstElement:make_subtype'Attr'
779+M.Attr.constructor = function(identifier, classes, attributes)
780780 identifier = identifier or ''
781781 classes = List:new(classes or {})
782782 attributes = setmetatable(to_alist(attributes or {}), AttributeList)
783− local attr = {identifier, classes, attributes}
784− setmetatable(attr, t)
785− return attr
783+ return {identifier, classes, attributes}
786784end
787−M.Attr.__index = function(t, k)
785+M.Attr.behavior._field_names = {identifier = 1, classes = 2, attributes = 3}
786+M.Attr.behavior.__index = function(t, k)
788787 return rawget(t, k) or
789788 rawget(t, M.Attr._field_names[k]) or
790789 rawget(getmetatable(t), k)
791790end
792−M.Attr.__newindex = function(t, k, v)
791+M.Attr.behavior.__newindex = function(t, k, v)
793792 if M.Attr._field_names[k] then
794793 rawset(t, M.Attr._field_names[k], v)
795794 else
796795 rawset(t, k, v)
797796 end
798797end
799−setmetatable(M.Attr, M.Attr)
800798
801799-- Citation
802800M.Citation = AstElement:make_subtype'Citation'