[Haskell-cafe] Parsing unordered parameter list with Parsec

Stefan O'Rear stefanor at cox.net
Thu Apr 5 11:12:47 EDT 2007

On Thu, Apr 05, 2007 at 03:50:26PM +0100, Will Newton wrote:
> Hi all,
> I'm new to Haskell and trying to do some parsing with Parsec. It's
> been extremely good so far. I have run into a problem I can't seem to
> see the solution to though. I hope someone on the list can help me
> out!
> I have a command with a parameter list like this:
> CMD PARAM1 foo PARAM2 100 PARAM3 200
> Which is easy enough to parse, but it turns out the grammar is not
> particularly well defined, and it's considered acceptable to swap
> parameter order round pretty much arbitrarily. Is there a simple way
> to handle this? I would like to only allow one of each parameter, some
> parameters may also be optional.
> It feels like I might have to write my own combinator to do this but
> I'm not sure I'm quite ready of that yet!

Sounds like you want Parsec's "permutation phrases" function:



More information about the Haskell-Cafe mailing list