Rewrite findMeta in terms of listify.

It'll now recurse into the data item you give it, which means it works
on types like Actual where the Meta isn't an immediate child.
This commit is contained in:
Adam Sampson 2008-04-07 22:31:18 +00:00
parent c627214727
commit c4f147f5db

View File

@ -70,11 +70,9 @@ unpackMeta s
getInt s = case readDec s of [(v, "")] -> v getInt s = case readDec s of [(v, "")] -> v
-- | Find the first Meta value in some part of the AST. -- | Find the first Meta value in some part of the AST.
findMeta :: (Data t, Typeable t) => t -> Meta -- Return 'emptyMeta' if it couldn't find one.
findMeta e = case cast e of findMeta :: Data t => t -> Meta
Just m -> m findMeta e
Nothing -> if null (concat metaList) then emptyMeta else head (concat metaList) = case listify (const True :: Meta -> Bool) e of
where (m:_) -> m
metaList = gmapQ (mkQ [] findMeta') e [] -> emptyMeta
findMeta' :: Meta -> [Meta]
findMeta' m = [m]