Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- Added support for `if else` ternary expressions

## [0.7.0] - 2025-11-11

### Added
Expand Down
4 changes: 4 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Added support for `if else` ternary expressions

## 0.7.0 - 2025-11-11

### Added
Expand Down
20 changes: 20 additions & 0 deletions core/datatests/generators/logical_line_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn generate_test_files(root_dir: &Path) {
routine_implementations::generate(root_dir);
control_flows::generate(root_dir);
statements::generate(root_dir);
ternary::generate(root_dir);
attributes::generate(root_dir);
semicolons::generate(root_dir);
regression::generate(root_dir);
Expand Down Expand Up @@ -3258,6 +3259,25 @@ mod statements {
}
}

mod ternary {
use super::*;

pub fn generate(root_dir: &Path) {
generate_test_cases!(
root_dir,
assignment = "
_|A := if A then B else C;
",
nested = "
_|A := if if A then B else C then
if A then B else C
else
if A then B else C;
",
);
}
}

mod attributes {
use super::*;

Expand Down
144 changes: 139 additions & 5 deletions core/datatests/generators/optimising_line_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,31 @@ mod comments {
and FFFFFFFFFFFF then
;
",
ternary = "
A :=
if A then
B
else //
if C then D else E;
A :=
if A then
B
else //
if CCCCC then
D
else
E;
A :=
if A then
B
else //
if C then
DDDDD //
else if a then
E
else
d;
",
);
}
}
Expand Down Expand Up @@ -3013,16 +3038,16 @@ mod control_flows {
inline = "
if A then
else if AAAAAA and BBBBBB then
Bar;
Bar
else if AAAAAAAAA
and BBBBBBBBB then
Bar;
Bar
else if AAAAAAAAAA
and BBBBBBBBBB
and CCCCCCCCCC then
Bar;
Bar
else if Foo(AAA, BB, CCC) then
Bar;
Bar
else if Foo(
AAAA,
BBBBBB,
Expand Down Expand Up @@ -3052,7 +3077,7 @@ mod control_flows {
end
else if AA(A, B, C) then begin
Bar;
end;
end
else if AAA(AAA, BB, CCC) then
begin
Bar;
Expand Down Expand Up @@ -4238,6 +4263,7 @@ mod expressions {
unary::generate(root_dir);
set::generate(root_dir);
strings::generate(root_dir);
ternary::generate(root_dir);
}

mod boolean {
Expand Down Expand Up @@ -4859,6 +4885,114 @@ mod expressions {
);
}
}

mod ternary {
use super::*;

pub fn generate(root_dir: &Path) {
generate_test_cases!(
root_dir,
basic_assignment = "
A := if B then C else D;
AAAAAAAA :=
if B then C else D;
AAAAAAAA :=
if BBBBBBB then
CC
else
DD;
",
nested_must_wrap = "
// wrap_column=41 |
// A := if B then if C then D else E else F;
A :=
if B then
if C then D else E
else
F;
",
nested = "
A :=
if B then
if CCCCC then D else E
else
F;
A :=
if B then
if CCCCCC then
D
else
E
else
F;
A :=
if BBBBBBB + BBBBBBBB then
if CCCCCC + CCCCC then
DDDDDDDDDD + DDDDD
else
EEEEEEEEE + EEEEEE
else
FFFFFFFF + FFFFFFFFFF;
A :=
if BBBBBBBB
+ BBBBBBBB then
if CCCCC + CCCCCC then
DDDDDDDDDD + DDDDD
else
EEEEEEEEE + EEEEEE
else
FFFFFFFF + FFFFFFFFFF;
A :=
if BBBBBBB + BBBBBBBB then
if CCCCCCC
+ CCCCCCC then
DDDDDDDDDD + DDDDD
else
EEEEEEEEE + EEEEEE
else
FFFFFFFF + FFFFFFFFFF;
A :=
if BBBBBBB + BBBBBBBB then
if CCCCC + CCCCCC then
DDDDDDDDDD
+ DDDDDD
else
EEEEEEEEE + EEEEEE
else
FFFFFFFF + FFFFFFFFFF;
A :=
if BBBBBBB + BBBBBBBB then
if CCCCC + CCCCCC then
DDDDDDDDDD + DDDDD
else
EEEEEEEEE
+ EEEEEEE
else
FFFFFFFF + FFFFFFFFFF;
A :=
if BBBBBBB + BBBBBBBB then
if CCCCCC + CCCCC then
DDDDDDDDDD + DDDDD
else
EEEEEEEEE + EEEEEE
else
FFFFFFFFF
+ FFFFFFFFFF;
A :=
if BBBBBBBB
+ BBBBBBBB then
if CCCCCC
+ CCCCCC then
DDDDDDDDDD + DDDDD
else
EEEEEEEEE
+ EEEEEEE
else
FFFFFFFFF + FFFFFFFFF;
",
);
}
}
}

mod attributes {
Expand Down
Loading
Loading