[Haskell-cafe] Parsec to parse tree structures?

david fries djf at gmx.ch
Sun Mar 14 12:03:12 EDT 2010


Hello Café

Some time ago I wrote a parser for a project of one our customers. The
format was proprietary and binary. The data was structured as a tree
with tables pointing to sub tables farther in the file. (Well actually
there was one or two cases where branches joined together, so I guess it
was a directed graph.) Also it had no defined endianess, some tables
were bigendian others were little endian and some were in their very own
in-house-endianess. 
All in all, the typical binary data structure that has been in use and
continuously extended for the last 15 years. You know the kind.

Oddly enough, our customer never bothered to write a parser of their
own. I wonder why.

My parser was written in C# and wasn't particularly elegant, but it
worked reliably. I was wondering how you would parse tree-like
structures with Parsec (or other functional parsers)? Up to know, all
examples I've seen were of sequential data. To parse trees, you'd
essentially need to be able to follow pointers, parse whatever is there
and then jump back. I guess I'd have to mess around with the internal
state of the parser to do that, which is something I'd rather avoid.


regards,
dave 



More information about the Haskell-Cafe mailing list