Fix for expression

This commit is contained in:
greg 2020-03-15 02:00:39 -07:00
parent cde52efcf2
commit 3ce73a4b55
1 changed files with 9 additions and 6 deletions

View File

@ -160,10 +160,12 @@ fn for_expr(text: &str) -> ParseResult<ExpressionKind> {
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<Vec<Enumerator>> {
fn enumerator(text: &str) -> ParseResult<Enumerator> {
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<ForBody> {
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<InvocationArgument> {