KCL: If-else expressions (#4022)

Closes https://github.com/KittyCAD/modeling-app/issues/3677

You can review each commit separately, they're neat commits with logical purpose in each.

Future enhancements:

- https://github.com/KittyCAD/modeling-app/issues/4015
- https://github.com/KittyCAD/modeling-app/issues/4020
- Right now the parser errors are not very good, especially if you forget to put an expression in the end of an if/else block
This commit is contained in:
Adam Chalmers
2024-09-30 15:40:50 -05:00
committed by GitHub
parent 6dfadbea18
commit 125207f60c
12 changed files with 897 additions and 22 deletions

View File

@ -0,0 +1,28 @@
// This tests evaluating if-else expressions.
let a = if true {
3
} else if true {
4
} else {
5
}
assertEqual(a, 3, 0.001, "the 'if' branch gets returned")
let b = if false {
3
} else if true {
4
} else {
5
}
assertEqual(b, 4, 0.001, "the 'else if' branch gets returned")
let c = if false {
3
} else if false {
4
} else {
5
}
assertEqual(c, 5, 0.001, "the 'else' branch gets returned")

View File

@ -0,0 +1,5 @@
let x = if true {
let y = 1
} else {
let z = 1
}

View File

@ -90,4 +90,9 @@ gen_test_fail!(
"semantic: cannot use % outside a pipe expression"
);
gen_test!(sketch_in_object);
gen_test!(if_else);
// gen_test_fail!(
// if_else_no_expr,
// "syntax: blocks inside an if/else expression must end in an expression"
// );
gen_test!(add_lots);