From efda75860ccb151a7aa2568e11acb9cff654e996 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 10 Mar 2020 01:45:15 -0700 Subject: [PATCH] For expr + whitespace --- schala-lang/language/src/parser.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index 7747f13..635c1b4 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -168,6 +168,7 @@ fn for_expr(text: &str) -> ParseResult { ))(text) } + fn enumerators(text: &str) -> ParseResult> { separated_nonempty_list(alt((value((), tag(",")), statement_sep)), enumerator)(text) @@ -181,7 +182,10 @@ fn enumerator(text: &str) -> ParseResult { } fn for_expr_body(text: &str) -> ParseResult { - unimplemented!() + alt(( + map(preceded(tag("return"), expression), ForBody::MonadicReturn), + map(delimited(tag("{"), block, tag("}")), ForBody::StatementBlock), + ))(text) } fn invocation_argument(text: &str) -> ParseResult { @@ -386,7 +390,7 @@ fn precedence_expr(text: &str) -> ParseResult { } fn expression_kind(text: &str) -> ParseResult { - context("Expression kind", precedence_expr)(text) + context("Expression kind", ws(precedence_expr))(text) } fn type_anno(text: &str) -> ParseResult { @@ -402,7 +406,7 @@ fn type_name(text: &str) -> ParseResult { } fn expression(text: &str) -> ParseResult { - let (rest, (kind, type_anno)) = pair(expression_kind, opt(type_anno))(text)?; + let (rest, (kind, type_anno)) = ws(pair(expression_kind, opt(type_anno)))(text)?; let expr = Expression { id: ItemId::new(0), kind, type_anno }; Ok((rest, expr)) }