@@ -762,21 +762,22 @@ lineBlockLines = try $ do
762762
763763-- | Parse a table using 'headerParser', 'rowParser',
764764-- 'lineParser', and 'footerParser'.
765−tableWith :: Stream s m Char
766− => ParserT s ParserState m ([Blocks], [Alignment], [Int])
767− -> ([Int] -> ParserT s ParserState m [Blocks])
768− -> ParserT s ParserState m sep
769− -> ParserT s ParserState m end
770− -> ParserT s ParserState m Blocks
765+tableWith :: (Stream s m Char, HasReaderOptions st,
766+ Functor mf, Applicative mf, Monad mf)
767+ => ParserT s st m (mf [Blocks], [Alignment], [Int])
768+ -> ([Int] -> ParserT s st m (mf [Blocks]))
769+ -> ParserT s st m sep
770+ -> ParserT s st m end
771+ -> ParserT s st m (mf Blocks)
771772tableWith headerParser rowParser lineParser footerParser = try $ do
772773 (heads, aligns, indices) <- headerParser
773− lines' <- rowParser indices `sepEndBy1` lineParser
774+ lines' <- sequence <$> rowParser indices `sepEndBy1` lineParser
774775 footerParser
775776 numColumns <- getOption readerColumns
776777 let widths = if (indices == [])
777778 then replicate (length aligns) 0.0
778779 else widthsFromIndices numColumns indices
779− return $ B.table mempty (zip aligns widths) heads lines'
780+ return $ B.table mempty (zip aligns widths) <$> heads <*> lines'
780781
781782-- Calculate relative widths of table columns, based on indices
782783widthsFromIndices :: Int -- Number of columns on terminal
@@ -809,10 +810,11 @@ widthsFromIndices numColumns' indices =
809810-- (which may be grid), then the rows,
810811-- which may be grid, separated by blank lines, and
811812-- ending with a footer (dashed line followed by blank line).
812−gridTableWith :: Stream [Char] m Char
813− => ParserT [Char] ParserState m Blocks -- ^ Block list parser
814− -> Bool -- ^ Headerless table
815− -> ParserT [Char] ParserState m Blocks
813+gridTableWith :: (Stream [Char] m Char, HasReaderOptions st,
814+ Functor mf, Applicative mf, Monad mf)
815+ => ParserT [Char] st m (mf Blocks) -- ^ Block list parser
816+ -> Bool -- ^ Headerless table
817+ -> ParserT [Char] st m (mf Blocks)
816818gridTableWith blocks headless =
817819 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
818820 (gridTableSep '-') gridTableFooter
@@ -835,14 +837,14 @@ removeFinalBar =
835837 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
836838
837839-- | Separator between rows of grid table.
838−gridTableSep :: Stream s m Char => Char -> ParserT s ParserState m Char
840+gridTableSep :: Stream s m Char => Char -> ParserT s st m Char
839841gridTableSep ch = try $ gridDashedLines ch >> return '\n'
840842
841843-- | Parse header for a grid table.
842−gridTableHeader :: Stream [Char] m Char
844+gridTableHeader :: (Stream [Char] m Char, Functor mf, Applicative mf, Monad mf)
843845 => Bool -- ^ Headerless table
844− -> ParserT [Char] ParserState m Blocks
845− -> ParserT [Char] ParserState m ([Blocks], [Alignment], [Int])
846+ -> ParserT [Char] st m (mf Blocks)
847+ -> ParserT [Char] st m (mf [Blocks], [Alignment], [Int])
846848gridTableHeader headless blocks = try $ do
847849 optional blanklines
848850 dashes <- gridDashedLines '-'
@@ -862,25 +864,26 @@ gridTableHeader headless blocks = try $ do
862864 then replicate (length dashes) ""
863865 else map (intercalate " ") $ transpose
864866 $ map (gridTableSplitLine indices) rawContent
865− heads <- mapM (parseFromString blocks) $ map trim rawHeads
867+ heads <- fmap sequence . mapM (parseFromString blocks) $ map trim rawHeads
866868 return (heads, aligns, indices)
867869
868−gridTableRawLine :: Stream s m Char => [Int] -> ParserT s ParserState m [String]
870+gridTableRawLine :: Stream s m Char => [Int] -> ParserT s st m [String]
869871gridTableRawLine indices = do
870872 char '|'
871873 line <- many1Till anyChar newline
872874 return (gridTableSplitLine indices line)
873875
874876-- | Parse row of grid table.
875−gridTableRow :: Stream [Char] m Char
876− => ParserT [Char] ParserState m Blocks
877+gridTableRow :: (Stream [Char] m Char, Functor mf, Applicative mf, Monad mf)
878+ => ParserT [Char] st m (mf Blocks)
877879 -> [Int]
878− -> ParserT [Char] ParserState m [Blocks]
880+ -> ParserT [Char] st m (mf [Blocks])
879881gridTableRow blocks indices = do
880882 colLines <- many1 (gridTableRawLine indices)
881883 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
882884 transpose colLines
883− mapM (liftM compactifyCell . parseFromString blocks) cols
885+ cells <- sequence <$> mapM (parseFromString blocks) cols
886+ return $ fmap (map compactifyCell) cells
884887
885888removeOneLeadingSpace :: [String] -> [String]
886889removeOneLeadingSpace xs =
@@ -894,7 +897,7 @@ compactifyCell :: Blocks -> Blocks
894897compactifyCell bs = head $ compactify [bs]
895898
896899-- | Parse footer for a grid table.
897−gridTableFooter :: Stream s m Char => ParserT s ParserState m [Char]
900+gridTableFooter :: Stream s m Char => ParserT s st m [Char]
898901gridTableFooter = blanklines
899902
900903---