diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-08-09 07:52:39 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-08-09 07:52:39 -0700 |
commit | 10cdd59fa8664caf5ac73dc06ee7076a4bbe69bd (patch) | |
tree | 34976c4cc39da3646399f30f84d500b45944a295 /src/Text/Pandoc/Shared.hs | |
parent | 244dae8da8d4bfbf3d5d7e22eacba6092789d841 (diff) | |
download | pandoc-10cdd59fa8664caf5ac73dc06ee7076a4bbe69bd.tar.gz |
Added safeRead to Text.Pandoc.Shared.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index f3ec43a06..9f615867c 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -65,7 +65,9 @@ module Text.Pandoc.Shared ( readDataFile, -- * Error handling err, - warn + warn, + -- * Safe read + safeRead ) where import Text.Pandoc.Definition @@ -489,3 +491,12 @@ warn :: String -> IO () warn msg = do name <- getProgName UTF8.hPutStrLn stderr $ name ++ ": " ++ msg + +-- +-- Safe read +-- + +safeRead :: (Monad m, Read a) => String -> m a +safeRead s = case reads s of + (d,[]):_ -> return d + _ -> fail $ "Could not read `" ++ s ++ "'" |