Yes great explanation - solved my problem. Thanks! Jeff On Wednesday, 24 May 2017 16:27:06 UTC-4, John MacFarlane wrote: > > +++ Jeff [May 24 17 08:35 ]: > > 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. > > There's an important difference. header' will parse one > character at a time (anyChar), each time stopping to see > if the end condition (string "===") is met. > > header'' will parse CHUNKS of one or more character at > a time (many1 anyChar), only checking after each chunk > to see if the end condition is met. Does that explain it? > > -- 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/9d30a290-c9e1-477e-baf1-112ed0ca7fc4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.