diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index 7267881..2a2bb62 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -150,10 +150,27 @@ fn primary_expr(text: &str) -> ParseResult { while_expr, literal, paren_expr, + lambda_expr, identifier_expr, ))(text) } +fn lambda_expr(text: &str) -> ParseResult { + 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> { + alt(( + map(formal_param, |x| vec![x]), + formal_params + ))(text) +} + + fn while_expr(text: &str) -> ParseResult { let p = preceded(tag("while"), tuple((ws(while_cond), ws(block)))); let m = map(p, |(condition, body)| {