Domain Specific Error Messages
Background
As defined by Fowler, an internal DSL uses a host language (e.g. Ruby, Groovy) and an external DSL uses a full-blown parser (e.g. ANTLR).
In the latest JNB article, Mark points out that internal DSLs must live within the syntax rules of the host language. This is fine if the audience is composed of software developers, but what if the domain is microbiology?
The following might not be clear:
if( specimen.isBlood && test.isAmpicillin ) {
test.doAlert
}
However, this is debatable: maybe it's ok. Maybe an internal DSL can whittle down its host syntax so that it is reasonable. Debate among yourselves.
The Universal Issue
There is one universal issue for both developers and microbiologists alike: we make typos. We can bend internal DSLs to look good, but what happens when we make a typo? Will the error message be meaningful for a microbiologist? Or would it reveal the host language with a dev-oriented message?
For example:
if( specimen.isBlood && test.isAmpicillin
test.doAlert
}
Now, what if one were to use ANTLR? Can we get a level of error reporting such as:
Could not understand the statement.
Possible cause is mismatched parentheses.
Please type '-help' for a language synopsis.
Please type '-samples' for quick examples.
What if the grammar were even simpler, such the following, but there is a semantic problem:
if specimen.isAmpicillin and test.isBlood
test.doAlert
Could we get a domain-specific error message such as:
Error: 'ampicillin' is not a specimen
Error: 'blood' is not a test
Check appropriate values for 'specimen' and 'test'
with '-values'.
I don't know the answer for either internal or external DSLs. For the latter, I'm going to this month's StL JUG to ask the question. See you there.
3 comments:
Thanks for the heads up! ;-)
Yes, ANTLR error messages can be customized. I almost certainly won't have time to cover this at the JUG meeting, but you can find information on it in the slides. See pages 83 to 85 at http://www.ociweb.com/mark/programming/ANTLR3/ANTLR3.pdf.
Very cool.. and a free PDF e-book for readers! :-) 89 pages
Btw, the end of this post was rushed. I had to go to work and the copy editor at CtJ HQ was on my case about deadlines.
I'm not really surprised that ANTLR can do such things: it is clearly the "heavy machinery" for parsing. Yet with all the DSL stuff on the blogs, one doesn't hear much about what happens when things go wrong.
Readers, come on out to the JUG to see much more on ANTLR.
Having spent a lot of time with JavaCC and a little with ANTLR, my experience has been that this is possible but definitely an under-estimated part of DSL development. Great question!!
Post a Comment