[Haskell-cafe] How do you test a parser?
kcharter at gmail.com
Sat Jun 11 20:44:04 CEST 2011
On Sat, Jun 11, 2011 at 7:10 AM, Andrew Coppin
<andrewcoppin at btinternet.com>wrote:
> If you have a function that turns a parse tree back into text again, you
> can try verifying that a round-trip is the identity function. Except perhaps
> sometimes it isn't. Perhaps a given expression has more than one equivalent
> representation. A round-trip from string and back again is even less likely
> to be stable.
I find that this kind of testing works quite nicely in practice with
QuickCheck, in the sense that it does a good job of finding bugs in both the
unparser and the parser. It's possible, but unlikely, that you'll have a bug
in the parser and a bug in the unparser that cancel one another out.
Generate the ASTs; parse . unparse ought to be id, or perhaps t = t . parse
. unparse for some simple transformation 't'. For example, if the parser
annotates AST nodes with source positions, you may need 't' to strip them
kevin.charter at acm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe