mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:45:45 +02:00
Add logical xor
operator (#7242)
We already have the binary `bit-xor` and the shortcircuiting logical `or`(`||`) and `and`(`&&`). This introduces `xor` as a compact form for both brevity and clarity. You can express the operation through `not`/`and`/`or` with a slight risk of introducing bugs through typos. Operator precedence `and` > `xor` > `or` Added logic and precedence tests.
This commit is contained in:
committed by
GitHub
parent
3e76ed9122
commit
2ccb91dc6a
@ -4502,6 +4502,7 @@ pub fn parse_operator(
|
||||
b"ends-with" => Operator::Comparison(Comparison::EndsWith),
|
||||
b"&&" | b"and" => Operator::Boolean(Boolean::And),
|
||||
b"||" | b"or" => Operator::Boolean(Boolean::Or),
|
||||
b"xor" => Operator::Boolean(Boolean::Xor),
|
||||
b"**" => Operator::Math(Math::Pow),
|
||||
_ => {
|
||||
return (
|
||||
|
@ -244,7 +244,9 @@ pub fn math_result_type(
|
||||
)
|
||||
}
|
||||
},
|
||||
Operator::Boolean(Boolean::And) | Operator::Boolean(Boolean::Or) => {
|
||||
Operator::Boolean(Boolean::And)
|
||||
| Operator::Boolean(Boolean::Or)
|
||||
| Operator::Boolean(Boolean::Xor) => {
|
||||
match (&lhs.ty, &rhs.ty) {
|
||||
(Type::Bool, Type::Bool) => (Type::Bool, None),
|
||||
|
||||
|
Reference in New Issue
Block a user