From 34d3f25e87240b4641d00b9f206e7301af932e42 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 Aug 2017 20:07:06 -0700 Subject: Parsing: added gobbleSpaces. This is a utility function to use in list parsing. --- src/Text/Pandoc/Parsing.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index 0c97d4060..37a0b53b4 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -49,6 +49,7 @@ module Text.Pandoc.Parsing ( takeWhileP, skipSpaces, blankline, blanklines, + gobbleSpaces, enclosed, stringAnyCase, parseFromString, @@ -377,6 +378,17 @@ blankline = try $ skipSpaces >> newline blanklines :: Stream s m Char => ParserT s st m [Char] blanklines = many1 blankline +-- | Gobble n spaces; if tabs are encountered, expand them +-- and gobble some or all of their spaces, leaving the rest. +gobbleSpaces :: Monad m => ReaderOptions -> Int -> ParserT [Char] st m () +gobbleSpaces _ 0 = return () +gobbleSpaces opts n = try $ do + char ' ' <|> do char '\t' + inp <- getInput + setInput $ replicate (readerTabStop opts - 1) ' ' ++ inp + return ' ' + gobbleSpaces opts (n - 1) + -- | Parses material enclosed between start and end parsers. enclosed :: (Show end, Stream s m Char) => ParserT s st m t -- ^ start parser -> ParserT s st m end -- ^ end parser -- cgit v1.2.3