Case is to when is

This commit is contained in:
Chad Stearns 2019-12-23 17:17:04 -05:00
parent 9a5b6a03b4
commit 62a004c103
9 changed files with 29 additions and 29 deletions

View file

@ -69,7 +69,7 @@ interface Float
#round : Float -> Int #round : Float -> Int
round = \num -> round = \num ->
case num is when num is
0.0 -> 0 0.0 -> 0
_ -> 1 _ -> 1
@ -110,7 +110,7 @@ round = \num ->
## >>> |> Float.div 2.0 ## >>> |> Float.div 2.0
#div : Float, Float -> Result Float DivByZero #div : Float, Float -> Result Float DivByZero
div = \numerator, denominator -> div = \numerator, denominator ->
case numerator is when numerator is
0.0 -> 0.0 # TODO return Result! 0.0 -> 0.0 # TODO return Result!
_ -> denominator _ -> denominator

View file

@ -134,7 +134,7 @@ pub fn fmt_expr<'a>(
} }
Case(loc_condition, branches) => { Case(loc_condition, branches) => {
buf.push_str("\ buf.push_str("\
case "); when ");
fmt_expr(buf, &loc_condition.value, indent, false, true); fmt_expr(buf, &loc_condition.value, indent, false, true);
buf.push_str(" is\n"); buf.push_str(" is\n");

View file

@ -1139,7 +1139,7 @@ pub fn colon_with_indent<'a>() -> impl Parser<'a, u16> {
pub fn case_with_indent<'a>() -> impl Parser<'a, u16> { pub fn case_with_indent<'a>() -> impl Parser<'a, u16> {
move |arena, state: State<'a>| { move |arena, state: State<'a>| {
string(keyword::CASE) string(keyword::WHEN)
.parse(arena, state) .parse(arena, state)
.map(|((), state)| (state.indent_col, state)) .map(|((), state)| (state.indent_col, state))
} }

View file

@ -249,17 +249,17 @@ mod test_canonicalize {
let src = indoc!( let src = indoc!(
r#" r#"
g = \x -> g = \x ->
case x is when x is
0 -> 0 0 -> 0
_ -> g (x - 1) _ -> g (x - 1)
h = \x -> h = \x ->
case x is when x is
0 -> 0 0 -> 0
_ -> g (x - 1) _ -> g (x - 1)
p = \x -> p = \x ->
case x is when x is
0 -> 0 0 -> 0
1 -> g (x - 1) 1 -> g (x - 1)
_ -> p (x - 1) _ -> p (x - 1)
@ -288,7 +288,7 @@ mod test_canonicalize {
let src = indoc!( let src = indoc!(
r#" r#"
g = \x -> g = \x ->
case x is when x is
0 -> 0 0 -> 0
_ -> g (x + 1) _ -> g (x + 1)
@ -327,7 +327,7 @@ mod test_canonicalize {
let src = indoc!( let src = indoc!(
r#" r#"
q = \x -> q = \x ->
case q x is when q x is
_ -> 0 _ -> 0
0 0
@ -348,12 +348,12 @@ mod test_canonicalize {
let src = indoc!( let src = indoc!(
r#" r#"
q = \x -> q = \x ->
case x is when x is
0 -> 0 0 -> 0
_ -> p (x - 1) _ -> p (x - 1)
p = \x -> p = \x ->
case x is when x is
0 -> 0 0 -> 0
_ -> q (x - 1) _ -> q (x - 1)

View file

@ -87,7 +87,7 @@ mod test_gen {
assert_evals_to!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
case 1 is when 1 is
1 -> 12 1 -> 12
_ -> 34 _ -> 34
"# "#
@ -102,7 +102,7 @@ mod test_gen {
assert_evals_to!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
case 2 is when 2 is
1 -> 63 1 -> 63
_ -> 48 _ -> 48
"# "#

View file

@ -695,7 +695,7 @@ mod test_format {
fn integer_case() { fn integer_case() {
expr_formats_same(indoc!( expr_formats_same(indoc!(
r#" r#"
case b is when b is
1 -> 1 ->
1 1
@ -710,7 +710,7 @@ mod test_format {
expr_formats_to( expr_formats_to(
indoc!( indoc!(
r#" r#"
case year is when year is
1999 -> 1999 ->
@ -725,7 +725,7 @@ mod test_format {
), ),
indoc!( indoc!(
r#" r#"
case year is when year is
1999 -> 1999 ->
1 1
@ -740,10 +740,10 @@ mod test_format {
fn case_with_comments() { fn case_with_comments() {
expr_formats_same(indoc!( expr_formats_same(indoc!(
r#" r#"
case b is when b is
# look at cases # look at cases
1 -> 1 ->
# case 1 # when 1
1 1
# important # important
@ -761,9 +761,9 @@ mod test_format {
fn nested_case() { fn nested_case() {
expr_formats_same(indoc!( expr_formats_same(indoc!(
r#" r#"
case b is when b is
_ -> _ ->
case c is when c is
_ -> _ ->
1 1
"# "#
@ -775,9 +775,9 @@ mod test_format {
expr_formats_to( expr_formats_to(
indoc!( indoc!(
r#" r#"
case b is when b is
1 -> 1 ->
1 # case 1 1 # when 1
# fall through # fall through
_ -> _ ->
@ -786,11 +786,11 @@ mod test_format {
), ),
indoc!( indoc!(
r#" r#"
case b is when b is
1 -> 1 ->
1 1
# case 1 # when 1
# fall through # fall through
_ -> _ ->
2 2

View file

@ -833,7 +833,7 @@ mod test_infer {
infer_eq( infer_eq(
indoc!( indoc!(
r#" r#"
case 1 is when 1 is
1 -> 2 1 -> 2
3 -> 4 3 -> 4
"# "#

View file

@ -1322,7 +1322,7 @@ mod test_parse {
&arena, &arena,
indoc!( indoc!(
r#" r#"
case x is when x is
"blah" -> 1 "blah" -> 1
"mise" -> 2 "mise" -> 2
"# "#
@ -1356,7 +1356,7 @@ mod test_parse {
&arena, &arena,
indoc!( indoc!(
r#" r#"
case x is when x is
1 -> 2 1 -> 2
3 -> 4 3 -> 4
"# "#
@ -1396,7 +1396,7 @@ mod test_parse {
&arena, &arena,
indoc!( indoc!(
r#" r#"
case x is when x is
{ y } -> 2 { y } -> 2
{ z, w } -> 4 { z, w } -> 4
"# "#

View file

@ -863,7 +863,7 @@ mod test_infer_uniq {
infer_eq( infer_eq(
indoc!( indoc!(
r#" r#"
case 1 is when 1 is
1 -> 2 1 -> 2
3 -> 4 3 -> 4
"# "#