Simplified inlinesInBalanced, using lookAhead.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@732 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2007-07-16 07:22:17 +00:00
parent 0ba858f22d
commit 48d67d0d1f

View file

@ -133,13 +133,13 @@ failUnlessSmart = do
-- between balanced pairs of @opener@ and a @closer@.
inlinesInBalanced :: String -> String -> GenParser Char ParserState [Inline]
inlinesInBalanced opener closer = try $ do
let nonOpenerSymbol = try $ do -- succeeds if next inline would be Str opener
res <- inline -- fails if next inline merely begins with opener
let openerSymbol = try $ do
res <- inline
if res == Str opener
then pzero
else return ' '
then return res
else pzero
try (string opener)
result <- manyTill ( (do notFollowedBy nonOpenerSymbol
result <- manyTill ( (do lookAhead openerSymbol
bal <- inlinesInBalanced opener closer
return $ [Str opener] ++ bal ++ [Str closer])
<|> (count 1 inline))