From 167012daf75436208bcf275164792f3ec06ee56c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 10 Sep 2012 14:35:21 -0700 Subject: Export 'nested' in Parsing. --- src/Text/Pandoc/Parsing.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Text/Pandoc/Parsing.hs') diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index d4a1afbec..bee96be82 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -82,6 +82,7 @@ module Text.Pandoc.Parsing ( (>>~), ellipses, apostrophe, dash, + nested, macro, applyMacros', Parser, @@ -925,6 +926,18 @@ emDashOld = do try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-') return (Str "\8212") +-- This is used to prevent exponential blowups for things like: +-- a**a*a**a*a**a*a**a*a**a*a**a*a** +nested :: Parser s ParserState a + -> Parser s ParserState a +nested p = do + nestlevel <- stateMaxNestingLevel `fmap` getState + guard $ nestlevel > 0 + updateState $ \st -> st{ stateMaxNestingLevel = stateMaxNestingLevel st - 1 } + res <- p + updateState $ \st -> st{ stateMaxNestingLevel = nestlevel } + return res + -- -- Macros -- -- cgit v1.2.3