On Fri, 28 Sep 2012 06:03:41 +0200, Bernard Helyer <b.hel...@gmail.com>
wrote:
By the time the compiler even has a concept of an 'if statement'
or a 'block' the whitespace is long gone. Not to say you
couldn't change the lexing model to detect such things,
but it's not a simple as you make it sound.
Not so with my compiler implementation. It would be trivial to add such a
check to the Parser. A newline is its own (whitespace) Token, so it would
simply require looking for two consecutive newline tokens, in order to
give an error or a warning for that case. However, including such special
checks would quickly bloat the Parser code and make it difficult to read.
A better solution would be a class which traverses the parse tree and
implements the checks in its methods. Another more complex way to do this
is to design a querying language (similar to XPath) which returns a set of
Nodes according to a query string, on which you can perform arbitrary
checks.
--
My D Compiler: http://code.google.com/p/dil