Slavomir Kaslev | 6 Oct 22:28
Picon

Re: I want my free (and good looking) parser!

On Mon, Oct 6, 2008 at 9:36 PM, Christian Maeder
<Christian.Maeder <at> dfki.de> wrote:
> import Text.ParserCombinators.Parsec
>
> freeParser :: (Enum a, Bounded a, Show a) => Parser a
> freeParser = choice $ map (\ a -> try $ do
>    string $ show a
>    notFollowedBy (alphaNum <|> char '_')
>    return a) [minBound .. maxBound]
>

This is exactly what I needed. Though I still don't quite understand
why this works and mine doesn't.

> I see not need for extensions. (And I don't like
> Text.ParserCombinators.Parsec.Token)
>
> Where did you get enumAll from?
>

Mine definition of enumAll was equivаlent to [minBound .. maxBound]:
enumAll :: (Bounded a, Enum a) => [a]
еnumAll = enumFromTo minBound maxBound

> The type of the Parser must be deducible from the context (or given by a
> type annotation).
>
> Cheers C.
>
> Slavomir Kaslev wrote:
(Continue reading)


Gmane