[Lazarus] Syntax highlighting anomalies

Sven Barth pascaldragon at googlemail.com
Fri Oct 8 20:39:27 CEST 2010


On 08.10.2010 20:23, Bernd Kreuss wrote:
> Hi,
>
> is it only me ore are there others who find the following behaviors of
> the pascal syntax highlighter in lazarus strange and inconsistent and
> sometimes even annoying?
>
> * some types (String and AnsiString)  are highlighted, all other types
> (built in or not) are not highlighted. IMHO no type names should be
> highlighted.

This is historical. Delphi did it, so we are doing it, too (btw: to keep 
it consistent UnicodeString should be highlighted, too ^^). Might be 
related to the fact that the highlighter (SynEdit) was an original 
Delphi project thus it inherited this behavior.

>
> * all reserved words for control flow (for, to, if, then, do, else,
> repeat, until, while, begin, end, try, except, finally, raise, goto) are
> highlighted, the only ones that are not highlighted are break, continue
> and exit. IMHO all such reserved words that describe the program
> structure should be highlighted. For example break and exit are of the
> same caliber as raise (or even goto) and also used for similar design
> patterns, I don't see why they should be treated differently.

Reserved words are highlighted. The ones you listed are all reserved 
words and it's not possible to use them as identifiers (without escaping 
them with "&"). But "break", "continue" and "exit" aren't reserved 
keywords. You can even use them as identifiers (I did it once and 
wondered later on why "exit" isn't working ^^).

Also there are some "context sensitive" reserved words like "index" and 
"message".
The first one is used in properties, but it can be used as a normal 
identifier as well. E.g. "property Foo[Index: Integer]: Bar" here index 
will be highlighted, but it only should be highlighted if it is used as 
"property Bar index 39 GetBar;". It won't be highlighted outside of a class.
"message" is used for the message dispatching system in Object Pascal 
(procedure Foo(aMsg: TMsgStruct); message Bar;), but it is highlighted 
everywhere and can be used as an identifier everywhere.
Those two are indeed a bit annoying. ^^

>
> I have tried to think about it long and hard but I cannot find any
> reason that would justify these anomalies other than maybe some
> historical reasons. For example a (hypothetical) reason that string is
> internally working in a different way than a Double or an Integer IMHO
> does not justify any different syntax highlighting, they all still
> belong into the same *category*: they appear in var declarations as type
> names and are used like type names everywhere no different than any
> other type name, so they consequently should look like type names and
> not like language keywords.

I don't know why Borland chose to highlight ShortString, AnsiString and 
String (WideString is only highlighted by Lazarus), but normal reserved 
keywords and normal non reserved identifiers are clear. The only 
troubles make hybrids like "index" and "message".

Regards,
Sven




More information about the Lazarus mailing list