@@ -55,6 +55,18 @@ local FluentNode = class({
5555
5656 attach = function (self , node )
5757 return node and type (node .__mul ) == " function" and self * node
58+ end ,
59+
60+ __call = function (self , ...)
61+ return self :format (... )
62+ end ,
63+
64+ __tostring = function (self )
65+ return self :format ({})
66+ end ,
67+
68+ __concat = function (a , b )
69+ return tostring (a ) .. tostring (b )
5870 end
5971
6072 })
@@ -86,6 +98,11 @@ node_types.Message = class({
8698 _init = function (self , node )
8799 self .attributes = {}
88100 self :super (node )
101+ -- Penlight bug #307, should be — self:catch(self.get_attribute)
102+ self :catch (function (_ , k ) return self :get_attribute (k ) end )
103+ end ,
104+ get_attribute = function (self , attribute )
105+ return self .index [attribute ] and self .attributes [self .index [attribute ]] or nil
89106 end ,
90107 format = function (self , parameters )
91108 return self .value :format (parameters )
@@ -298,6 +315,9 @@ node_types.Attribute = class({
298315 self .value = node
299316 return self
300317 end
318+ end ,
319+ format = function (self , parameters )
320+ return self .value :format (parameters )
301321 end
302322 })
303323
@@ -350,7 +370,8 @@ local FluentResource = class({
350370 end
351371 end
352372 flush ()
353- -- self:catch(function (self, identifier) return self:get_message(identifier) end)
373+ -- Penlight bug #307, should be — self:catch(self.get_message)
374+ self :catch (function (_ , k ) return self :get_message (k ) end )
354375 end ,
355376
356377 insert = function (self , node )
@@ -361,15 +382,12 @@ local FluentResource = class({
361382 end ,
362383
363384 get_message = function (self , identifier )
385+ local key = rawget (self .index , string.match (identifier , " ^(%a[-_%a%d]+)" ))
386+ if not key then return end
387+ local entry = rawget (self , " body" )[key ]
388+ if not entry then return end
364389 local attr = string.match (identifier , " %.([(%a[-_%a%d]+)$" )
365- local id = string.match (identifier , " ^(%a[-_%a%d]+)" )
366- if not self .index [id ] then error (" No such entry" ) end
367- local entry = self .body [self .index [id ]]
368- if attr then
369- return entry .attributes [entry .index [attr ]].value
370- else
371- return entry .value
372- end
390+ return attr and entry .attributes [entry .index [attr ]] or entry
373391 end ,
374392
375393 dump_ast = function (self )
0 commit comments