Add precedence for shorthand ternary operator

This commit is contained in:
Evan Shaw 2022-09-21 22:22:21 +12:00
parent 723244eca0
commit 46abeec2b8
2 changed files with 14 additions and 1 deletions

View File

@ -2783,6 +2783,19 @@ mod tests {
r#else: Box::new(Expression::Int { i: 5 }),
})],
);
assert_ast(
"<?php 1 ?: 2 ?: 3;",
&[expr!(Expression::Ternary {
condition: Box::new(Expression::Int { i: 1 }),
then: None,
r#else: Box::new(Expression::Ternary {
condition: Box::new(Expression::Int { i: 2 }),
then: None,
r#else: Box::new(Expression::Int { i: 3 })
}),
})],
);
}
#[test]

View File

@ -64,7 +64,7 @@ impl Precedence {
BooleanAnd => Self::And,
BooleanOr => Self::Or,
Coalesce => Self::NullCoalesce,
Question => Self::Ternary,
Question | QuestionColon => Self::Ternary,
Equals | PlusEquals | MinusEquals | AsteriskEqual | PowEquals | SlashEquals
| DotEquals | AndEqual | CoalesceEqual | PercentEquals | AmpersandEquals
| PipeEquals | CaretEquals | LeftShiftEquals | RightShiftEquals => Self::Assignment,