10 Jun 2013 - Tomi Junnila
When I started out trying to use NCrunch, I was working on a project that needed to parse a domain-specific language created by someone else. To do the parsing, I was studying the use of ANTLR 3, which took me a while to learn and I wasn’t quite sure my grammar was correct, and that it would remain correct as I made small changes to it in order to accommodate some more obscure details in the language.
I decided simple unit tests to verify the parsing process would be a good idea – it would be simple to add new tests to verify each new language statement, and I’d easily know if I broke anything in the pre-existing parts. Sadly, however, NCrunch didn’t seem to work very well with ANTLR: after changing the obvious settings, NCrunch would still occasionally (but often) fail building the ANTLR project with a strange internal error from my grammar file:
System.InvalidCastException: Unable to cast object of type 'Antlr3.Targets.CSharp3Target' to type 'Antlr3.Codegen.Target'
Google didn’t find anything (probably not very many people use NCrunch and ANTLR), so I posted a question on the NCrunch forums, and got support very fast from the NCrunch developer, and we were able to find a way to make NCrunch able to build ANTLR projects: