Add null coalescing operator.

This commit is contained in:
Stephen Chung
2022-06-10 11:22:33 +08:00
parent 0f1e51b1c9
commit 8999872d62
7 changed files with 87 additions and 15 deletions

View File

@@ -1917,8 +1917,8 @@ impl Engine {
}
}
}
// ??? && ??? = rhs, ??? || ??? = rhs
Expr::And(..) | Expr::Or(..) => Err(LexError::ImproperSymbol(
// ??? && ??? = rhs, ??? || ??? = rhs, xxx ?? xxx = rhs
Expr::And(..) | Expr::Or(..) | Expr::Coalesce(..) => Err(LexError::ImproperSymbol(
"=".to_string(),
"Possibly a typo of '=='?".to_string(),
)
@@ -2223,6 +2223,18 @@ impl Engine {
pos,
)
}
Token::DoubleQuestion => {
let rhs = args.pop().unwrap();
let current_lhs = args.pop().unwrap();
Expr::Coalesce(
BinaryExpr {
lhs: current_lhs,
rhs,
}
.into(),
pos,
)
}
Token::In => {
// Swap the arguments
let current_lhs = args.remove(0);