Hi, all! I used to work in Pascal (Delphi/fpc) for 10 years, and later had to go to C++ (because of my day job). Now, I'm back to fpc, and one thing I really miss is ability to have semicolon before else.
So, here's (attached) patch for fpc that makes it possible. The only problematic place for this syntax change is inside case statement, when last branch is single if statement, for example: case p of '1': do_1; '2' if (q > 0) then do_2; else do_3; end; It is not clear if else should be part of branch '2' (part of if statement), or else branch for case. Fortunately, there is also 'otherwise' (I bet only few out there know about it, I've discovered it this night!) which can be used instead of else inside case, which can be used to clarify intent, so that default behavior could be to interpret else as part of if statement. Note that attached patch has lots of bad points: - besides compiling fpc itself with this change (and changing some else-s to otherwise-s), as well as some of my projects, I haven't officially tested it - from design point of view, it's very 'dirty' (I mess with scanner internal state from statement parser - ouch, that hurts!) - because of possible problems, else as part of case should be deprecated, or discouraged, or there should at least be warning if last branch before else is single if statement - this patch only applies to else branch of if statement, not one inside case (because, as stated before, you can use keyword 'otherwise' inside case) - I'm pretty sure there are still some else-s inside case-s inside compiler/rtl/fcl which introduce bugs, I just didn't hit those places; the proper solution here is to either add begin/end, or change code to use 'otherwise' Anyway, as far as I can see - it works! Hope someone will find it useful. Or not :-) Regards, Aleksa
semicolon_before_else.patch
Description: Binary data
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel