From 3ce73a4b55c8664cd0fc85906910b0ae3bfb4a80 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 15 Mar 2020 02:00:39 -0700 Subject: [PATCH] Fix for expression --- schala-lang/language/src/parser.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 {