parser: treat ? : same as ?: combined

This commit is contained in:
Ryan Chandler 2022-12-10 17:12:23 +00:00
parent 4076aeea85
commit 7e66e812d9
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -93,12 +93,17 @@ fn for_precedence(state: &mut State, precedence: Precedence) -> ParseResult<Expr
match kind {
TokenKind::Question => {
let then = lowest_precedence(state)?;
let then = if state.current.kind == TokenKind::Colon {
None
} else {
Some(Box::new(lowest_precedence(state)?))
};
utils::skip_colon(state)?;
let otherwise = for_precedence(state, rpred)?;
left = Expression::Ternary {
condition: Box::new(left),
then: Some(Box::new(then)),
then,
r#else: Box::new(otherwise),
}
}