Last week while I was playing around with ManaMana’s self-testing capability, I came across a problem where I needed the RDSL syntax to allow for preformatted blocks in requirements such as the following:
* A Wiki page displays the following text ``` Dear World, Hello! ``` when it is newly generated.
Modifying the RDSL lexer to recognize the preformatted blocks was the easy part. The problem after that was how do I strip whitespace in the requirements while preserving it inside the preformatted blocks? Initially, I thought about the following process:
I was not convinced. I’m glad I didn’t settle for it because then I discovered this solution.
Here’s the final code.
Going off on a bit of a tangent here, but I’m not sure though if this is the best way to process preformatted blocks because, with this method, they are not first-class tokens and, thus, not recognized by the parser. Having the parser recognize them would probably be nice as it allows for syntax checking. I haven’t thought this one through as much as I think I should though. We’ll see.