From 44508a204ce9b96ddbbbb01e29e1dd168e860856 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Wed, 15 May 2019 09:04:17 +0200 Subject: [PATCH] Reuse Parser type in PDF.Body (and generalize the type of the comment parser) --- src/PDF/Body.hs | 11 ++++------- src/PDF/Object.hs | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/PDF/Body.hs b/src/PDF/Body.hs index 77bf8e2..c0a79b0 100644 --- a/src/PDF/Body.hs +++ b/src/PDF/Body.hs @@ -1,16 +1,13 @@ {-# LANGUAGE NamedFieldPuns #-} -module PDF.Body ( - populate - ) where +module PDF.Body where import Data.ByteString.Lazy.Char8 (ByteString) import qualified Data.ByteString.Lazy.Char8 as BS (drop, pack) -import Data.Functor.Identity (Identity) import Data.Int (Int64) import qualified Data.Map as Map (insert, lookup) import PDF.Object ( Content(..), DirectObject(..), IndirectObjCoordinates(..), Object(..) - , Occurrence(..), XRefEntry(..), XRefSection, XRefSubSection(..) + , Occurrence(..), Parser, XRefEntry(..), XRefSection, XRefSubSection(..) , eol, eolCharset, dictionary, directObject, integer, line ) import Text.Parsec @@ -20,7 +17,7 @@ data UserState = UserState { , content :: Content } -type SParser = ParsecT ByteString UserState Identity +type SParser = Parser UserState modifyContent :: (Content -> Content) -> SParser () modifyContent f = modifyState $ \state -> state {content = f $ content state} @@ -35,7 +32,7 @@ pushOccurrence newOccurrence = modifyContent $ \content -> content { body = newOccurrence : (body content) } -comment :: SParser String +comment :: Parser u String comment = char '%' *> many (noneOf eolCharset) <* eol lookupOffset :: Int -> XRefSection -> Maybe Int64 diff --git a/src/PDF/Object.hs b/src/PDF/Object.hs index 9de40c5..2de386d 100644 --- a/src/PDF/Object.hs +++ b/src/PDF/Object.hs @@ -6,6 +6,7 @@ module PDF.Object ( , IndirectObjCoordinates(..) , Object(..) , Occurrence(..) + , Parser , XRefEntry(..) , XRefSection , XRefSubSection(..)