diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-08-08 20:07:06 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-08-08 20:07:06 -0700 |
commit | 34d3f25e87240b4641d00b9f206e7301af932e42 (patch) | |
tree | 37e56c57fd76a9fde61aba272af60da30ec02c90 /src/Text/Pandoc | |
parent | b1c2ada4e4da71578b934ffc7aafb11208f2b552 (diff) | |
download | pandoc-34d3f25e87240b4641d00b9f206e7301af932e42.tar.gz |
Parsing: added gobbleSpaces.
This is a utility function to use in list parsing.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 12 |
1 files changed, 12 insertions, 0 deletions
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 |