summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-10-20 20:16:28 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-10-20 21:05:58 -0700
commit23921b2ef1ba5be07cfaecc52c446bd3958425a9 (patch)
tree1ea055a019e95874a96666970e1bdf20761a7fe3 /src
parentaf12b56d068fb3e021585df44d196bbcac478ffa (diff)
Text.Pandoc.Parsing: remove `nested` [API change].
It was not being used, and in fact it was a bad idea from the beginning, as it had no hope of solving the problem it was introduced to solve.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Parsing.hs2
-rw-r--r--src/Text/Pandoc/Parsing/General.hs17
-rw-r--r--src/Text/Pandoc/Parsing/State.hs2
-rw-r--r--src/Text/Pandoc/Readers/DokuWiki.hs13
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs19
-rw-r--r--src/Text/Pandoc/Readers/TWiki.hs15
-rw-r--r--src/Text/Pandoc/Readers/TikiWiki.hs13
7 files changed, 12 insertions, 69 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 501e8c74b..6284bb0f3 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -105,7 +105,6 @@ module Text.Pandoc.Parsing ( module Text.Pandoc.Sources,
doubleCloseQuote,
ellipses,
dash,
- nested,
citeKey,
Parsec,
ParsecT,
@@ -279,7 +278,6 @@ import Text.Pandoc.Parsing.General
manyTillChar,
manyUntil,
manyUntilChar,
- nested,
nonspaceChar,
notFollowedBy',
oneOfStrings,
diff --git a/src/Text/Pandoc/Parsing/General.hs b/src/Text/Pandoc/Parsing/General.hs
index f09175cd4..397a3e94f 100644
--- a/src/Text/Pandoc/Parsing/General.hs
+++ b/src/Text/Pandoc/Parsing/General.hs
@@ -37,7 +37,6 @@ module Text.Pandoc.Parsing.General
, manyTillChar
, manyUntil
, manyUntilChar
- , nested
, nonspaceChar
, notFollowedBy'
, oneOfStrings
@@ -63,8 +62,7 @@ module Text.Pandoc.Parsing.General
where
import Control.Monad
- ( guard
- , join
+ ( join
, liftM
, unless
, void
@@ -683,19 +681,6 @@ registerHeader (ident,classes,kvs) header' = do
updateState $ updateIdentifierList $ Set.insert ident
return (ident,classes,kvs)
--- This is used to prevent exponential blowups for things like:
--- a**a*a**a*a**a*a**a*a**a*a**a*a**
-nested :: Stream s m a
- => ParsecT s ParserState m a
- -> ParsecT s ParserState m a
-nested p = do
- nestlevel <- stateMaxNestingLevel <$> getState
- guard $ nestlevel > 0
- updateState $ \st -> st{ stateMaxNestingLevel = stateMaxNestingLevel st - 1 }
- res <- p
- updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
- return res
-
token :: (Stream s m t)
=> (t -> Text)
-> (t -> SourcePos)
diff --git a/src/Text/Pandoc/Parsing/State.hs b/src/Text/Pandoc/Parsing/State.hs
index 1efb90b73..66432fa1e 100644
--- a/src/Text/Pandoc/Parsing/State.hs
+++ b/src/Text/Pandoc/Parsing/State.hs
@@ -46,7 +46,6 @@ data ParserState = ParserState
, stateQuoteContext :: QuoteContext -- ^ Inside quoted environment?
, stateAllowLinks :: Bool -- ^ Allow parsing of links
, stateAllowLineBreaks :: Bool -- ^ Allow parsing of line breaks
- , stateMaxNestingLevel :: Int -- ^ Max # of nested Strong/Emph
, stateLastStrPos :: Maybe SourcePos -- ^ Position after last str parsed
, stateKeys :: KeyTable -- ^ List of reference keys
, stateHeaderKeys :: KeyTable -- ^ List of implicit header ref keys
@@ -141,7 +140,6 @@ defaultParserState = ParserState
, stateQuoteContext = NoQuote
, stateAllowLinks = True
, stateAllowLineBreaks = True
- , stateMaxNestingLevel = 6
, stateLastStrPos = Nothing
, stateKeys = M.empty
, stateHeaderKeys = M.empty
diff --git a/src/Text/Pandoc/Readers/DokuWiki.hs b/src/Text/Pandoc/Readers/DokuWiki.hs
index d62ea970f..3d52cd747 100644
--- a/src/Text/Pandoc/Readers/DokuWiki.hs
+++ b/src/Text/Pandoc/Readers/DokuWiki.hs
@@ -27,7 +27,7 @@ import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Options
-import Text.Pandoc.Parsing hiding (enclosed, nested)
+import Text.Pandoc.Parsing hiding (enclosed)
import Text.Pandoc.Shared (trim, stringify, tshow)
import Data.List (isPrefixOf, isSuffixOf)
import qualified Safe
@@ -53,15 +53,6 @@ type DWParser = ParsecT Sources ParserState
eol :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m ()
eol = void newline <|> eof
-nested :: PandocMonad m => DWParser m a -> DWParser m a
-nested p = do
- nestlevel <- stateMaxNestingLevel <$> getState
- guard $ nestlevel > 0
- updateState $ \st -> st{ stateMaxNestingLevel = stateMaxNestingLevel st - 1 }
- res <- p
- updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
- return res
-
guardColumnOne :: PandocMonad m => DWParser m ()
guardColumnOne = getPosition >>= \pos -> guard (sourceColumn pos == 1)
@@ -163,7 +154,7 @@ nestedInlines :: (Show a, PandocMonad m)
nestedInlines end = innerSpace <|> nestedInline
where
innerSpace = try $ whitespace <* notFollowedBy end
- nestedInline = notFollowedBy whitespace >> nested inline
+ nestedInline = notFollowedBy whitespace >> inline
bold :: PandocMonad m => DWParser m B.Inlines
bold = try $ B.strong <$> enclosed (string "**") nestedInlines
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
index 33fcace2a..e7fae679c 100644
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -34,7 +34,7 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Logging
import Text.Pandoc.Options
-import Text.Pandoc.Parsing hiding (nested, tableCaption)
+import Text.Pandoc.Parsing hiding (tableCaption)
import Text.Pandoc.Readers.HTML (htmlTag, isBlockTag, isCommentTag, toAttr)
import Text.Pandoc.Shared (safeRead, stringify, stripTrailingNewlines,
trim, splitTextBy, tshow, formatCode)
@@ -86,17 +86,6 @@ instance HasLogMessages MWState where
-- auxiliary functions
--
--- This is used to prevent exponential blowups for things like:
--- ''a'''a''a'''a''a'''a''a'''a
-nested :: PandocMonad m => MWParser m a -> MWParser m a
-nested p = do
- nestlevel <- mwMaxNestingLevel `fmap` getState
- guard $ nestlevel > 0
- updateState $ \st -> st{ mwMaxNestingLevel = mwMaxNestingLevel st - 1 }
- res <- p
- updateState $ \st -> st{ mwMaxNestingLevel = nestlevel }
- return res
-
specialChars :: [Char]
specialChars = "'[]<=&*{}|\":\\"
@@ -706,12 +695,12 @@ inlinesBetween start end =
trimInlines . mconcat <$> try (start >> many1Till inline end)
emph :: PandocMonad m => MWParser m Inlines
-emph = B.emph <$> nested (inlinesBetween start end)
+emph = B.emph <$> inlinesBetween start end
where start = sym "''"
end = try $ notFollowedBy' (() <$ strong) >> sym "''"
strong :: PandocMonad m => MWParser m Inlines
-strong = B.strong <$> nested (inlinesBetween start end)
+strong = B.strong <$> inlinesBetween start end
where start = sym "'''"
end = sym "'''"
@@ -720,6 +709,6 @@ doubleQuotes = do
guardEnabled Ext_smart
inTT <- mwInTT <$> getState
guard (not inTT)
- B.doubleQuoted <$> nested (inlinesBetween openDoubleQuote closeDoubleQuote)
+ B.doubleQuoted <$> inlinesBetween openDoubleQuote closeDoubleQuote
where openDoubleQuote = sym "\"" >> lookAhead nonspaceChar
closeDoubleQuote = try $ sym "\""
diff --git a/src/Text/Pandoc/Readers/TWiki.hs b/src/Text/Pandoc/Readers/TWiki.hs
index 54b69c34f..8bba600a2 100644
--- a/src/Text/Pandoc/Readers/TWiki.hs
+++ b/src/Text/Pandoc/Readers/TWiki.hs
@@ -26,7 +26,7 @@ import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Options
-import Text.Pandoc.Parsing hiding (enclosed, nested)
+import Text.Pandoc.Parsing hiding (enclosed)
import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag)
import Text.Pandoc.Shared (tshow)
import Text.Pandoc.XML (fromEntities)
@@ -52,15 +52,6 @@ type TWParser = ParsecT Sources ParserState
tryMsg :: Text -> TWParser m a -> TWParser m a
tryMsg msg p = try p <?> T.unpack msg
-nested :: PandocMonad m => TWParser m a -> TWParser m a
-nested p = do
- nestlevel <- stateMaxNestingLevel <$> getState
- guard $ nestlevel > 0
- updateState $ \st -> st{ stateMaxNestingLevel = stateMaxNestingLevel st - 1 }
- res <- p
- updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
- return res
-
htmlElement :: PandocMonad m => Text -> TWParser m (Attr, Text)
htmlElement tag = tryMsg tag $ do
(TagOpen _ attr, _) <- htmlTag (~== TagOpen tag [])
@@ -85,7 +76,7 @@ parseHtmlContentWithAttrs tag parser = do
parsedContent <- try $ parseContent content
return (attr, parsedContent)
where
- parseContent = parseFromString' $ nested $ manyTill parser endOfContent
+ parseContent = parseFromString' $ manyTill parser endOfContent
endOfContent = try $ skipMany blankline >> skipSpaces >> eof
parseCharHtmlContentWithAttrs :: PandocMonad m
@@ -402,7 +393,7 @@ nestedInlines :: (Show a, PandocMonad m)
nestedInlines end = innerSpace <|> nestedInline
where
innerSpace = try $ whitespace <* notFollowedBy end
- nestedInline = notFollowedBy whitespace >> nested inline
+ nestedInline = notFollowedBy whitespace >> inline
strong :: PandocMonad m => TWParser m B.Inlines
strong = try $ B.strong <$> enclosed (char '*') nestedInlines
diff --git a/src/Text/Pandoc/Readers/TikiWiki.hs b/src/Text/Pandoc/Readers/TikiWiki.hs
index 10714ca9f..f009fad61 100644
--- a/src/Text/Pandoc/Readers/TikiWiki.hs
+++ b/src/Text/Pandoc/Readers/TikiWiki.hs
@@ -29,7 +29,7 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Logging (Verbosity (..))
import Text.Pandoc.Options
-import Text.Pandoc.Parsing hiding (enclosed, nested)
+import Text.Pandoc.Parsing hiding (enclosed)
import Text.Pandoc.Shared (safeRead)
import Text.Pandoc.XML (fromEntities)
import Text.Printf (printf)
@@ -58,15 +58,6 @@ tryMsg msg p = try p <?> T.unpack msg
skip :: TikiWikiParser m a -> TikiWikiParser m ()
skip parser = Control.Monad.void parser
-nested :: PandocMonad m => TikiWikiParser m a -> TikiWikiParser m a
-nested p = do
- nestlevel <- stateMaxNestingLevel <$> getState
- guard $ nestlevel > 0
- updateState $ \st -> st{ stateMaxNestingLevel = stateMaxNestingLevel st - 1 }
- res <- p
- updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
- return res
-
--
-- main parser
--
@@ -450,7 +441,7 @@ nestedInlines :: (Show a, PandocMonad m) => TikiWikiParser m a -> TikiWikiParser
nestedInlines end = innerSpace <|> nestedInline
where
innerSpace = try $ whitespace <* notFollowedBy end
- nestedInline = notFollowedBy whitespace >> nested inline
+ nestedInline = notFollowedBy whitespace >> inline
-- {img attId="39" imalign="right" link="http://info.tikiwiki.org" alt="Panama Hat"}
--