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

Paul Keir pkeir at dcs.gla.ac.uk
Tue Mar 25 16:26:05 EDT 2008


Thankyou. Yes, I'd also noticed that "only end" could result in the "end" part being taken as an identifier. The language I'm parsing actually doesn't have reserved words though; so "end" and "only" are both possible valid identifiers. I should then probably replace my use of say, reserved "only", with string "only"; whiteSpace; for clarity. Still stuck though...

P


-----Original Message-----
From: Brandon S. Allbery KF8NH [mailto:allbery at ece.cmu.edu]
Sent: Tue 25/03/2008 19:58
To: Paul Keir; haskell-cafe at haskell.org Cafe
Subject: Re: [Haskell-cafe] Parsec (Zero or One of)
 

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

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



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080325/25ee0268/attachment.htm


More information about the Haskell-Cafe mailing list