diff --git a/src/expr.rs b/src/expr.rs index e35019d3d5..f55803e038 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -15,6 +15,7 @@ pub enum Expr { Func(String, Box), Apply(Box, Box), Operator(Box, Operator, Box), + Closure(Vec, Box), If(Box, Box, Box), } diff --git a/src/parse.rs b/src/parse.rs index c338286fe6..f80f266cc3 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -263,6 +263,18 @@ where I: Stream, ) } +pub fn closure(min_indent: i32) -> impl Parser +where I: Stream, + I::Error: ParseError +{ + // TODO patterns must be separated by commas! + between(char('|'), char('|'), many1::, _>(pattern())) + .and(expr_body(min_indent)) + .map(|(patterns, closure_body)| { + Expr::Closure(patterns, Box::new(closure_body)) + }) +} + pub fn pattern() -> impl Parser where I: Stream, I::Error: ParseError