diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-08-09 07:42:40 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-08-09 07:42:40 -0700 |
commit | 244dae8da8d4bfbf3d5d7e22eacba6092789d841 (patch) | |
tree | 6cba2354245abb8f78c665937122ba0156e506dd /src | |
parent | dfa4b76630837560189844eb79c83abcb619b0f6 (diff) | |
download | pandoc-244dae8da8d4bfbf3d5d7e22eacba6092789d841.tar.gz |
Added parseFormatSpec to Text.Pandoc.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc.hs | 22 |
1 files changed, 22 insertions, 0 deletions
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) |