diff --git a/builtins/Float.roc b/builtins/Float.roc index 10289bac9d..1761ecb347 100644 --- a/builtins/Float.roc +++ b/builtins/Float.roc @@ -69,7 +69,7 @@ interface Float #round : Float -> Int round = \num -> - case num when + case num is 0.0 -> 0 _ -> 1 @@ -110,7 +110,7 @@ round = \num -> ## >>> |> Float.div 2.0 #div : Float, Float -> Result Float DivByZero div = \numerator, denominator -> - case numerator when + case numerator is 0.0 -> 0.0 # TODO return Result! _ -> denominator diff --git a/src/fmt/expr.rs b/src/fmt/expr.rs index 0e70780138..526f35c3b3 100644 --- a/src/fmt/expr.rs +++ b/src/fmt/expr.rs @@ -133,9 +133,10 @@ pub fn fmt_expr<'a>( fmt_if(buf, loc_condition, loc_then, loc_else, indent); } Case(loc_condition, branches) => { - buf.push_str("case "); + buf.push_str("\ + case "); fmt_expr(buf, &loc_condition.value, indent, false, true); - buf.push_str(" when\n"); + buf.push_str(" is\n"); let mut it = branches.iter().peekable(); while let Some((pattern, expr)) = it.next() { diff --git a/src/parse/keyword.rs b/src/parse/keyword.rs index f856cee785..d18d9b2db2 100644 --- a/src/parse/keyword.rs +++ b/src/parse/keyword.rs @@ -4,3 +4,4 @@ pub static ELSE: &str = "else"; pub static CASE: &str = "case"; pub static WHEN: &str = "when"; pub static AS: &str = "as"; +pub static IS: &str = "is"; \ No newline at end of file diff --git a/src/parse/mod.rs b/src/parse/mod.rs index d5fadc4cb0..21aef45c2b 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -636,6 +636,7 @@ fn reserved_keyword<'a>() -> impl Parser<'a, ()> { string(keyword::ELSE), string(keyword::CASE), string(keyword::WHEN), + string(keyword::IS), string(keyword::AS) ) } @@ -778,13 +779,13 @@ pub fn case_expr<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> { loc!(move |arena, state| parse_expr(min_indent, arena, state)), min_indent, ), - string(keyword::WHEN) + string(keyword::IS) ) ) ), move |arena, state, (case_indent, loc_condition)| { if case_indent < min_indent { - panic!("TODO case wasns't indented enough"); + panic!("TODO case wasn't indented enough"); } // Everything in the branches must be indented at least as much as the case itself. diff --git a/tests/test_canonicalize.rs b/tests/test_canonicalize.rs index e19f94704b..0e60687216 100644 --- a/tests/test_canonicalize.rs +++ b/tests/test_canonicalize.rs @@ -249,17 +249,17 @@ mod test_canonicalize { let src = indoc!( r#" g = \x -> - case x when + case x is 0 -> 0 _ -> g (x - 1) h = \x -> - case x when + case x is 0 -> 0 _ -> g (x - 1) p = \x -> - case x when + case x is 0 -> 0 1 -> g (x - 1) _ -> p (x - 1) @@ -288,7 +288,7 @@ mod test_canonicalize { let src = indoc!( r#" g = \x -> - case x when + case x is 0 -> 0 _ -> g (x + 1) @@ -327,7 +327,7 @@ mod test_canonicalize { let src = indoc!( r#" q = \x -> - case q x when + case q x is _ -> 0 0 @@ -348,12 +348,12 @@ mod test_canonicalize { let src = indoc!( r#" q = \x -> - case x when + case x is 0 -> 0 _ -> p (x - 1) p = \x -> - case x when + case x is 0 -> 0 _ -> q (x - 1) diff --git a/tests/test_eval.rs b/tests/test_eval.rs index 2e8f32e5da..752d9e791c 100644 --- a/tests/test_eval.rs +++ b/tests/test_eval.rs @@ -87,7 +87,7 @@ mod test_gen { assert_evals_to!( indoc!( r#" - case 1 when + case 1 is 1 -> 12 _ -> 34 "# @@ -102,7 +102,7 @@ mod test_gen { assert_evals_to!( indoc!( r#" - case 2 when + case 2 is 1 -> 63 _ -> 48 "# diff --git a/tests/test_format.rs b/tests/test_format.rs index abc5504eb8..29a89cd7ca 100644 --- a/tests/test_format.rs +++ b/tests/test_format.rs @@ -695,7 +695,7 @@ mod test_format { fn integer_case() { expr_formats_same(indoc!( r#" - case b when + case b is 1 -> 1 @@ -710,7 +710,7 @@ mod test_format { expr_formats_to( indoc!( r#" - case year when + case year is 1999 -> @@ -725,7 +725,7 @@ mod test_format { ), indoc!( r#" - case year when + case year is 1999 -> 1 @@ -740,7 +740,7 @@ mod test_format { fn case_with_comments() { expr_formats_same(indoc!( r#" - case b when + case b is # look at cases 1 -> # case 1 @@ -761,9 +761,9 @@ mod test_format { fn nested_case() { expr_formats_same(indoc!( r#" - case b when + case b is _ -> - case c when + case c is _ -> 1 "# @@ -775,7 +775,7 @@ mod test_format { expr_formats_to( indoc!( r#" - case b when + case b is 1 -> 1 # case 1 @@ -786,7 +786,7 @@ mod test_format { ), indoc!( r#" - case b when + case b is 1 -> 1 diff --git a/tests/test_infer.rs b/tests/test_infer.rs index cdd4a733e2..43220c57e9 100644 --- a/tests/test_infer.rs +++ b/tests/test_infer.rs @@ -833,7 +833,7 @@ mod test_infer { infer_eq( indoc!( r#" - case 1 when + case 1 is 1 -> 2 3 -> 4 "# diff --git a/tests/test_parse.rs b/tests/test_parse.rs index 3784c39956..4e67a7e037 100644 --- a/tests/test_parse.rs +++ b/tests/test_parse.rs @@ -1322,7 +1322,7 @@ mod test_parse { &arena, indoc!( r#" - case x when + case x is "blah" -> 1 "mise" -> 2 "# @@ -1356,7 +1356,7 @@ mod test_parse { &arena, indoc!( r#" - case x when + case x is 1 -> 2 3 -> 4 "# @@ -1396,7 +1396,7 @@ mod test_parse { &arena, indoc!( r#" - case x when + case x is { y } -> 2 { z, w } -> 4 "# diff --git a/tests/test_uniqueness_infer.rs b/tests/test_uniqueness_infer.rs index 316b3762d9..826c4b3f33 100644 --- a/tests/test_uniqueness_infer.rs +++ b/tests/test_uniqueness_infer.rs @@ -863,7 +863,7 @@ mod test_infer_uniq { infer_eq( indoc!( r#" - case 1 when + case 1 is 1 -> 2 3 -> 4 "#