[Haskell-cafe] ansi2html - one program, several issues

John Meacham john at repetae.net
Sun Jul 20 02:17:22 EDT 2008

On Sun, Jul 20, 2008 at 02:34:09AM +0400, Bulat Ziganshin wrote:
> i think that Parsec library should hold entire file in memory only when
> you use 'try' for whole file. otherwise it should omit data as
> proceeded

I do not believe that is the case, since the return type of runParser
"Either ParseError a" means that before you can extract the result of
the parse from the 'Right' branch, it must evaluate whether the result
is 'Left' or 'Right' meaning it needs to parse the whole input in order
to determine whether the parse was succesful.

This was the reason I made frisby's main parsing routine just be

> runPeg :: P a -> String -> a

so you have to do something explicit like

> runPegMaybe :: P a -> String -> Maybe a
> runPegMaybe p s = runPeg (fmap Just p // return Nothing) s

to force strictness in the parsing. 

Though, perhaps parsec is doing something more clever. I do know it uses
the one token lookahead trick to determine which branch to take on
alternation, but I don't think that solves the issue with parsing the
entire file..


John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list