Fix for expression

This commit is contained in:
greg 2020-03-15 02:00:39 -07:00
parent cde52efcf2
commit 3ce73a4b55

View File

@ -160,10 +160,12 @@ fn for_expr(text: &str) -> ParseResult<ExpressionKind> {
map(enumerator, |e| vec![e]), map(enumerator, |e| vec![e]),
delimited(tag("{"), enumerators, tag("}")) delimited(tag("{"), enumerators, tag("}"))
)); ));
context("For expression",
preceded(tag("for"), 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) } |(enumerators, body)| ExpressionKind::ForExpression { enumerators, body: Box::new(body) }
))(text) ))))(text)
} }
@ -174,16 +176,17 @@ fn enumerators(text: &str) -> ParseResult<Vec<Enumerator>> {
fn enumerator(text: &str) -> ParseResult<Enumerator> { fn enumerator(text: &str) -> ParseResult<Enumerator> {
map( map(
tuple((identifier, tag("<-"), expression)), tuple((ws(identifier), ws(tag("<-")), ws(expression))),
|(id, _, generator)| Enumerator { id, generator } |(id, _, generator)| Enumerator { id, generator }
)(text) )(text)
} }
fn for_expr_body(text: &str) -> ParseResult<ForBody> { fn for_expr_body(text: &str) -> ParseResult<ForBody> {
context("For expression body",
alt(( alt((
map(preceded(tag("return"), expression), ForBody::MonadicReturn), map(preceded(ws(tag("return")), expression), ForBody::MonadicReturn),
map(delimited(tag("{"), block, tag("}")), ForBody::StatementBlock), map(block, ForBody::StatementBlock),
))(text) )))(text)
} }
fn invocation_argument(text: &str) -> ParseResult<InvocationArgument> { fn invocation_argument(text: &str) -> ParseResult<InvocationArgument> {