diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-15 23:48:17 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-15 23:48:17 +0000 |
commit | 8e71c4c388a086efb7ea971fa3ea96d0b4c975fd (patch) | |
tree | 23a24c1c2f5100f5aa81ac47fa23d30313ff407c /src | |
parent | 54dd46c07c505bd89151cc9dc965bf40ad519c8f (diff) | |
download | pandoc-8e71c4c388a086efb7ea971fa3ea96d0b4c975fd.tar.gz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/ParserCombinators.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Text/Pandoc/ParserCombinators.hs b/src/Text/Pandoc/ParserCombinators.hs index 7a129b6be..2e4c1413c 100644 --- a/src/Text/Pandoc/ParserCombinators.hs +++ b/src/Text/Pandoc/ParserCombinators.hs @@ -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 + |