@@ -762,21 +762,22 @@ lineBlockLines = try $ do
763-- | Parse a table using 'headerParser', 'rowParser',
763-- | Parse a table using 'headerParser', 'rowParser',
764-- 'lineParser', and 'footerParser'.
764-- 'lineParser', and 'footerParser'.
765−tableWith :: Stream s m Char
765+tableWith :: (Stream s m Char, HasReaderOptions st,
766+ Functor mf, Applicative mf, Monad mf)
766− => ParserT s ParserState m ([Blocks], [Alignment], [Int])
767+ => ParserT s st m (mf [Blocks], [Alignment], [Int])
767− -> ([Int] -> ParserT s ParserState m [Blocks])
768+ -> ([Int] -> ParserT s st m (mf [Blocks]))
768− -> ParserT s ParserState m sep
769+ -> ParserT s st m sep
769− -> ParserT s ParserState m end
770+ -> ParserT s st m end
770− -> ParserT s ParserState m Blocks
771+ -> ParserT s st m (mf Blocks)
771tableWith headerParser rowParser lineParser footerParser = try $ do
772tableWith headerParser rowParser lineParser footerParser = try $ do
772 (heads, aligns, indices) <- headerParser
773 (heads, aligns, indices) <- headerParser
773− lines' <- rowParser indices `sepEndBy1` lineParser
774+ lines' <- sequence <$> rowParser indices `sepEndBy1` lineParser
774 footerParser
775 footerParser
775 numColumns <- getOption readerColumns
776 numColumns <- getOption readerColumns
776 let widths = if (indices == [])
777 let widths = if (indices == [])
777 then replicate (length aligns) 0.0
778 then replicate (length aligns) 0.0
778 else widthsFromIndices numColumns indices
779 else widthsFromIndices numColumns indices
779− return $ B.table mempty (zip aligns widths) heads lines'
780+ return $ B.table mempty (zip aligns widths) <$> heads <*> lines'
781-- Calculate relative widths of table columns, based on indices
782-- Calculate relative widths of table columns, based on indices
782widthsFromIndices :: Int -- Number of columns on terminal
783widthsFromIndices :: Int -- Number of columns on terminal
@@ -809,10 +810,11 @@ widthsFromIndices numColumns' indices =
809-- (which may be grid), then the rows,
810-- (which may be grid), then the rows,
810-- which may be grid, separated by blank lines, and
811-- which may be grid, separated by blank lines, and
811-- ending with a footer (dashed line followed by blank line).
812-- ending with a footer (dashed line followed by blank line).
812−gridTableWith :: Stream [Char] m Char
813+gridTableWith :: (Stream [Char] m Char, HasReaderOptions st,
814+ Functor mf, Applicative mf, Monad mf)
813− => ParserT [Char] ParserState m Blocks -- ^ Block list parser
815+ => ParserT [Char] st m (mf Blocks) -- ^ Block list parser
814− -> Bool -- ^ Headerless table
816+ -> Bool -- ^ Headerless table
815− -> ParserT [Char] ParserState m Blocks
817+ -> ParserT [Char] st m (mf Blocks)
816gridTableWith blocks headless =
818gridTableWith blocks headless =
817 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
819 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
818 (gridTableSep '-') gridTableFooter
820 (gridTableSep '-') gridTableFooter
@@ -835,14 +837,14 @@ removeFinalBar =
835 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
837 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
837-- | Separator between rows of grid table.
839-- | 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
839gridTableSep ch = try $ gridDashedLines ch >> return '\n'
841gridTableSep ch = try $ gridDashedLines ch >> return '\n'
841-- | Parse header for a grid table.
843-- | Parse header for a grid table.
842−gridTableHeader :: Stream [Char] m Char
844+gridTableHeader :: (Stream [Char] m Char, Functor mf, Applicative mf, Monad mf)
843 => Bool -- ^ Headerless table
845 => Bool -- ^ Headerless table
844− -> ParserT [Char] ParserState m Blocks
846+ -> ParserT [Char] st m (mf Blocks)
845− -> ParserT [Char] ParserState m ([Blocks], [Alignment], [Int])
847+ -> ParserT [Char] st m (mf [Blocks], [Alignment], [Int])
846gridTableHeader headless blocks = try $ do
848gridTableHeader headless blocks = try $ do
847 optional blanklines
849 optional blanklines
848 dashes <- gridDashedLines '-'
850 dashes <- gridDashedLines '-'
@@ -862,25 +864,26 @@ gridTableHeader headless blocks = try $ do
862 then replicate (length dashes) ""
864 then replicate (length dashes) ""
863 else map (intercalate " ") $ transpose
865 else map (intercalate " ") $ transpose
864 $ map (gridTableSplitLine indices) rawContent
866 $ map (gridTableSplitLine indices) rawContent
865− heads <- mapM (parseFromString blocks) $ map trim rawHeads
867+ heads <- fmap sequence . mapM (parseFromString blocks) $ map trim rawHeads
866 return (heads, aligns, indices)
868 return (heads, aligns, indices)
868−gridTableRawLine :: Stream s m Char => [Int] -> ParserT s ParserState m [String]
870+gridTableRawLine :: Stream s m Char => [Int] -> ParserT s st m [String]
869gridTableRawLine indices = do
871gridTableRawLine indices = do
871 line <- many1Till anyChar newline
873 line <- many1Till anyChar newline
872 return (gridTableSplitLine indices line)
874 return (gridTableSplitLine indices line)
874-- | Parse row of grid table.
876-- | Parse row of grid table.
875−gridTableRow :: Stream [Char] m Char
877+gridTableRow :: (Stream [Char] m Char, Functor mf, Applicative mf, Monad mf)
876− => ParserT [Char] ParserState m Blocks
878+ => ParserT [Char] st m (mf Blocks)
878− -> ParserT [Char] ParserState m [Blocks]
880+ -> ParserT [Char] st m (mf [Blocks])
879gridTableRow blocks indices = do
881gridTableRow blocks indices = do
880 colLines <- many1 (gridTableRawLine indices)
882 colLines <- many1 (gridTableRawLine indices)
881 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
883 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
882 transpose colLines
884 transpose colLines
883− mapM (liftM compactifyCell . parseFromString blocks) cols
885+ cells <- sequence <$> mapM (parseFromString blocks) cols
886+ return $ fmap (map compactifyCell) cells
885removeOneLeadingSpace :: [String] -> [String]
888removeOneLeadingSpace :: [String] -> [String]
886removeOneLeadingSpace xs =
889removeOneLeadingSpace xs =
@@ -894,7 +897,7 @@ compactifyCell :: Blocks -> Blocks
894compactifyCell bs = head $ compactify [bs]
897compactifyCell bs = head $ compactify [bs]
896-- | Parse footer for a grid table.
899-- | 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]
898gridTableFooter = blanklines
901gridTableFooter = blanklines