[Haskell-cafe] Parsec (Zero or One of)

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Tue Mar 25 15:58:24 EDT 2008

On Mar 25, 2008, at 12:43 , Paul Keir wrote:
> Thanks. I can't find optionMaybe in my version 2.1 of Parsec, but  
> in any case, defining my only_prod as
> only_prod = do { reserved "only"; option [] identifier }
> or
> only_prod = do { reserved "only"; identifier <|> return [] }
> gives the same error responses as before. I will anyway look closer  
> at option.

The other problem here is that just using a given string in  
"reserved" doesn't prevent it from being parsed elsewhere by  
"identifier".  (Note the character offset of the error was 9, i.e.  
just past "only end", and it was looking for "end" or more identifier  

Are you using the higher level parser facilities from  
Text.ParserCombinators.Parsec.Token, or rolling your own?  If the  
latter, you will need to modify "identifier" to not accept keywords.

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

More information about the Haskell-Cafe mailing list