From 9344bb1977c02d98b0629531a4b2030c3527247e Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Thu, 17 Feb 2022 22:36:00 +0700 Subject: [PATCH] `in` in let syntax --- example/ex.hyc | 1 + src/front/parse.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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)