[Haskell-cafe] Parsec question

John Goerzen jgoerzen at complete.org
Fri Nov 19 10:34:44 EST 2004

On Fri, Nov 19, 2004 at 02:56:38PM -0000, Bayley, Alistair wrote:
> I've also used Parsec for separated lexer + parser and currently have
> something like this to invoke them:
> testParse inputString = do
>   case (parse myLexer "" inputString) of
>     Left err -> fail ("lexical error: " ++ err)
>     Right tokens ->
>       case (parse myParser "" tokens) of
>         Left err -> fail ("parse error: " ++ err)
>         Right result -> return result
> ... or was this the "manual startup" that you were referring to? The above
> seems clunky to me, so I'd also welcome suggestions for piping the lexer
> output into the parser.

Yep, that is exactly the idea I took.  Works, but just doesn't seem

> What do you mean by "makes position calculations very complex"? Are you
> talking about reporting the position of lexical or parse errors? (If so,
> Parsec supports this quite well.)

The parse errors.  I did take to passing around pairs of SourcePos, Tok
around.  It works, but I had to then write custom token functions to
handle them.  I'd rather be able to just access the other parser like
normal (refer to it in a do block or whatever), so I don't have to
manually handle it.  I suppose "very complex" was an exaggeration,
looking back.

-- John

More information about the Haskell-Cafe mailing list