git.iko.soy/typeable/pandoc
on master help sign in
Move utility error functions to Text.Pandoc.Shared
commitad39bc7009e320b3afb91a5683521eb1eccf0ef7 authorMatthew Pickering <matthewtpickering@gmail.com> dateWed 18 Feb 2015, 21:05 (12 years ago) parent48f442f
5 files changed+14−12
src/Text/Pandoc.hs+1−1 src/Text/Pandoc/Error.hs+1−8 src/Text/Pandoc/ImageSize.hs+1−2 src/Text/Pandoc/Readers/HTML.hs+1−1 src/Text/Pandoc/Shared.hs+10
src/Text/Pandoc.hs+1−1
@@ -164,7 +164,7 @@ import Text.Pandoc.Writers.Haddock
164164import Text.Pandoc.Writers.Custom
165165import Text.Pandoc.Templates
166166import Text.Pandoc.Options
167−import Text.Pandoc.Shared (safeRead, warn)
167+import Text.Pandoc.Shared (safeRead, warn, mapLeft)
168168import Text.Pandoc.MediaBag (MediaBag)
169169import Text.Pandoc.Error
170170import Data.Aeson
src/Text/Pandoc/Error.hs+1−8
@@ -28,7 +28,7 @@ This module provides a standard way to deal with possible errors encounted
2828during parsing.
2929
3030-}
31−module Text.Pandoc.Error (PandocError(..), handleError,hush, mapLeft) where
31+module Text.Pandoc.Error (PandocError(..), handleError) where
3232
3333import Text.Parsec.Error
3434import Text.Parsec.Pos hiding (Line)
@@ -46,13 +46,6 @@ data PandocError = -- | Generic parse failure
4646instance Error PandocError where
4747 strMsg = ParseFailure
4848
49−mapLeft :: (a -> b) -> Either a c -> Either b c
50−mapLeft f (Left x) = Left (f x)
51−mapLeft _ (Right x) = Right x
52−
53−hush :: Either a b -> Maybe b
54−hush (Left _) = Nothing
55−hush (Right x) = Just x
5649
5750-- | An unsafe method to handle `PandocError`s.
5851handleError :: Either PandocError a -> a
src/Text/Pandoc/ImageSize.hs+1−2
@@ -39,10 +39,9 @@ import Control.Monad
3939import Data.Bits
4040import Data.Binary
4141import Data.Binary.Get
42−import Text.Pandoc.Shared (safeRead)
42+import Text.Pandoc.Shared (safeRead, hush)
4343import qualified Data.Map as M
4444import Text.Pandoc.Compat.Except
45−import Text.Pandoc.Error
4645import Control.Monad.Trans
4746import Data.Maybe (fromMaybe)
4847
src/Text/Pandoc/Readers/HTML.hs+1−1
@@ -44,7 +44,7 @@ import Text.Pandoc.Definition
4444import qualified Text.Pandoc.Builder as B
4545import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..))
4646import Text.Pandoc.Shared ( extractSpaces, renderTags'
47− , escapeURI, safeRead )
47+ , escapeURI, safeRead, mapLeft )
4848import Text.Pandoc.Options (ReaderOptions(readerParseRaw, readerTrace)
4949 , Extension (Ext_epub_html_exts,
5050 Ext_native_divs, Ext_native_spans))
src/Text/Pandoc/Shared.hs+10
@@ -85,6 +85,8 @@ module Text.Pandoc.Shared (
8585 -- * Error handling
8686 err,
8787 warn,
88+ mapLeft,
89+ hush,
8890 -- * Safe read
8991 safeRead,
9092 -- * Temp directory
@@ -855,6 +857,14 @@ warn msg = do
855857 name <- getProgName
856858 UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
857859
860+mapLeft :: (a -> b) -> Either a c -> Either b c
861+mapLeft f (Left x) = Left (f x)
862+mapLeft _ (Right x) = Right x
863+
864+hush :: Either a b -> Maybe b
865+hush (Left _) = Nothing
866+hush (Right x) = Just x
867+
858868-- | Remove intermediate "." and ".." directories from a path.
859869--
860870-- > collapseFilePath "./foo" == "foo"