Add ELSEIF compiler directive

Issue #127 new
Christian-W. Budde created an issue

I wonder how much work it is to support the ELSEIF compiler directive. This would improve taking care for various exclusive defines. For example:

{$IF DEFINED('ChoiceA')}
  // do something
{$ELSEIF DEFINED('ChoiceB')}
  // do something
{$ELSEIF DEFINED('ChoiceC')}
  // do something
{$ENDIF}

The above is just an example for compile time support of an exclusive switch. In this case it's always either ChoiceA or ChoiceB or ...

Without such a compiler directive the code gets either unaccurate:

{$IF DEFINED('ChoiceA')}
  // do something
{$ENDIF}
{$IF DEFINED('ChoiceB')}
  // do something
{$ENDIF}
{$IF DEFINED('ChoiceC')}
  // do something
{$ENDIF}

or rather ugly:

{$IF DEFINED('ChoiceA')}
  // do something
{$ELSE}
{$IF DEFINED('ChoiceB')}
  // do something
{$ELSE}
{$IF DEFINED('ChoiceC')}
  // do something
{$ENDIF}
{$ENDIF}
{$ENDIF}

It's not high priority, but since this is quite independent, it might be quite easy to add.

Comments (2)

  1. Eric Grange repo owner

    Had a quick try with the code below, it's a bit tricky than I first thought, and some more tests with nested conditionals and cascading ELSEIF would probably be warranted before an implementation can be trusted.

    var abc : String;
    
    {$IF Declared('abc')}
    PrintLn('abc declared');
    {$ELSEIF Declared('xyz')}
    PrintLn('bug 1');
    {$ELSE}
    PrintLn('bug 2');
    {$ENDIF}
    
    {$IF Declared('xyz')}
    PrintLn('bug 3');
    {$ELSEIF Declared('abc')}
    PrintLn('abc declared indeed');
    {$ELSE}
    PrintLn('bug 4');
    {$ENDIF}
    
    {$IF Declared('xyz')}
    PrintLn('bug 5');
    {$ELSEIF not Declared('abc')}
    PrintLn('bug 6');
    {$ELSE}
    PrintLn('ok');
    {$ENDIF}
    
  2. Log in to comment