From 3b34c82b4285eb9292c13c7fc3307df1056c05fa Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 22 May 2019 21:54:55 -0400 Subject: [PATCH] Introduce Closure --- src/expr.rs | 1 + src/parse.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) 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