Recent

Author Topic: $ifdef highlighting  (Read 1267 times)

440bx

  • Hero Member
  • *****
  • Posts: 6025
$ifdef highlighting
« on: December 05, 2025, 04:15:27 am »
Hello,

Normally, when code is in a {$ifdef <something>} <some code here> {$endif} the highlighting intensity of <some code here> changes depending on whether of not <something> is defined.

when using {$ifdef 0} <some code here> {$endif} the <some code here> is highlighted as if 0 is defined, which it isn't (0 is not an identifier that can be defined.)

IOW, whatever is between {$ifdef 0} and {$endif} should probably be in low intensity to indicate it is not "active" instead of high intensity (which normally indicates code the compiler will compile.)

comments welcome.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18699
  • To Europe: simply sell USA bonds: dollar collapses
Re: $ifdef highlighting
« Reply #1 on: December 05, 2025, 07:04:23 am »
Do you mean {$IF 0} // which starts a comment
{$ifdef 0} does nothing.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Khrys

  • Sr. Member
  • ****
  • Posts: 381
Re: $ifdef highlighting
« Reply #2 on: December 05, 2025, 07:06:07 am »
I think it makes sense to treat  {$ifdef 0} / {$if 0}  as a special type of comment that allows for comment nesting without involving any strange compiler switches  ;)

Thaddy

  • Hero Member
  • *****
  • Posts: 18699
  • To Europe: simply sell USA bonds: dollar collapses
Re: $ifdef highlighting
« Reply #3 on: December 05, 2025, 07:12:57 am »
Yes it makes sense since you can define 0
Code: Pascal  [Select][+][-]
  1. begin
  2. {$define 0}
  3. {$ifdef 0}
  4.   writeln('test1');
  5. {$endif}
  6. {$if 0}
  7.   writeln('test2'); // never reached...
  8. {$endif}
  9. end.
The two have completely different meaning......

This is also not a bug, but intentional.
« Last Edit: December 05, 2025, 07:19:46 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

440bx

  • Hero Member
  • *****
  • Posts: 6025
Re: $ifdef highlighting
« Reply #4 on: December 05, 2025, 07:34:53 am »
this isn't about whether 0 is defined or not.  It is about the highlighting.

whether 0 is defined or not the highlighting stays the same and, it shouldn't.  When defined what is in its domain should be bright otherwise it should be dim.  That's what happens with normal identifiers but does not happen with numerals (no reason why it shouldn't.)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18699
  • To Europe: simply sell USA bonds: dollar collapses
Re: $ifdef highlighting
« Reply #5 on: December 05, 2025, 07:45:10 am »
That is a shortcoming in the Lazarus IDE that does not handle {$if 0} correct. It is not treated as a comment.
It does handle {$define 0}{$ifdef 0} correct. (As 0 is just like any other identifier as far as {$ifdef} is concerned.)
« Last Edit: December 05, 2025, 07:55:50 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

440bx

  • Hero Member
  • *****
  • Posts: 6025
Re: $ifdef highlighting
« Reply #6 on: December 05, 2025, 08:25:10 am »
again: it's about the highlighting, nothing else.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18699
  • To Europe: simply sell USA bonds: dollar collapses
Re: $ifdef highlighting
« Reply #7 on: December 05, 2025, 08:33:12 am »
This was about the highlighting...nothing else. The observation you made is just releated to the highligthing of {$if 0} style comments. It does not affect code, only display is not correct.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12021
  • Debugger - SynEdit - and more
    • wiki
Re: $ifdef highlighting
« Reply #8 on: December 05, 2025, 11:26:52 am »
The $IF and $IFDEF conditions are evaluated by codetools.

There are a few that codetools currently doesn't handle.

If 0 is one of them, the report it as an issue.  Actually for IFDEF that seems to be any numeric constant?

440bx

  • Hero Member
  • *****
  • Posts: 6025
Re: $ifdef highlighting
« Reply #9 on: December 05, 2025, 05:38:11 pm »
The $IF and $IFDEF conditions are evaluated by codetools.

There are a few that codetools currently doesn't handle.

If 0 is one of them, the report it as an issue.  Actually for IFDEF that seems to be any numeric constant?
That makes sense and, yes, the problem occurs for any numeric constant.

ETA:

reported.

Link   : https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41944
Ticket:41944

« Last Edit: December 05, 2025, 05:47:27 pm by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18699
  • To Europe: simply sell USA bonds: dollar collapses
Re: $ifdef highlighting
« Reply #10 on: December 06, 2025, 07:26:54 pm »
There is nothing that I did not explained: all of this is intentional and documented. Maybe that the docs can be made clearer.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

paweld

  • Hero Member
  • *****
  • Posts: 1561
Re: $ifdef highlighting
« Reply #11 on: December 07, 2025, 08:49:14 am »
@Thaddy: @440bx is right, for identifiers that are numbers, the highlighting does not work properly, regardless of whether the identifier is defined or not - see the attached screenshot.
Best regards / Pozdrawiam
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 18699
  • To Europe: simply sell USA bonds: dollar collapses
Re: $ifdef highlighting
« Reply #12 on: December 07, 2025, 12:44:58 pm »
Yes, I never wrote otherwise, but the bug report by martin
« Last Edit: December 07, 2025, 12:51:59 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Thaddy

  • Hero Member
  • *****
  • Posts: 18699
  • To Europe: simply sell USA bonds: dollar collapses
Re: $ifdef highlighting
« Reply #13 on: December 07, 2025, 12:59:03 pm »
The "problem" with {$ifdef} is that everything that comes after a legal identifier string consisting of the  ' _', 0..9,'A..Z','a..z' is treated as a comment, so {$ifdef 5+1=true} resolves to 5 because +1=true is a comment.
The string is cut off at the first character or symbol that is not in that set.
In this case +.
OTOH {$if 5+1=6} resolves to true because {$if} allows expressions.
And there is where the whole discussion went wrong.
All this is documented. The compiler handles the options correctly but codetools doesn't.

Codetools should parse  ' _', 0..9,'A..Z','a..z' correctly, which is basically the set for any valid pascal identifier char except the escape char &
« Last Edit: December 07, 2025, 01:37:13 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

paweld

  • Hero Member
  • *****
  • Posts: 1561
Re: $ifdef highlighting
« Reply #14 on: December 07, 2025, 02:47:30 pm »
Quote from: Thaddy
The compiler handles the options correctly but codetools doesn't.

@440bx didn't mention the compiler at all; his report has been about highlighting in the editor from the very beginning.
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018