summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Parsing.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-07-14 11:17:46 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-07-14 11:17:46 +0200
commit42fd536a0e66dcfddb4abd7daf6d738bf954b62a (patch)
tree4ccc60046d1b2712bf8bf48a1fd54485a7047f42 /src/Text/Pandoc/Parsing.hs
parentf6d97bc8cc7d635c6a69f64293a0bf2a04a1db05 (diff)
Fix ghc 8.2.1 compiler warnings.
Diffstat (limited to 'src/Text/Pandoc/Parsing.hs')
-rw-r--r--src/Text/Pandoc/Parsing.hs49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 549042d14..0c97d4060 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -247,8 +247,9 @@ instance Monoid a => Monoid (Future s a) where
mconcat = liftM mconcat . sequence
-- | Parse characters while a predicate is true.
-takeWhileP :: Stream [Char] m Char
- => (Char -> Bool) -> ParserT [Char] st m [Char]
+takeWhileP :: Monad m
+ => (Char -> Bool)
+ -> ParserT [Char] st m [Char]
takeWhileP f = do
-- faster than 'many (satisfy f)'
inp <- getInput
@@ -262,7 +263,7 @@ takeWhileP f = do
-- Parse n characters of input (or the rest of the input if
-- there aren't n characters).
-takeP :: Stream [Char] m Char => Int -> ParserT [Char] st m [Char]
+takeP :: Monad m => Int -> ParserT [Char] st m [Char]
takeP n = do
guard (n > 0)
-- faster than 'count n anyChar'
@@ -276,7 +277,7 @@ takeP n = do
return xs
-- | Parse any line of text
-anyLine :: Stream [Char] m Char => ParserT [Char] st m [Char]
+anyLine :: Monad m => ParserT [Char] st m [Char]
anyLine = do
-- This is much faster than:
-- manyTill anyChar newline
@@ -292,13 +293,13 @@ anyLine = do
_ -> mzero
-- | Parse any line, include the final newline in the output
-anyLineNewline :: Stream [Char] m Char => ParserT [Char] st m [Char]
+anyLineNewline :: Monad m => ParserT [Char] st m [Char]
anyLineNewline = (++ "\n") <$> anyLine
-- | Parse indent by specified number of spaces (or equiv. tabs)
-indentWith :: Stream [Char] m Char
+indentWith :: Stream s m Char
=> HasReaderOptions st
- => Int -> ParserT [Char] st m [Char]
+ => Int -> ParserT s st m [Char]
indentWith num = do
tabStop <- getOption readerTabStop
if (num < tabStop)
@@ -394,9 +395,9 @@ stringAnyCase (x:xs) = do
-- | Parse contents of 'str' using 'parser' and return result.
parseFromString :: Monad m
- => ParserT String st m a
+ => ParserT [Char] st m a
-> String
- -> ParserT String st m a
+ -> ParserT [Char] st m a
parseFromString parser str = do
oldPos <- getPosition
setPosition $ initialPos "chunk"
@@ -422,9 +423,9 @@ parseFromString' parser str = do
return res
-- | Parse raw line block up to and including blank lines.
-lineClump :: Stream [Char] m Char => ParserT [Char] st m String
+lineClump :: Monad m => ParserT [Char] st m String
lineClump = blanklines
- <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
+ <|> (unlines <$> many1 (notFollowedBy blankline >> anyLine))
-- | Parse a string of characters between an open character
-- and a close character, including text between balanced
@@ -520,7 +521,7 @@ uriScheme :: Stream s m Char => ParserT s st m String
uriScheme = oneOfStringsCI (Set.toList schemes)
-- | Parses a URI. Returns pair of original and URI-escaped version.
-uri :: Stream [Char] m Char => ParserT [Char] st m (String, String)
+uri :: Monad m => ParserT [Char] st m (String, String)
uri = try $ do
scheme <- uriScheme
char ':'
@@ -625,7 +626,9 @@ withHorizDisplacement parser = do
-- | Applies a parser and returns the raw string that was parsed,
-- along with the value produced by the parser.
-withRaw :: Stream [Char] m Char => ParsecT [Char] st m a -> ParsecT [Char] st m (a, [Char])
+withRaw :: Monad m
+ => ParsecT [Char] st m a
+ -> ParsecT [Char] st m (a, [Char])
withRaw parser = do
pos1 <- getPosition
inp <- getInput
@@ -786,7 +789,7 @@ charRef = do
c <- characterReference
return $ Str [c]
-lineBlockLine :: Stream [Char] m Char => ParserT [Char] st m String
+lineBlockLine :: Monad m => ParserT [Char] st m String
lineBlockLine = try $ do
char '|'
char ' '
@@ -796,11 +799,11 @@ lineBlockLine = try $ do
continuations <- many (try $ char ' ' >> anyLine)
return $ white ++ unwords (line : continuations)
-blankLineBlockLine :: Stream [Char] m Char => ParserT [Char] st m Char
+blankLineBlockLine :: Stream s m Char => ParserT s st m Char
blankLineBlockLine = try (char '|' >> blankline)
-- | Parses an RST-style line block and returns a list of strings.
-lineBlockLines :: Stream [Char] m Char => ParserT [Char] st m [String]
+lineBlockLines :: Monad m => ParserT [Char] st m [String]
lineBlockLines = try $ do
lines' <- many1 (lineBlockLine <|> ((:[]) <$> blankLineBlockLine))
skipMany1 $ blankline <|> blankLineBlockLine
@@ -870,7 +873,7 @@ widthsFromIndices numColumns' indices =
-- (which may be grid), then the rows,
-- which may be grid, separated by blank lines, and
-- ending with a footer (dashed line followed by blank line).
-gridTableWith :: (Stream [Char] m Char, HasReaderOptions st,
+gridTableWith :: (Monad m, HasReaderOptions st,
Functor mf, Applicative mf, Monad mf)
=> ParserT [Char] st m (mf Blocks) -- ^ Block list parser
-> Bool -- ^ Headerless table
@@ -879,7 +882,7 @@ gridTableWith blocks headless =
tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
(gridTableSep '-') gridTableFooter
-gridTableWith' :: (Stream [Char] m Char, HasReaderOptions st,
+gridTableWith' :: (Monad m, HasReaderOptions st,
Functor mf, Applicative mf, Monad mf)
=> ParserT [Char] st m (mf Blocks) -- ^ Block list parser
-> Bool -- ^ Headerless table
@@ -919,7 +922,7 @@ gridTableSep :: Stream s m Char => Char -> ParserT s st m Char
gridTableSep ch = try $ gridDashedLines ch >> return '\n'
-- | Parse header for a grid table.
-gridTableHeader :: (Stream [Char] m Char, Functor mf, Applicative mf, Monad mf)
+gridTableHeader :: (Monad m, Functor mf, Applicative mf, Monad mf)
=> Bool -- ^ Headerless table
-> ParserT [Char] st m (mf Blocks)
-> ParserT [Char] st m (mf [Blocks], [Alignment], [Int])
@@ -952,7 +955,7 @@ gridTableRawLine indices = do
return (gridTableSplitLine indices line)
-- | Parse row of grid table.
-gridTableRow :: (Stream [Char] m Char, Functor mf, Applicative mf, Monad mf)
+gridTableRow :: (Monad m, Functor mf, Applicative mf, Monad mf)
=> ParserT [Char] st m (mf Blocks)
-> [Int]
-> ParserT [Char] st m (mf [Blocks])
@@ -981,8 +984,8 @@ gridTableFooter = blanklines
---
-- | Removes the ParsecT layer from the monad transformer stack
-readWithM :: (Monad m)
- => ParserT [Char] st m a -- ^ parser
+readWithM :: Monad m
+ => ParserT [Char] st m a -- ^ parser
-> st -- ^ initial state
-> String -- ^ input
-> m (Either PandocError a)
@@ -998,7 +1001,7 @@ readWith :: Parser [Char] st a
readWith p t inp = runIdentity $ readWithM p t inp
-- | Parse a string with @parser@ (for testing).
-testStringWith :: (Show a)
+testStringWith :: Show a
=> ParserT [Char] ParserState Identity a
-> [Char]
-> IO ()