Is it possible to add "assert" as a keyword in Delphi?
I write couple of "assert(...)" in cod开发者_如何学Goe, 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?
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.
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.
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.
I always type the exit function in CAPITALS to make it stand out. you could try the same with assert.
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.
精彩评论