Starting for expr
This commit is contained in:
parent
744ba2fc74
commit
b6a60a05ba
@ -149,12 +149,41 @@ fn primary_expr(text: &str) -> ParseResult<ExpressionKind> {
|
||||
|
||||
alt((
|
||||
if_expr,
|
||||
for_expr,
|
||||
literal,
|
||||
paren_expr,
|
||||
identifier_expr,
|
||||
))(text)
|
||||
}
|
||||
|
||||
fn for_expr(text: &str) -> ParseResult<ExpressionKind> {
|
||||
//TODO do I need something like no struct literal here?
|
||||
let en = alt((
|
||||
map(enumerator, |e| vec![e]),
|
||||
delimited(tag("{"), enumerators, tag("}"))
|
||||
));
|
||||
preceded(tag("for"),
|
||||
map(tuple((en, for_expr_body)),
|
||||
|(enumerators, body)| ExpressionKind::ForExpression { enumerators, body: Box::new(body) }
|
||||
))(text)
|
||||
}
|
||||
|
||||
fn enumerators(text: &str) -> ParseResult<Vec<Enumerator>> {
|
||||
separated_nonempty_list(alt((value((), tag(",")), statement_sep)),
|
||||
enumerator)(text)
|
||||
}
|
||||
|
||||
fn enumerator(text: &str) -> ParseResult<Enumerator> {
|
||||
map(
|
||||
tuple((identifier, tag("<-"), expression)),
|
||||
|(id, _, generator)| Enumerator { id, generator }
|
||||
)(text)
|
||||
}
|
||||
|
||||
fn for_expr_body(text: &str) -> ParseResult<ForBody> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn invocation_argument(text: &str) -> ParseResult<InvocationArgument> {
|
||||
use nom::character::complete::char;
|
||||
alt((
|
||||
|
Loading…
Reference in New Issue
Block a user