diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index a3d1b3e..bfc2bf3 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -160,10 +160,12 @@ fn for_expr(text: &str) -> ParseResult { map(enumerator, |e| vec![e]), delimited(tag("{"), enumerators, tag("}")) )); + context("For expression", preceded(tag("for"), - map(tuple((en, for_expr_body)), + cut( + map(tuple((ws(en), for_expr_body)), |(enumerators, body)| ExpressionKind::ForExpression { enumerators, body: Box::new(body) } - ))(text) + ))))(text) } @@ -174,16 +176,17 @@ fn enumerators(text: &str) -> ParseResult> { fn enumerator(text: &str) -> ParseResult { map( - tuple((identifier, tag("<-"), expression)), + tuple((ws(identifier), ws(tag("<-")), ws(expression))), |(id, _, generator)| Enumerator { id, generator } )(text) } fn for_expr_body(text: &str) -> ParseResult { + context("For expression body", alt(( - map(preceded(tag("return"), expression), ForBody::MonadicReturn), - map(delimited(tag("{"), block, tag("}")), ForBody::StatementBlock), - ))(text) + map(preceded(ws(tag("return")), expression), ForBody::MonadicReturn), + map(block, ForBody::StatementBlock), + )))(text) } fn invocation_argument(text: &str) -> ParseResult {