aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-02-19 19:23:30 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-02-19 19:23:30 +0300
commit5a9d7d20ddeebc164acdbb3b318df298417ad1ab (patch)
tree504c72f28f433bcd18ce2c2bd810daf8d16cc410
parent574104861f13997effb36f8e3483dfd7c7d01cd7 (diff)
downloadpandoc-5a9d7d20ddeebc164acdbb3b318df298417ad1ab.tar.gz
Move manyUntil to Text.Pandoc.Parsing and use it in Txt2Tags reader
-rw-r--r--src/Text/Pandoc/Parsing.hs15
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs14
-rw-r--r--src/Text/Pandoc/Readers/Txt2Tags.hs3
-rw-r--r--test/Tests/Readers/Txt2Tags.hs5
4 files changed, 20 insertions, 17 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 562e3d577..1b66aa430 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -40,6 +40,7 @@ module Text.Pandoc.Parsing ( takeWhileP,
anyLineNewline,
indentWith,
many1Till,
+ manyUntil,
notFollowedBy',
oneOfStrings,
oneOfStringsCI,
@@ -325,6 +326,20 @@ many1Till p end = do
rest <- manyTill p end
return (first:rest)
+-- | Like @manyTill@, but also returns the result of end parser.
+manyUntil :: (Stream s m t)
+ => ParserT s u m a
+ -> ParserT s u m b
+ -> ParserT s u m ([a], b)
+manyUntil p end = scan
+ where scan =
+ (do e <- end
+ return ([], e)
+ ) <|>
+ (do x <- p
+ (xs, e) <- scan
+ return (x:xs, e))
+
-- | A more general form of @notFollowedBy@. This one allows any
-- type of parser to be specified, and succeeds only if that parser fails.
-- It does not consume any input.
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index a842925a2..2f20de1c9 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -189,20 +189,6 @@ atStart p = do
guard $ museLastStrPos st /= Just pos
p
--- Like manyTill, but also returns result of end parser
-manyUntil :: (Stream s m t)
- => ParserT s u m a
- -> ParserT s u m b
- -> ParserT s u m ([a], b)
-manyUntil p end = scan
- where scan =
- (do e <- end
- return ([], e)
- ) <|>
- (do x <- p
- (xs, e) <- scan
- return (x:xs, e))
-
someUntil :: (Stream s m t)
=> ParserT s u m a
-> ParserT s u m b
diff --git a/src/Text/Pandoc/Readers/Txt2Tags.hs b/src/Text/Pandoc/Readers/Txt2Tags.hs
index b4f4bc564..f4dda7a11 100644
--- a/src/Text/Pandoc/Readers/Txt2Tags.hs
+++ b/src/Text/Pandoc/Readers/Txt2Tags.hs
@@ -529,8 +529,7 @@ image = try $ do
-- List taken from txt2tags source
let extensions = [".jpg", ".jpeg", ".gif", ".png", ".eps", ".bmp"]
char '['
- path <- manyTill (noneOf "\n\t\r ") (try $ lookAhead (oneOfStrings extensions))
- ext <- oneOfStrings extensions
+ (path, ext) <- manyUntil (noneOf "\n\t\r ") (oneOfStrings extensions)
char ']'
return $ B.image (path ++ ext) "" mempty
diff --git a/test/Tests/Readers/Txt2Tags.hs b/test/Tests/Readers/Txt2Tags.hs
index 9c5053af7..435d983a1 100644
--- a/test/Tests/Readers/Txt2Tags.hs
+++ b/test/Tests/Readers/Txt2Tags.hs
@@ -96,9 +96,12 @@ tests =
, "Autolink" =:
"http://www.google.com" =?>
para (link "http://www.google.com" "" (str "http://www.google.com"))
- , "Image" =:
+ , "JPEG Image" =:
"[image.jpg]" =?>
para (image "image.jpg" "" mempty)
+ , "PNG Image" =:
+ "[image.png]" =?>
+ para (image "image.png" "" mempty)
, "Link" =:
"[title http://google.com]" =?>