[Haskell-cafe] parsec manyTill stack overflow

Badea Daniel badeadaniel at yahoo.com
Fri Jul 4 16:31:07 EDT 2008

I'm trying to parse a large file looking for instructions on each line and for a section end marker but Parsec's manyTill function causes stack overflow, as you can see in the following example (I'm using ghci 6.8.3):

> parse (many anyChar) "" ['a'|x<-[1..1024*64]]

It almost immediately starts printing "aaaaaaaaaaa...." and runs to completion.

> parse (manyTill anyChar eof) "" ['a'|x<-[1..1024*1024]]
*** Exception: stack overflow

I guess this happens because manyTill recursively accumulates output from the first parser and returns only when it hits the 'end' parser. Is it possible to write a version of 'manyTill' that works like 'many' returning output from 'anyChar' as soon as it advances through the list of tokens?



More information about the Haskell-Cafe mailing list