[Haskell-cafe] concurrent definitions with parsec

Zsolt SZALAI zs.szalai at gmail.com
Mon Mar 10 09:41:37 EDT 2008


Hi!

I'm writing a parser for a language, with a BNF like this:
Type = "type" Def
Def = RecordDef | RecordOfDef ...
RecordDef = "record" Body
RecordOfDef = "record" "of"

With a perser what uses parsec module it can be mapped to haskell easily:
structuredTypeDef = recordDef
                     <|> recordOfDef

But this way, the recordOfDef case will never be parsed at a line like "type
record <somethings>", because recordDef will win in the first place always.
Is there an option or an other operation instead of <|> to do the trick?
I cant see if the problem can be solved with parsecperm or not.

It is a possibility to do something like swap "recordDef  <|> recordOfDef"
with "recordlikeDefs "
where recordlikeDefs = do { reserved "record" ; others }
but that would be the dirty way...

Do you have any advise on the case?
Thanks,
-- 
Zsolt Szalai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080310/fcc18e10/attachment.htm


More information about the Haskell-Cafe mailing list