1 of 4
Wheat Wizard
• 77.6k
• 18
• 237
• 513

{-{--}---}main=putStr"Hello, world!"


Try it online!

Test sloc

Since sloc is regex based it is a very good guess to think it cannot identify nested comments. And if we take a look we see that indeed it cannot. If we nest two comments like this sloc identifies it like so

      code
^^
{-{--}-}
^^^^^^
comment


However this has the opposite of the intended effect. We want sloc to think our code is a comment rather than our comment is code. So we add a "line comment marker" to the part of the comment sloc thinks is code, so that sloc thinks a line comment is being started.

{-{--}-}---}


So to sloc there are two comments the block comment {-{--} and the line comment ---} but to haskell which actually parses comments, it is all one block comment.

So then we just add our code after. Sloc thinks this is still a comment and Haskell knows it is not.

Wheat Wizard
• 77.6k
• 18
• 237
• 513