Add ends-with operator and fix dataframe operator behavior (#5395)

* add ends-with operator

* escape needles in dataframe operator regex patterns
This commit is contained in:
panicbit
2022-05-02 10:02:38 +02:00
committed by GitHub
parent 07a7bb14bf
commit 49cbc30974
8 changed files with 68 additions and 2 deletions

View File

@ -4049,6 +4049,7 @@ pub fn parse_operator(
b"not-in" => Operator::NotIn,
b"mod" => Operator::Modulo,
b"starts-with" => Operator::StartsWith,
b"ends-with" => Operator::EndsWith,
b"&&" | b"and" => Operator::And,
b"||" | b"or" => Operator::Or,
b"**" => Operator::Pow,

View File

@ -337,6 +337,24 @@ pub fn math_result_type(
)
}
},
Operator::EndsWith => match (&lhs.ty, &rhs.ty) {
(Type::String, Type::String) => (Type::Bool, None),
(Type::Any, _) => (Type::Bool, None),
(_, Type::Any) => (Type::Bool, None),
_ => {
*op = Expression::garbage(op.span);
(
Type::Any,
Some(ParseError::UnsupportedOperation(
op.span,
lhs.span,
lhs.ty.clone(),
rhs.span,
rhs.ty.clone(),
)),
)
}
},
Operator::In => match (&lhs.ty, &rhs.ty) {
(t, Type::List(u)) if type_compatible(t, u) => (Type::Bool, None),
(Type::Int | Type::Float, Type::Range) => (Type::Bool, None),