if conditions
This commit is contained in:
parent
77bd4f3f16
commit
f67bb61888
|
|
@ -605,7 +605,7 @@ fn expr<'a>() -> impl Parser<'a, TokenInput<'a>, Index, ParserExtra> {
|
||||||
|
|
||||||
let field = just(Token::Dot).ignore_then(select! {Token::Ident(ident) => ident});
|
let field = just(Token::Dot).ignore_then(select! {Token::Ident(ident) => ident});
|
||||||
|
|
||||||
let expr = simple.pratt((
|
let assignment_expr = simple.pratt((
|
||||||
postfix(100, subscript, |expr, index, e: &mut E| {
|
postfix(100, subscript, |expr, index, e: &mut E| {
|
||||||
let node = AstNode::Subscript { expr, index };
|
let node = AstNode::Subscript { expr, index };
|
||||||
e.state().push(node)
|
e.state().push(node)
|
||||||
|
|
@ -729,6 +729,27 @@ fn expr<'a>() -> impl Parser<'a, TokenInput<'a>, Index, ParserExtra> {
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let else_expr = just(Token::Else).ignore_then(_expr.clone());
|
||||||
|
|
||||||
|
let if_expr = just(Token::If)
|
||||||
|
.ignore_then(
|
||||||
|
_expr
|
||||||
|
.clone()
|
||||||
|
.delimited_by(just(Token::OpenParens), just(Token::CloseParens)),
|
||||||
|
)
|
||||||
|
.then(_expr.clone())
|
||||||
|
.then(else_expr.or_not())
|
||||||
|
.map_with(|((condition, then), r#else), e: &mut E| {
|
||||||
|
let node = AstNode::If {
|
||||||
|
condition,
|
||||||
|
then,
|
||||||
|
r#else,
|
||||||
|
};
|
||||||
|
e.state().push(node)
|
||||||
|
});
|
||||||
|
|
||||||
|
let expr = choice((if_expr, assignment_expr)).labelled("expression");
|
||||||
|
|
||||||
Arc::new(expr)
|
Arc::new(expr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue