I am new to Haskell and I am trying to write a new reader for Pandoc. There is something strange about manyTill and I'm a bit stuck. I have written a minimal code to present the problem. Suppose I want to write a parser that succeeds if the string ends in three equal signs "===", and return the string preceeding the "===". I have written three versions. One with Parsec, and two with Pandoc: import Text.Parsec.String (Parser) import Text.Parsec (parse, ParseError) import Text.Parsec.Combinator (many1, manyTill) import Text.Parsec.Char (anyChar, string, noneOf) import qualified Text.Pandoc.Builder as B (str) import Text.Pandoc.Builder (Inlines) import Text.Parsec.Prim (try) simpleParse :: Parser a -> String -> Either ParseError a simpleParse p = parse p "" header' :: Parser String header' = manyTill anyChar (string "===") header'' :: Parser [Inlines] header'' = manyTill (B.str <$> (many1 anyChar)) (string "===") header''' :: Parser [Inlines] header''' = manyTill (B.str <$> (many1 (noneOf "="))) (string "===") I thought header' and header'' are the same parser except the type is a bit different. But I'm wrong: *Main> simpleParse header' "a===" Right "a" *Main> simpleParse header'' "a===" Left (line 1, column 5): unexpected end of input expecting "===" *Main> simpleParse header''' "a===" Right [Many {unMany = fromList [Str "a"]}] header''' works, but it seems to me a hacky solution, and I also don't understand *why do I have to exclude '=' in the Pandoc implementation?* Another problem with header''' is that I can't parse say "=a===" with it. Of course one may try to use 'try', as follows: headerWithTry' :: Parser String headerWithTry' = manyTill anyChar (try (string "===")) headerWithTry'' :: Parser [Inlines] headerWithTry'' = manyTill (B.str <$> (many1 anyChar)) (try (string "===")) headerWithTry''' :: Parser [Inlines] headerWithTry''' = manyTill (B.str <$> (many1 (noneOf "="))) (try (string "===")) But it does not work: *Main> simpleParse headerWithTry' "=a===" Right "=a" *Main> simpleParse headerWithTry'' "=a===" Left (line 1, column 6): unexpected end of input expecting "===" *Main> simpleParse headerWithTry''' "=a===" Left (line 1, column 1): unexpected "a" expecting "===" *Why?* Thanks, Jeff -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d879451a-e34c-495b-b72d-414e752d1e51%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.