"Regan Heath" <re...@netmail.co.nz> wrote in message news:op.vswbv8qj54x...@puck.auriga.bhead.co.uk... > On Wed, 23 Mar 2011 21:16:02 -0000, Jonathan M Davis <jmdavisp...@gmx.com> > wrote: >> There are tasks for which you need to be able to lex and parse D code. >> To 100% correctly remove unit tests would be one such task. > > Is that last bit true? You definitely need to be able to lex it, but > instead of actually parsing it you just count { and } and remove > 'unittest' plus { plus } plus everything in between right? >
No, to do it 100% reliably, you do need lexing/parsing, and also the semantics stage. Example: string makeATest(string str) { return "unit"~"test { "~str~" }"; } mixin(makeATest(q{ // Do tests }));