[Haskell-cafe] Missing join and split

Evan Laforge qdunkan at gmail.com
Mon Dec 31 01:07:00 EST 2007


> > Parser combinators basically provide generalized regexes, and they all
> > take lists of arbitrary tokens rather than just Chars.  I've written a
> > simple combinator library before that dispenses with all the monadic
> > goodness in favor of a group combinator and returning [Either [tok]
> > [tok]], which sort of gives parsers a simpler regexy flavor (Left is
> > "out of group chunk" and Right is "in group chunk").
> >
> > foo (match (group any `sepBy` char ';') -> [c1, c2, c3]) = ...
>
> Ah. Is this accessible somewhere?

Unfortunately it's just a toy since it uses the inefficient naive
parser combinator thing.  I wrote it while reading one of those
pre-monadic parser combinator papers.  A better version could wrap
parsec or ReadP (which unfortunately doesn't seem to be parameterized
on the token type).  Anyway, in case you're still interested:

http://ofb.net/~elaforge/hs/group_parse.hs

Excuse the poor quality, it was a long time ago.  At the time I was
thinking of a regex->parser combinator compiler, with the catch being
that you can extend the regex language to include your own parsers,
like:

let env = [("num", number_in_range 0 255), ("dotted", many1 letter
`sepBy` char '.')]
    p = from_regex env "<num>, +<num>: (<dotted>)"
in parse p input

You could even have a magic character that makes them be postfix
operators, and include combinators:, like "[a-z]<:comma_sep>", but
you're probably better off writing a real parser here.


More information about the Haskell-Cafe mailing list