[Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-17 Thread Graham Klyne
I've attempted to define a Parsec combinator thus: [[ notMatching :: Show a => GenParser tok st a -> GenParser tok st () notMatching p = try ( do { a <- p ; unexpected (show a) } <|> return () ) ]] It's modelled on the Parsec-provided combinator 'notFollowedBy', but is less fussy about the type o

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-17 Thread Andrew Pimlott
On Tue, Feb 17, 2004 at 06:42:39PM +, Graham Klyne wrote: > I've attempted to define a Parsec combinator thus: > > [[ > notMatching :: Show a => GenParser tok st a -> GenParser tok st () > notMatching p = try ( do { a <- p ; unexpected (show a) } <|> return () ) > ]] If p fails but consumes s

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-17 Thread Graham Klyne
Thanks! That got me going, though not with quite what you suggested. I ended up with this: [[ notMatching :: Show a => GenParser tok st a -> GenParser tok st () notMatching p = do { a <- try p ; unexpected (show a) } <|> return () ]] which does the required job for me. Using your version caused t

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-17 Thread Andrew Pimlott
On Tue, Feb 17, 2004 at 07:48:52PM +, Graham Klyne wrote: > Thanks! That got me going, though not with quite what you suggested. > > I ended up with this: > [[ > notMatching :: Show a => GenParser tok st a -> GenParser tok st () > notMatching p = do { a <- try p ; unexpected (show a) } <|> re

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-17 Thread Andrew Pimlott
On Tue, Feb 17, 2004 at 04:57:34PM -0500, Andrew Pimlott wrote: > What about a more prosaic implementation: > > notFollowedBy' :: Show a => GenParser tok st a -> GenParser tok st () > notFollowedBy' p= do res <- do a <- try p; return $ Just a > <

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-18 Thread Daan Leijen
On Wed, 18 Feb 2004 01:11:31 -0500, Andrew Pimlott <[EMAIL PROTECTED]> wrote: After some pondering and fiddling, a version I like: notFollowedBy' :: Show a => GenParser tok st a -> GenParser tok st () notFollowedBy' p= join $ do a <- try p; return (unexpected (show a))

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-18 Thread Andrew Pimlott
On Wed, Feb 18, 2004 at 02:45:15PM +0100, Daan Leijen wrote: > On Wed, 18 Feb 2004 01:11:31 -0500, Andrew Pimlott <[EMAIL PROTECTED]> > wrote: > >After some pondering and fiddling, a version I like: > > > >notFollowedBy' :: Show a => GenParser tok st a -> GenParser tok st () > >notFollowed

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-18 Thread Andrew Pimlott
On Wed, Feb 18, 2004 at 02:45:15PM +0100, Daan Leijen wrote: > On Wed, 18 Feb 2004 01:11:31 -0500, Andrew Pimlott <[EMAIL PROTECTED]> > wrote: > >After some pondering and fiddling, a version I like: > > > >notFollowedBy' :: Show a => GenParser tok st a -> GenParser tok st () > >notFollowed

Re: [Haskell] Parsec question: attempted 'notMatching' combinator

2004-02-18 Thread Christian Maeder
Hi, In a local copy of Parsec.Prim I've added a primitive, that may be of help for your problem as well. consumeNothing :: GenParser tok st () consumeNothing = Parser (\state -> Consumed (Ok () state (unknownError state))) With this I've implemented: checkWith :: (Show a) => GenParser tok st