Parsing: added gobbleSpaces.
This is a utility function to use in list parsing.
This commit is contained in:
parent
b1c2ada4e4
commit
34d3f25e87
1 changed files with 12 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue