mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 11:16:33 +00:00
Added charsInBalanced parser combinator to Text.Pandoc.ParserCombinators.
This is not currently used, but should be useful in parsing strings containing balanced pairs of brackets or parentheses. git-svn-id: https://pandoc.googlecode.com/svn/trunk@728 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
@@ -39,7 +39,8 @@ module Text.Pandoc.ParserCombinators (
|
||||
enclosed,
|
||||
stringAnyCase,
|
||||
parseFromStr,
|
||||
lineClump
|
||||
lineClump,
|
||||
charsInBalanced
|
||||
) where
|
||||
import Text.ParserCombinators.Parsec
|
||||
import Data.Char ( toUpper, toLower )
|
||||
@@ -122,3 +123,18 @@ lineClump = do
|
||||
blanks <- blanklines <|> (do{eof; return "\n"})
|
||||
return ((unlines lines) ++ blanks)
|
||||
|
||||
-- | Parse a string of characters between an open character
|
||||
-- and a close character, including text between balanced
|
||||
-- pairs of open and close. For example,
|
||||
-- @charsInBalanced '(' ')'@ will parse "(hello (there))"
|
||||
-- and return "hello (there)".
|
||||
charsInBalanced :: Char -> Char -> GenParser Char st String
|
||||
charsInBalanced open close = try $ do
|
||||
char open
|
||||
raw <- manyTill ( (do res <- charsInBalanced open close
|
||||
return $ [open] ++ res ++ [close])
|
||||
<|> (do notFollowedBy' (blankline >> blanklines)
|
||||
count 1 anyChar))
|
||||
(char close)
|
||||
return $ concat raw
|
||||
|
||||
|
||||
Reference in New Issue
Block a user