[Haskell-cafe] Re: Parsec question

Erik de Castro Lopo mle+cl at mega-nerd.com
Tue Dec 23 19:14:57 EST 2008


Toby Hutton wrote:

> One of the tricks I found early on is to understand where to use 'try'
> (since by default input is consumed even if a parser fails) but apart
> from that just read Daan's page, even though it's out of date, and
> look at how all these cool combinators work.
> 
> http://legacy.cs.uu.nl/daan/download/parsec/parsec.html

Ah yes, reading that document and using 'try' is a good tip. This
is what I cam up with:

    qualifiedIdentStar :: CharParser st [ String ]
    qualifiedIdentStar = do
            try identDotStar
        <|> qualifiedIdentifier
        where
        identDotStar = do
            s <- sepEndBy1 identifier dot
            char '*'
            return (s ++ [ "*" ])


Cheers,
Erik

-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"It has been discovered that C++ provides a remarkable facility
for concealing the trival details of a program -- such as where
its bugs are." -- David Keppel


More information about the Haskell-Cafe mailing list