diff --git a/schala-lang/language/src/eval/test.rs b/schala-lang/language/src/eval/test.rs index 7f301b1..6e03711 100644 --- a/schala-lang/language/src/eval/test.rs +++ b/schala-lang/language/src/eval/test.rs @@ -96,26 +96,26 @@ fn full_if_matching() { let source = r#" type Option = Some(T) | None let a = Option::None -if a { is Option::None -> 4, is Option::Some(x) -> x } +if a { is Option::None then 4, is Option::Some(x) then x } "#; test_in_fresh_env!(source, "4"); let source = r#" type Option = Some(T) | None let a = Option::Some(99) -if a { is Option::None -> 4, is Option::Some(x) -> x } +if a { is Option::None then 4, is Option::Some(x) then x } "#; test_in_fresh_env!(source, "99"); let source = r#" let a = 10 -if a { is 10 -> "x", is 4 -> "y" } +if a { is 10 then "x", is 4 then "y" } "#; test_in_fresh_env!(source, "\"x\""); let source = r#" let a = 10 -if a { is 15 -> "x", is 10 -> "y" } +if a { is 15 then "x", is 10 then "y" } "#; test_in_fresh_env!(source, "\"y\""); } @@ -124,7 +124,7 @@ test_in_fresh_env!(source, "\"y\""); fn string_pattern() { let source = r#" let a = "foo" -if a { is "foo" -> "x", is _ -> "y" } +if a { is "foo" then "x", is _ then "y" } "#; test_in_fresh_env!(source, "\"x\""); } @@ -134,8 +134,8 @@ fn boolean_pattern() { let source = r#" let a = true if a { - is true -> "x", - is false -> "y" + is true then "x", + is false then "y" } "#; test_in_fresh_env!(source, "\"x\""); @@ -145,7 +145,7 @@ test_in_fresh_env!(source, "\"x\""); fn boolean_pattern_2() { let source = r#" let a = false -if a { is true -> "x", is false -> "y" } +if a { is true then "x", is false then "y" } "#; test_in_fresh_env!(source, "\"y\""); } @@ -155,7 +155,7 @@ fn ignore_pattern() { let source = r#" type Option = Some(T) | None if Option::Some(10) { - is _ -> "hella" + is _ then "hella" } "#; test_in_fresh_env!(source, "\"hella\""); @@ -165,8 +165,8 @@ test_in_fresh_env!(source, "\"hella\""); fn tuple_pattern() { let source = r#" if (1, 2) { - is (1, x) -> x, - is _ -> 99 + is (1, x) then x, + is _ then 99 } "#; test_in_fresh_env!(source, 2); @@ -177,8 +177,8 @@ test_in_fresh_env!(source, 2); fn tuple_pattern_2() { let source = r#" if (1, 2) { - is (10, x) -> x, - is (y, x) -> x + y + is (10, x) then x, + is (y, x) then x + y } "#; test_in_fresh_env!(source, 3); @@ -188,8 +188,8 @@ test_in_fresh_env!(source, 3); fn tuple_pattern_3() { let source = r#" if (1, 5) { - is (10, x) -> x, - is (1, x) -> x + is (10, x) then x, + is (1, x) then x } "#; test_in_fresh_env!(source, 5); @@ -199,8 +199,8 @@ test_in_fresh_env!(source, 5); fn tuple_pattern_4() { let source = r#" if (1, 5) { - is (10, x) -> x, - is (1, x) -> x, + is (10, x) then x, + is (1, x) then x, } "#; test_in_fresh_env!(source, 5); @@ -215,21 +215,21 @@ let b = Stuff::Jugs(1, "haha") let c = Stuff::Mardok let x = if a { - is Stuff::Mulch(20) -> "x", - is _ -> "ERR" + is Stuff::Mulch(20) then "x", + is _ then "ERR" } let y = if b { - is Stuff::Mulch(n) -> "ERR", - is Stuff::Jugs(2, _) -> "ERR", - is Stuff::Jugs(1, s) -> s, - is _ -> "ERR", + is Stuff::Mulch(n) then "ERR", + is Stuff::Jugs(2, _) then "ERR", + is Stuff::Jugs(1, s) then s, + is _ then "ERR", } let z = if c { - is Stuff::Jugs(_, _) -> "ERR", - is Stuff::Mardok -> "NIGH", - is _ -> "ERR", + is Stuff::Jugs(_, _) then "ERR", + is Stuff::Mardok then "NIGH", + is _ then "ERR", } (x, y, z) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index b6a457c..24de350 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -122,7 +122,7 @@ //! simple_pattern_match := pattern "then" conditional //! else_clause := ε | "else" expr_or_block //! guard_block := "{" (guard_arm, ",")* "}" -//! guard_arm := guard "->" expr_or_block +//! guard_arm := guard "then" expr_or_block //! guard := "is" pattern | (operator)+ precedence_expr //! ``` //! @@ -894,7 +894,7 @@ impl Parser { #[recursive_descent_method] fn guard_arm(&mut self) -> ParseResult { let guard = self.guard()?; - expect!(self, Operator(ref c) if **c == "->"); + expect!(self, Keyword(Kw::Then)); let body = self.expr_or_block()?; Ok(GuardArm { guard, body }) }