mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Introduce Closure
This commit is contained in:
parent
91aac9a86e
commit
3b34c82b42
2 changed files with 13 additions and 0 deletions
|
@ -15,6 +15,7 @@ pub enum Expr {
|
|||
Func(String, Box<Expr>),
|
||||
Apply(Box<Expr>, Box<Expr>),
|
||||
Operator(Box<Expr>, Operator, Box<Expr>),
|
||||
Closure(Vec<Pattern>, Box<Expr>),
|
||||
|
||||
If(Box<Expr>, Box<Expr>, Box<Expr>),
|
||||
}
|
||||
|
|
12
src/parse.rs
12
src/parse.rs
|
@ -263,6 +263,18 @@ where I: Stream<Item = char, Position = IndentablePosition>,
|
|||
)
|
||||
}
|
||||
|
||||
pub fn closure<I>(min_indent: i32) -> impl Parser<Input = I, Output = Expr>
|
||||
where I: Stream<Item = char, Position = IndentablePosition>,
|
||||
I::Error: ParseError<I::Item, I::Range, I::Position>
|
||||
{
|
||||
// TODO patterns must be separated by commas!
|
||||
between(char('|'), char('|'), many1::<Vec<_>, _>(pattern()))
|
||||
.and(expr_body(min_indent))
|
||||
.map(|(patterns, closure_body)| {
|
||||
Expr::Closure(patterns, Box::new(closure_body))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn pattern<I>() -> impl Parser<Input = I, Output = Pattern>
|
||||
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