mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
Convert if expression to match (#1683)
This commit is contained in:
parent
db8219e798
commit
789b28ac8a
1 changed files with 23 additions and 37 deletions
|
@ -221,43 +221,29 @@ fn parse_range(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseEr
|
|||
|
||||
/// Parse any allowed operator, including word-based operators
|
||||
fn parse_operator(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseError>) {
|
||||
let operator = if lite_arg.item == "==" {
|
||||
Operator::Equal
|
||||
} else if lite_arg.item == "!=" {
|
||||
Operator::NotEqual
|
||||
} else if lite_arg.item == "<" {
|
||||
Operator::LessThan
|
||||
} else if lite_arg.item == "<=" {
|
||||
Operator::LessThanOrEqual
|
||||
} else if lite_arg.item == ">" {
|
||||
Operator::GreaterThan
|
||||
} else if lite_arg.item == ">=" {
|
||||
Operator::GreaterThanOrEqual
|
||||
} else if lite_arg.item == "=~" {
|
||||
Operator::Contains
|
||||
} else if lite_arg.item == "!~" {
|
||||
Operator::NotContains
|
||||
} else if lite_arg.item == "+" {
|
||||
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 (
|
||||
garbage(lite_arg.span),
|
||||
Some(ParseError::mismatch("operator", lite_arg.clone())),
|
||||
);
|
||||
let operator = match &lite_arg.item[..] {
|
||||
"==" => Operator::Equal,
|
||||
"!=" => Operator::NotEqual,
|
||||
"<" => Operator::LessThan,
|
||||
"<=" => Operator::LessThanOrEqual,
|
||||
">" => Operator::GreaterThan,
|
||||
">=" => Operator::GreaterThanOrEqual,
|
||||
"=~" => Operator::Contains,
|
||||
"!~" => Operator::NotContains,
|
||||
"+" => Operator::Plus,
|
||||
"-" => Operator::Minus,
|
||||
"*" => Operator::Multiply,
|
||||
"/" => Operator::Divide,
|
||||
"in:" => Operator::In,
|
||||
"not-in:" => Operator::NotIn,
|
||||
"&&" => Operator::And,
|
||||
"||" => Operator::Or,
|
||||
_ => {
|
||||
return (
|
||||
garbage(lite_arg.span),
|
||||
Some(ParseError::mismatch("operator", lite_arg.clone())),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
(
|
||||
|
|
Loading…
Reference in a new issue