
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.) Alistair.
-----Original Message----- From: John Goerzen [mailto:jgoerzen@complete.org] Sent: 19 November 2004 14:28 To: haskell-cafe@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. *****************************************************************

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 right.
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
participants (2)
-
Bayley, Alistair
-
John Goerzen