diff --git a/example/ex.hyc b/example/ex.hyc index 538e40d..64a1f18 100644 --- a/example/ex.hyc +++ b/example/ex.hyc @@ -1,5 +1,6 @@ fun foo a b = a * b; let bar = foo( 3 3 ); +let baz = bar in print(baz); if bar == 9 then do diff --git a/src/front/parse.rs b/src/front/parse.rs index 23308df..f21d68f 100644 --- a/src/front/parse.rs +++ b/src/front/parse.rs @@ -16,7 +16,7 @@ pub enum Token { // Keywords Import, - Let, Fun, + Let, In, Fun, If, Then, Else, End, Do, } @@ -74,6 +74,7 @@ pub fn lexer() -> impl Parser, Error = Simple> { "import" => Token::Import, "let" => Token::Let, + "in" => Token::In, "fun" => Token::Fun, "if" => Token::If, "then" => Token::Then, @@ -116,6 +117,7 @@ pub enum Expr { Let { name: String, value: Box, + then: Box>, }, Fun { name: String, @@ -244,9 +246,15 @@ fn expr_parser() -> impl Parser> + Clone { do_block.clone() .or(decl.clone()) ) - .map(|(name, value)| Expr::Let { + .then(just(Token::In) + .ignore_then(do_block.clone() + .or(decl.clone())) + .or_not() + ) + .map(|((name, value), then)| Expr::Let { name, value: Box::new(value), + then: Box::new(then), }).labelled("variable"); let declare_fun = just(Token::Fun)