forked from extern/nushell
Convert if expression to match (#1683)
This commit is contained in:
parent
db8219e798
commit
789b28ac8a
@ -221,43 +221,29 @@ fn parse_range(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseEr
|
|||||||
|
|
||||||
/// Parse any allowed operator, including word-based operators
|
/// Parse any allowed operator, including word-based operators
|
||||||
fn parse_operator(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseError>) {
|
fn parse_operator(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseError>) {
|
||||||
let operator = if lite_arg.item == "==" {
|
let operator = match &lite_arg.item[..] {
|
||||||
Operator::Equal
|
"==" => Operator::Equal,
|
||||||
} else if lite_arg.item == "!=" {
|
"!=" => Operator::NotEqual,
|
||||||
Operator::NotEqual
|
"<" => Operator::LessThan,
|
||||||
} else if lite_arg.item == "<" {
|
"<=" => Operator::LessThanOrEqual,
|
||||||
Operator::LessThan
|
">" => Operator::GreaterThan,
|
||||||
} else if lite_arg.item == "<=" {
|
">=" => Operator::GreaterThanOrEqual,
|
||||||
Operator::LessThanOrEqual
|
"=~" => Operator::Contains,
|
||||||
} else if lite_arg.item == ">" {
|
"!~" => Operator::NotContains,
|
||||||
Operator::GreaterThan
|
"+" => Operator::Plus,
|
||||||
} else if lite_arg.item == ">=" {
|
"-" => Operator::Minus,
|
||||||
Operator::GreaterThanOrEqual
|
"*" => Operator::Multiply,
|
||||||
} else if lite_arg.item == "=~" {
|
"/" => Operator::Divide,
|
||||||
Operator::Contains
|
"in:" => Operator::In,
|
||||||
} else if lite_arg.item == "!~" {
|
"not-in:" => Operator::NotIn,
|
||||||
Operator::NotContains
|
"&&" => Operator::And,
|
||||||
} else if lite_arg.item == "+" {
|
"||" => Operator::Or,
|
||||||
Operator::Plus
|
_ => {
|
||||||
} else if lite_arg.item == "-" {
|
|
||||||
Operator::Minus
|
|
||||||
} else if lite_arg.item == "*" {
|
|
||||||
Operator::Multiply
|
|
||||||
} else if lite_arg.item == "/" {
|
|
||||||
Operator::Divide
|
|
||||||
} else if lite_arg.item == "in:" {
|
|
||||||
Operator::In
|
|
||||||
} else if lite_arg.item == "not-in:" {
|
|
||||||
Operator::NotIn
|
|
||||||
} else if lite_arg.item == "&&" {
|
|
||||||
Operator::And
|
|
||||||
} else if lite_arg.item == "||" {
|
|
||||||
Operator::Or
|
|
||||||
} else {
|
|
||||||
return (
|
return (
|
||||||
garbage(lite_arg.span),
|
garbage(lite_arg.span),
|
||||||
Some(ParseError::mismatch("operator", lite_arg.clone())),
|
Some(ParseError::mismatch("operator", lite_arg.clone())),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user