The most practical thing seemed to be a little text-based scripting language. Armed with a small amount of experience using Selenium to test web applications and a Selenium reference guide, the plan was:
Invent a little bit of syntax.
Write a parser for it.
See if it works.
Repeat until done.
Invisible XML fits perfectly here:
Writing parsers in iXML is easy.
My processor already supports Invisible XML, so parsing the users script with iXML is easy.
The output of a parse is an XML document.
In an XProc implementation, writing an interpreter for some XML is easy.
Here’s how it started:
script version 0.2 . page "http://example.com" .
We start with a version, so we can adapt as it evolves, and then we know we’re going to want to load a page. Next, we write a little bit of iXML to parse it:
ixml version "1.1-nineml" . script = versionDecl, s, page, s . -versionDecl = s, -"script version ", version, s, -"." . @version = "0.2" . @page = -"page", RS, string, s, -"." .
(I’m eliding a few more lines of grammar needed to parse strings and whitespace. I probably didn’t write them for this purpose anyway, I probably copied them from some other grammar.)
Now we just add some more syntax, then some more iXML, and “repeat until done.”
It finished as 130ish lines of iXML. It took a few evenings, but the resulting language supports a healthy subset of the Selenium API, three kinds of conditional blocks, subroutines, variables, and XPath expressions.
(It is in many respects a very sloppy language with side effects and minimal static checking. But it’s a proof-of-concept as much as anything.)