[Haskell-cafe] Parsec question

Bayley, Alistair Alistair_Bayley at ldn.invesco.com
Fri Nov 19 09:56:38 EST 2004

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.

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.)


> -----Original Message-----
> From: John Goerzen [mailto:jgoerzen at complete.org] 
> Sent: 19 November 2004 14:28
> To: haskell-cafe at haskell.org
> Subject: [Haskell-cafe] Parsec question
> Hi,
> I'm porting a parser over from an OCamllex/Ocamlyacc version and I'm
> using Parsec for both the tokenizer and the resulting token 
> stream parser.
> I have both of them working fine, but now my question is: how do I
> combine them?  I can't quite figure out how to say "take the 
> output from
> this GenParser Char () Tok and use it as the input for this
> GenParser Tok () ParserOutput".
> Well, I have figured out an ugly way involving manually 
> starting up both
> parsers, but it makes position calculations very complex.  I 
> suspect I'm
> missing something.
> Ideas?

Confidentiality Note: The information contained in this 
message, and any attachments, may contain confidential 
and/or privileged material. It is intended solely for the 
person(s) or entity to which it is addressed. Any review, 
retransmission, dissemination, or taking of any action in 
reliance upon this information by persons or entities other 
than the intended recipient(s) is prohibited. If you received
this in error, please contact the sender and delete the 
material from any computer.

More information about the Haskell-Cafe mailing list