Skip to content

Support new conditional operator (ternary) #273

@zaneduffield

Description

@zaneduffield

Delphi 13 added a new if-expression syntax similar to ?: from other languages (documentation).

Since this operator is intended for terse code, pasfmt should try to format such expressions inline as much as possible.

Examples of the (proposed) desired formatting include

A := if B then C else D;

Foo(if B then C else D);

if (if B then C else D) > 10 then
  Foo
else
  Bar;

In cases where a line break is forced, or it doesn't fit on one line, we should revert to the existing formatting for if-then-else statements, with continuations appropriate for the context:

A := //
    if B then
        C
    else
        D;

Foo( //
    if B then
        C
    else
        D;
);

if ( //
    if B then
        C
    else
        D)
    > 10 then
  Foo
else
  Bar;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions