Change return type of Native reader

This commit is contained in:
Matthew Pickering
2015-02-18 21:09:06 +00:00
parent 41d9527533
commit ef2a8107e2
+14 -26
View File
@@ -3,7 +3,7 @@ Copyright (C) 2011-2014 John MacFarlane <jgm@berkeley.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; Either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -33,6 +33,9 @@ module Text.Pandoc.Readers.Native ( readNative ) where
import Text.Pandoc.Definition
import Text.Pandoc.Shared (safeRead)
import Text.Pandoc.Error
import Control.Applicative
-- | Read native formatted text and return a Pandoc document.
-- The input may be a full pandoc document, a block list, a block,
-- an inline list, or an inline. Thus, for example,
@@ -44,33 +47,18 @@ import Text.Pandoc.Shared (safeRead)
-- > Pandoc nullMeta [Plain [Str "hi"]]
--
readNative :: String -- ^ String to parse (assuming @'\n'@ line endings)
-> Pandoc
readNative s =
case safeRead s of
Just d -> d
Nothing -> Pandoc nullMeta $ readBlocks s
-> Either PandocError Pandoc
readNative s = maybe (Pandoc nullMeta <$> readBlocks s) Right (safeRead s)
readBlocks :: String -> [Block]
readBlocks s =
case safeRead s of
Just d -> d
Nothing -> [readBlock s]
readBlocks :: String -> Either PandocError [Block]
readBlocks s = maybe ((:[]) <$> readBlock s) Right (safeRead s)
readBlock :: String -> Block
readBlock s =
case safeRead s of
Just d -> d
Nothing -> Plain $ readInlines s
readBlock :: String -> Either PandocError Block
readBlock s = maybe (Plain <$> readInlines s) Right (safeRead s)
readInlines :: String -> [Inline]
readInlines s =
case safeRead s of
Just d -> d
Nothing -> [readInline s]
readInlines :: String -> Either PandocError [Inline]
readInlines s = maybe ((:[]) <$> readInline s) Right (safeRead s)
readInline :: String -> Inline
readInline s =
case safeRead s of
Just d -> d
Nothing -> error "Cannot parse document"
readInline :: String -> Either PandocError Inline
readInline s = maybe (Left . ParseFailure $ "Could not read: " ++ s) Right (safeRead s)