Lambdas
This commit is contained in:
parent
08ce718fb6
commit
91e7dcb6d0
@ -150,10 +150,27 @@ fn primary_expr(text: &str) -> ParseResult<ExpressionKind> {
|
||||
while_expr,
|
||||
literal,
|
||||
paren_expr,
|
||||
lambda_expr,
|
||||
identifier_expr,
|
||||
))(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> {
|
||||
let p = preceded(tag("while"), tuple((ws(while_cond), ws(block))));
|
||||
let m = map(p, |(condition, body)| {
|
||||
|
Loading…
Reference in New Issue
Block a user