1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

in in let syntax

This commit is contained in:
Natapat Samutpong 2022-02-17 22:36:00 +07:00
parent c3e9ede0ef
commit 9344bb1977
2 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -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<char, Vec<(Token, Span)>, Error = Simple<char>> {
"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<Self>,
then: Box<Option<Self>>,
},
Fun {
name: String,
@ -244,9 +246,15 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + 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)