Simple String aliasing to prepare the day when we'll be able to have more complex Component than just PDF Names (and access elements in an array)

This commit is contained in:
Tissevert 2020-02-28 18:14:27 +01:00
parent cb257fc07e
commit 4969c6442e
1 changed files with 5 additions and 4 deletions

View File

@ -41,6 +41,7 @@ newtype Error a = Error {
} deriving (Alternative, Functor, Applicative, Monad, MonadPlus)
instance MonadFail Error where
fail = Error . Left
type Component = String
getDictionary :: PDFContent m => Object -> m Dictionary
getDictionary (Direct (Dictionary aDict)) = return aDict
@ -64,21 +65,21 @@ objectById objectId = do
layer <- ask
return (objects layer ! objectId)
(./) :: PDFContent m => m Object -> String -> m Object
(./) :: PDFContent m => m Object -> Component -> m Object
(./) object key = (object >>= getDictionary >>= getField key >>= castObject)
where
castObject (Reference (IndirectObjCoordinates {objectId})) =
objectById objectId
castObject directObject = return $ Direct directObject
(//) :: PDFContent m => m Object -> [String] -> m Object
(//) :: PDFContent m => m Object -> [Component] -> m Object
(//) object [] = object
(//) object (key:keys) = object ./ key // keys
(>./) :: PDFContent m => Object -> String -> m Object
(>./) :: PDFContent m => Object -> Component -> m Object
(>./) object = (return object ./)
(>//) :: PDFContent m => Object -> [String] -> m Object
(>//) :: PDFContent m => Object -> [Component] -> m Object
(>//) object = (return object //)
origin :: PDFContent m => m Object