make ++ append lists (#6766)

* make `++` append lists

* fmt

* fix for database
This commit is contained in:
pwygab
2022-10-20 18:28:18 +08:00
committed by GitHub
parent 50e53e788a
commit 5e748ae8fc
8 changed files with 104 additions and 2 deletions

View File

@ -4273,6 +4273,7 @@ pub fn parse_operator(
b"=~" => Operator::RegexMatch,
b"!~" => Operator::NotRegexMatch,
b"+" => Operator::Plus,
b"++" => Operator::Append,
b"-" => Operator::Minus,
b"*" => Operator::Multiply,
b"/" => Operator::Divide,

View File

@ -68,6 +68,35 @@ pub fn math_result_type(
)
}
},
Operator::Append => match (&lhs.ty, &rhs.ty) {
(Type::List(a), Type::List(b)) => {
if a == b {
(Type::List(a.clone()), None)
} else {
(Type::List(Box::new(Type::Any)), None)
}
}
(Type::List(a), b) | (b, Type::List(a)) => {
if a == &Box::new(b.clone()) {
(Type::List(a.clone()), None)
} else {
(Type::List(Box::new(Type::Any)), None)
}
}
_ => {
*op = Expression::garbage(op.span);
(
Type::Any,
Some(ParseError::UnsupportedOperation(
op.span,
lhs.span,
lhs.ty.clone(),
rhs.span,
rhs.ty.clone(),
)),
)
}
},
Operator::Minus => match (&lhs.ty, &rhs.ty) {
(Type::Int, Type::Int) => (Type::Int, None),
(Type::Float, Type::Int) => (Type::Float, None),