views:

236

answers:

5

I write couple of "assert(...)" in code, to make sure that pre- and post-conditions should be satisfied. We can tell the Delphi compiler, whether to compile with assertions in a debug version and without assertions in a release version.

I would like to know, if it is possible, to highlight "assert" like other Pascal keywords?

A: 

I don't think so. Under Tools -> Options -> Editor Options -> Source Options, you can turn syntax highlighting on or off, but there's no option I can see that lets you define what syntax to highlight.

Mason Wheeler
+2  A: 

No. Delphi's highlighter is not configurable like that. You can configure the color of keywords, but you cannot configure what words count as keywords.

If you meant this question as a feature request, then please submit it to Embarcadero's Quality Central. Stack Overflow is not the venue for that.

Since you're checking preconditions and postconditions, your assertions should be pretty easy to find even without highlighting: They'll be the first and last statements in any function.

Rob Kennedy
I submitted precisely this request years ago. QC is a black hole for such things: QC # 20639. It was closed as "resolved" and marked for retesting but nothing appears to have changed. And Emborcaderogearprise wonder why people don't bother using QC....
Deltics
+3  A: 

Actually Assert is not a reserved word.
You can create your own Assert procedure or function and even though it's not recommended, it will compile.
Therefore no highlighting is possible with Assert.

François
+2  A: 

I always type the exit function in CAPITALS to make it stand out. you could try the same with assert.

Mike Sutton
+3  A: 

Assert, like many other seemingly "reserved words" are actually what are called "standard functions"

Exit, Break, Continue, and Assert are examples of symbols that are not reserved by the compiler, but rather exist as symbols within the "System" unit namespace. The reason is that Delphi (or more specifically Turbo Pascal) originally didn't have the notion of Exit, Break, Continue or Assert. Many existing users may have already used those identifiers for their own libraries. Had we made these identifiers reserved words, we'd have broken many existing applications. By creating them as "standard functions" and "scoping" them to the System unit, we could provide the added functionality without the risk of breaking existing code. In some library that has, say, its own Exit function, the program's use of that identifier would not be affected. However if the programmer explicitly wanted to use the Exit standard function, you can fully qualify the identifier like this "System.Exit" and the compiler will generate code to exit the current function rather than calling the Exit that is closer in scope.

Allen Bauer
maybe it would be great, if next Delphi can add more flexibility in code highlighting.
stanleyxu2005
You explain why ASSERT() isn't treated as a keyword by the *compiler* but this is not a reason why it, and the similar flow control statements, could not be handled as a separate case by the *highlighter*. The simple answer to "is it possible to treat these statements as *if* they were reserved words by the syntax highlighter" is "yes" and you could make it so very easily. Your answer is therefore wrong because it conflates the behaviour of the highlighter with the behaviour of the compiler.
Deltics