There is no invalid code. You can have a ";" in a define or not. I know macro parsing is difficult, but at least this should be possible
#define test1
#define test2 ;
test1 ;
test2
test2 ;
;;;;
#define begin {
#define nothing
#define empty ;
#define end }
begin
nothing
empty
end
begin ;
nothing ;
empty ;
end ;