This commit is contained in:
greg 2020-03-15 22:10:38 -07:00
parent 08ce718fb6
commit 91e7dcb6d0

View File

@ -150,10 +150,27 @@ fn primary_expr(text: &str) -> ParseResult<ExpressionKind> {
while_expr, while_expr,
literal, literal,
paren_expr, paren_expr,
lambda_expr,
identifier_expr, identifier_expr,
))(text) ))(text)
} }
fn lambda_expr(text: &str) -> ParseResult<ExpressionKind> {
let p = preceded(ws(tag("\\")),
tuple((ws(lambda_param_list), ws(opt(type_anno)), ws(block))));
context("Lambda expression",
map(p, |(params, type_anno, body)| ExpressionKind::Lambda { params, type_anno, body })
)(text)
}
fn lambda_param_list(text: &str) -> ParseResult<Vec<FormalParam>> {
alt((
map(formal_param, |x| vec![x]),
formal_params
))(text)
}
fn while_expr(text: &str) -> ParseResult<ExpressionKind> { fn while_expr(text: &str) -> ParseResult<ExpressionKind> {
let p = preceded(tag("while"), tuple((ws(while_cond), ws(block)))); let p = preceded(tag("while"), tuple((ws(while_cond), ws(block))));
let m = map(p, |(condition, body)| { let m = map(p, |(condition, body)| {