mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-22 07:25:36 +00:00
Factor out "returnState" into Parsing module
This commit is contained in:
@@ -66,6 +66,7 @@ module Text.Pandoc.Parsing ( anyLine,
|
||||
gridTableWith,
|
||||
readWith,
|
||||
returnWarnings,
|
||||
returnState,
|
||||
readWithM,
|
||||
testStringWith,
|
||||
guardEnabled,
|
||||
@@ -873,6 +874,10 @@ returnWarnings p = do
|
||||
warnings <- stateWarnings <$> getState
|
||||
return (doc, warnings)
|
||||
|
||||
-- | Return the final internal state with the result of a parser
|
||||
returnState :: (Stream s m c) => ParsecT s st m a -> ParsecT s st m (a, st)
|
||||
returnState p = (,) <$> p <*> getState
|
||||
|
||||
-- | Parse a string with @parser@ (for testing).
|
||||
testStringWith :: (Show a, Stream [Char] Identity Char)
|
||||
=> ParserT [Char] ParserState Identity a
|
||||
|
||||
@@ -81,17 +81,10 @@ readMarkdownWithWarnings :: ReaderOptions -- ^ Reader options
|
||||
-> (Pandoc, [String])
|
||||
readMarkdownWithWarnings opts s = runMarkdown opts s (returnWarnings parseMarkdown)
|
||||
|
||||
|
||||
retState :: MarkdownParser a -> MarkdownParser (a, ParserState)
|
||||
retState p = do
|
||||
r <- p
|
||||
s <- getState
|
||||
return (r, s)
|
||||
|
||||
runMarkdown :: ReaderOptions -> String -> MarkdownParser a -> a
|
||||
runMarkdown opts inp p = fst res
|
||||
where
|
||||
imd = readWithM (retState p) def{ stateOptions = opts } (inp ++ "\n\n")
|
||||
imd = readWithM (returnState p) def{ stateOptions = opts } (inp ++ "\n\n")
|
||||
res = runReader imd s
|
||||
s :: ParserState
|
||||
s = snd $ runReader imd s
|
||||
|
||||
@@ -74,18 +74,11 @@ type OrgParser = ParserT [Char] OrgParserState (Reader OrgParserLocal)
|
||||
runOrg :: ReaderOptions -> String -> OrgParser a -> a
|
||||
runOrg opts inp p = fst res
|
||||
where
|
||||
imd = readWithM (retState p) def{ orgStateOptions = opts } (inp ++ "\n\n")
|
||||
imd = readWithM (returnState p) def{ orgStateOptions = opts } (inp ++ "\n\n")
|
||||
res = runReader imd def { finalState = s }
|
||||
s :: OrgParserState
|
||||
s = snd $ runReader imd (def { finalState = s })
|
||||
|
||||
retState :: OrgParser a -> OrgParser (a, OrgParserState)
|
||||
retState p = do
|
||||
r <- p
|
||||
s <- getState
|
||||
return (r, s)
|
||||
|
||||
|
||||
parseOrg :: OrgParser Pandoc
|
||||
parseOrg = do
|
||||
blocks' <- parseBlocks
|
||||
|
||||
Reference in New Issue
Block a user