mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Add Expr::Let
This commit is contained in:
parent
72a7cf8d1b
commit
b3f3f08c96
2 changed files with 21 additions and 0 deletions
|
@ -8,6 +8,7 @@ pub enum Expr {
|
|||
Char(char),
|
||||
|
||||
Var(String),
|
||||
Let(String, Box<Expr>, Box<Expr>),
|
||||
|
||||
// Functions
|
||||
Func(String, Box<Expr>),
|
||||
|
|
20
src/parse.rs
20
src/parse.rs
|
@ -66,6 +66,7 @@ parser! {
|
|||
number_literal(),
|
||||
char_literal(),
|
||||
if_expr(),
|
||||
let_expr(),
|
||||
func_or_var(),
|
||||
))
|
||||
.and(
|
||||
|
@ -155,6 +156,25 @@ where I: Stream<Item = char, Position = IndentablePosition>,
|
|||
))
|
||||
}
|
||||
|
||||
pub fn let_expr<I>() -> impl Parser<Input = I, Output = Expr>
|
||||
where I: Stream<Item = char, Position = IndentablePosition>,
|
||||
I::Error: ParseError<I::Item, I::Range, I::Position>
|
||||
{
|
||||
ident()
|
||||
.skip(spaces())
|
||||
.skip(char('='))
|
||||
.skip(spaces())
|
||||
.and(expr_body())
|
||||
// TODO check for indent in this expr, then parse a second expr post-outdent
|
||||
.and(expr_body())
|
||||
.map(|((var_name, var_expr), in_expr)| {
|
||||
match var_name {
|
||||
Ok(str) => Expr::Let(str, Box::new(var_expr), Box::new(in_expr)),
|
||||
Err(_ident_problem) => Expr::SyntaxProblem("TODO put _ident_problem here".to_owned())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn func_or_var<I>() -> impl Parser<Input = I, Output = Expr>
|
||||
where I: Stream<Item = char, Position = IndentablePosition>,
|
||||
I::Error: ParseError<I::Item, I::Range, I::Position>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue