Generating random WebIDL fragments from grammar

Hi,

As a way to test both my WebIDL parser [1] and the WebIDL grammar, I've
been looking at generating random but valid fragments from the WebIDL
grammar.

To that end, I've been using abnfgen:
http://www.quut.com/abnfgen/

Since abnfgen only takes ABNF as input, I've written a quick and dirty
script (attached) that converts the grammar as defined in the WebIDL
spec (when copied and pasted in a text file) into an ABNF grammar.

It does mostly syntax conversion from one grammar to the other, although
it also does a few tweaks in order to generate more useful test cases. 

The grammar that it currently generates is buggy, because the grammar in
the WebIDL spec is buggy; attached is a ABNF grammar that more closely
matches what I think WebIDL intends.

Using that grammar, I can generate a bunch of random WebIDL fragments,
e.g. with:
        for i in `seq 1 150` ; do abnfgen webidl.bnf > test$i.idl ; done
which I then run against my parser:
        for i in *.idl ;do widlproc $i 1>/dev/null ; done

This has proved pretty useful in finding bugs in my implementation, as
well as bugs in the grammar, so I thought I would share it.

(I've already modified a number of test cases in the widlproc repository
as a result of this work)

Dom

1. https://github.com/dontcallmedom/widlproc

Received on Friday, 21 December 2012 17:38:49 UTC