From 244dae8da8d4bfbf3d5d7e22eacba6092789d841 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 9 Aug 2012 07:42:40 -0700 Subject: Added parseFormatSpec to Text.Pandoc. --- src/Text/Pandoc.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs index e12aa055c..b65e7130d 100644 --- a/src/Text/Pandoc.hs +++ b/src/Text/Pandoc.hs @@ -138,12 +138,34 @@ import Text.Pandoc.Options import Data.ByteString.Lazy (ByteString) import Data.Version (showVersion) import Text.JSON.Generic +import Data.Set (Set) +import qualified Data.Set as Set +import Text.Parsec import Paths_pandoc (version) -- | Version number of pandoc library. pandocVersion :: String pandocVersion = showVersion version +parseFormatSpec :: String + -> Either ParseError (String, Set Extension -> Set Extension) +parseFormatSpec = parse formatSpec "" + where formatSpec = do + name <- formatName + extMods <- many extMod + return (name, foldl (.) id extMods) + formatName = many1 $ noneOf "-+" + extMod = do + polarity <- oneOf "-+" + name <- many1 $ noneOf "-+" + ext <- case reads name of + ((n,[]):_) -> return n + _ -> unexpected $ "Unknown extension: " ++ + name + return $ case polarity of + '-' -> Set.delete ext + _ -> Set.insert ext + -- | Association list of formats and readers. readers :: [(String, ReaderOptions -> String -> Pandoc)] readers = [("native" , \_ -> readNative) -- cgit v1.2.3