forked from extern/nushell
Add pattern matching (#8590)
# Description This adds `match` and basic pattern matching. An example: ``` match $x { 1..10 => { print "Value is between 1 and 10" } { foo: $bar } => { print $"Value has a 'foo' field with value ($bar)" } [$a, $b] => { print $"Value is a list with two items: ($a) and ($b)" } _ => { print "Value is none of the above" } } ``` Like the recent changes to `if` to allow it to be used as an expression, `match` can also be used as an expression. This allows you to assign the result to a variable, eg) `let xyz = match ...` I've also included a short-hand pattern for matching records, as I think it might help when doing a lot of record patterns: `{$foo}` which is equivalent to `{foo: $foo}`. There are still missing components, so consider this the first step in full pattern matching support. Currently missing: * Patterns for strings * Or-patterns (like the `|` in Rust) * Patterns for tables (unclear how we want to match a table, so it'll need some design) * Patterns for binary values * And much more # User-Facing Changes [see above] # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use chrono::FixedOffset;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Call, CellPath, Expression, FullCellPath, Operator, RangeOperator};
|
||||
use super::{Call, CellPath, Expression, FullCellPath, MatchPattern, Operator, RangeOperator};
|
||||
use crate::{ast::ImportPattern, BlockId, Signature, Span, Spanned, Unit, VarId};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
@ -27,6 +27,7 @@ pub enum Expr {
|
||||
Subexpression(BlockId),
|
||||
Block(BlockId),
|
||||
Closure(BlockId),
|
||||
MatchBlock(Vec<(MatchPattern, Expression)>),
|
||||
List(Vec<Expression>),
|
||||
Table(Vec<Expression>, Vec<Vec<Expression>>),
|
||||
Record(Vec<(Expression, Expression)>),
|
||||
@ -43,6 +44,7 @@ pub enum Expr {
|
||||
Overlay(Option<BlockId>), // block ID of the overlay's origin module
|
||||
Signature(Box<Signature>),
|
||||
StringInterpolation(Vec<Expression>),
|
||||
MatchPattern(Box<MatchPattern>),
|
||||
Nothing,
|
||||
Garbage,
|
||||
}
|
||||
|
@ -221,7 +221,9 @@ impl Expression {
|
||||
}
|
||||
false
|
||||
}
|
||||
Expr::MatchPattern(_) => false,
|
||||
Expr::Operator(_) => false,
|
||||
Expr::MatchBlock(_) => false,
|
||||
Expr::Range(left, middle, right, ..) => {
|
||||
if let Some(left) = &left {
|
||||
if left.has_in_variable(working_set) {
|
||||
@ -395,6 +397,8 @@ impl Expression {
|
||||
Expr::Nothing => {}
|
||||
Expr::GlobPattern(_) => {}
|
||||
Expr::Int(_) => {}
|
||||
Expr::MatchPattern(_) => {}
|
||||
Expr::MatchBlock(_) => {}
|
||||
Expr::Keyword(_, _, expr) => expr.replace_in_variable(working_set, new_var_id),
|
||||
Expr::List(list) => {
|
||||
for l in list {
|
||||
@ -554,6 +558,8 @@ impl Expression {
|
||||
Expr::Garbage => {}
|
||||
Expr::Nothing => {}
|
||||
Expr::GlobPattern(_) => {}
|
||||
Expr::MatchPattern(_) => {}
|
||||
Expr::MatchBlock(_) => {}
|
||||
Expr::Int(_) => {}
|
||||
Expr::Keyword(_, _, expr) => expr.replace_span(working_set, replaced, new_span),
|
||||
Expr::List(list) => {
|
||||
|
21
crates/nu-protocol/src/ast/match_pattern.rs
Normal file
21
crates/nu-protocol/src/ast/match_pattern.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Span, VarId};
|
||||
|
||||
use super::Expression;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MatchPattern {
|
||||
pub pattern: Pattern,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum Pattern {
|
||||
Record(Vec<(String, MatchPattern)>),
|
||||
List(Vec<MatchPattern>),
|
||||
Value(Expression),
|
||||
Variable(VarId),
|
||||
IgnoreValue, // the _ pattern
|
||||
Garbage,
|
||||
}
|
@ -4,6 +4,7 @@ mod cell_path;
|
||||
mod expr;
|
||||
mod expression;
|
||||
mod import_pattern;
|
||||
mod match_pattern;
|
||||
mod operator;
|
||||
mod pipeline;
|
||||
|
||||
@ -13,5 +14,6 @@ pub use cell_path::*;
|
||||
pub use expr::*;
|
||||
pub use expression::*;
|
||||
pub use import_pattern::*;
|
||||
pub use match_pattern::*;
|
||||
pub use operator::*;
|
||||
pub use pipeline::*;
|
||||
|
@ -3,6 +3,7 @@ mod capture_block;
|
||||
mod command;
|
||||
mod engine_state;
|
||||
mod overlay;
|
||||
mod pattern_match;
|
||||
mod stack;
|
||||
|
||||
pub use call_info::*;
|
||||
@ -10,4 +11,5 @@ pub use capture_block::*;
|
||||
pub use command::*;
|
||||
pub use engine_state::*;
|
||||
pub use overlay::*;
|
||||
pub use pattern_match::*;
|
||||
pub use stack::*;
|
||||
|
201
crates/nu-protocol/src/engine/pattern_match.rs
Normal file
201
crates/nu-protocol/src/engine/pattern_match.rs
Normal file
@ -0,0 +1,201 @@
|
||||
use crate::{
|
||||
ast::{Expr, MatchPattern, Pattern, RangeInclusion},
|
||||
Unit, Value, VarId,
|
||||
};
|
||||
|
||||
pub trait Matcher {
|
||||
fn match_value(&self, value: &Value, matches: &mut Vec<(VarId, Value)>) -> bool;
|
||||
}
|
||||
|
||||
impl Matcher for MatchPattern {
|
||||
fn match_value(&self, value: &Value, matches: &mut Vec<(VarId, Value)>) -> bool {
|
||||
self.pattern.match_value(value, matches)
|
||||
}
|
||||
}
|
||||
|
||||
impl Matcher for Pattern {
|
||||
fn match_value(&self, value: &Value, matches: &mut Vec<(VarId, Value)>) -> bool {
|
||||
match self {
|
||||
Pattern::Garbage => false,
|
||||
Pattern::IgnoreValue => true,
|
||||
Pattern::Record(field_patterns) => match value {
|
||||
Value::Record { cols, vals, .. } => {
|
||||
'top: for field_pattern in field_patterns {
|
||||
for (col_idx, col) in cols.iter().enumerate() {
|
||||
if col == &field_pattern.0 {
|
||||
// We have found the field
|
||||
let result = field_pattern.1.match_value(&vals[col_idx], matches);
|
||||
if !result {
|
||||
return false;
|
||||
} else {
|
||||
continue 'top;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
Pattern::Variable(var_id) => {
|
||||
// TODO: FIXME: This needs the span of this variable
|
||||
matches.push((*var_id, value.clone()));
|
||||
true
|
||||
}
|
||||
Pattern::List(items) => match &value {
|
||||
Value::List { vals, .. } => {
|
||||
if items.len() > vals.len() {
|
||||
// We need more items in our pattern than are available in the Value
|
||||
return false;
|
||||
}
|
||||
|
||||
for (val_idx, val) in vals.iter().enumerate() {
|
||||
// We require that the pattern and the value have the same number of items, or the pattern does not match
|
||||
// The only exception is if the pattern includes a `..` pattern
|
||||
|
||||
if let Some(pattern) = items.get(val_idx) {
|
||||
if !pattern.match_value(val, matches) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
Pattern::Value(pattern_value) => {
|
||||
// TODO: Fill this out with the rest of them
|
||||
match &pattern_value.expr {
|
||||
Expr::Int(x) => {
|
||||
if let Value::Int { val, .. } = &value {
|
||||
x == val
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
Expr::Binary(x) => {
|
||||
if let Value::Binary { val, .. } = &value {
|
||||
x == val
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
Expr::Bool(x) => {
|
||||
if let Value::Bool { val, .. } = &value {
|
||||
x == val
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
Expr::ValueWithUnit(amount, unit) => {
|
||||
if let Value::Filesize { val, .. } = &value {
|
||||
// FIXME: we probably want this math in one place that both the
|
||||
// pattern matcher and the eval engine can get to it
|
||||
match &amount.expr {
|
||||
Expr::Int(amount) => match &unit.item {
|
||||
Unit::Byte => amount == val,
|
||||
Unit::Kilobyte => *val == amount * 1000,
|
||||
Unit::Megabyte => *val == amount * 1000 * 1000,
|
||||
Unit::Gigabyte => *val == amount * 1000 * 1000 * 1000,
|
||||
Unit::Petabyte => *val == amount * 1000 * 1000 * 1000 * 1000,
|
||||
Unit::Exabyte => {
|
||||
*val == amount * 1000 * 1000 * 1000 * 1000 * 1000
|
||||
}
|
||||
Unit::Zettabyte => {
|
||||
*val == amount * 1000 * 1000 * 1000 * 1000 * 1000 * 1000
|
||||
}
|
||||
Unit::Kibibyte => *val == amount * 1024,
|
||||
Unit::Mebibyte => *val == amount * 1024 * 1024,
|
||||
Unit::Gibibyte => *val == amount * 1024 * 1024 * 1024,
|
||||
Unit::Pebibyte => *val == amount * 1024 * 1024 * 1024 * 1024,
|
||||
Unit::Exbibyte => {
|
||||
*val == amount * 1024 * 1024 * 1024 * 1024 * 1024
|
||||
}
|
||||
Unit::Zebibyte => {
|
||||
*val == amount * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
} else if let Value::Duration { val, .. } = &value {
|
||||
// FIXME: we probably want this math in one place that both the
|
||||
// pattern matcher and the eval engine can get to it
|
||||
match &amount.expr {
|
||||
Expr::Int(amount) => match &unit.item {
|
||||
Unit::Nanosecond => val == amount,
|
||||
Unit::Microsecond => *val == amount * 1000,
|
||||
Unit::Millisecond => *val == amount * 1000 * 1000,
|
||||
Unit::Second => *val == amount * 1000 * 1000 * 1000,
|
||||
Unit::Minute => *val == amount * 1000 * 1000 * 1000 * 60,
|
||||
Unit::Hour => *val == amount * 1000 * 1000 * 1000 * 60 * 60,
|
||||
Unit::Day => *val == amount * 1000 * 1000 * 1000 * 60 * 60 * 24,
|
||||
Unit::Week => {
|
||||
*val == amount * 1000 * 1000 * 1000 * 60 * 60 * 24 * 7
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
Expr::Range(start, step, end, inclusion) => {
|
||||
// TODO: Add support for floats
|
||||
|
||||
let start = if let Some(start) = &start {
|
||||
match &start.expr {
|
||||
Expr::Int(start) => *start,
|
||||
_ => return false,
|
||||
}
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let end = if let Some(end) = &end {
|
||||
match &end.expr {
|
||||
Expr::Int(end) => *end,
|
||||
_ => return false,
|
||||
}
|
||||
} else {
|
||||
i64::MAX
|
||||
};
|
||||
|
||||
let step = if let Some(step) = step {
|
||||
match &step.expr {
|
||||
Expr::Int(step) => *step - start,
|
||||
_ => return false,
|
||||
}
|
||||
} else if end < start {
|
||||
-1
|
||||
} else {
|
||||
1
|
||||
};
|
||||
|
||||
let (start, end) = if end < start {
|
||||
(end, start)
|
||||
} else {
|
||||
(start, end)
|
||||
};
|
||||
|
||||
if let Value::Int { val, .. } = &value {
|
||||
if matches!(inclusion.inclusion, RangeInclusion::RightExclusive) {
|
||||
*val >= start && *val < end && ((*val - start) % step) == 0
|
||||
} else {
|
||||
*val >= start && *val <= end && ((*val - start) % step) == 0
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -73,6 +73,12 @@ pub enum SyntaxShape {
|
||||
/// A general math expression, eg `1 + 2`
|
||||
MathExpression,
|
||||
|
||||
/// A block of matches, used by `match`
|
||||
MatchBlock,
|
||||
|
||||
/// A match pattern, eg `{a: $foo}`
|
||||
MatchPattern,
|
||||
|
||||
/// Nothing
|
||||
Nothing,
|
||||
|
||||
@ -137,6 +143,8 @@ impl SyntaxShape {
|
||||
Type::List(Box::new(contents))
|
||||
}
|
||||
SyntaxShape::Keyword(_, expr) => expr.to_type(),
|
||||
SyntaxShape::MatchBlock => Type::Any,
|
||||
SyntaxShape::MatchPattern => Type::Any,
|
||||
SyntaxShape::MathExpression => Type::Any,
|
||||
SyntaxShape::Nothing => Type::Any,
|
||||
SyntaxShape::Number => Type::Number,
|
||||
@ -196,6 +204,8 @@ impl Display for SyntaxShape {
|
||||
SyntaxShape::Variable => write!(f, "var"),
|
||||
SyntaxShape::VarWithOptType => write!(f, "vardecl"),
|
||||
SyntaxShape::Signature => write!(f, "signature"),
|
||||
SyntaxShape::MatchPattern => write!(f, "matchpattern"),
|
||||
SyntaxShape::MatchBlock => write!(f, "matchblock"),
|
||||
SyntaxShape::Expression => write!(f, "expression"),
|
||||
SyntaxShape::Boolean => write!(f, "bool"),
|
||||
SyntaxShape::Error => write!(f, "error"),
|
||||
|
@ -22,6 +22,7 @@ pub enum Type {
|
||||
Int,
|
||||
List(Box<Type>),
|
||||
ListStream,
|
||||
MatchPattern,
|
||||
#[default]
|
||||
Nothing,
|
||||
Number,
|
||||
@ -94,6 +95,7 @@ impl Type {
|
||||
Type::Binary => SyntaxShape::Binary,
|
||||
Type::Custom(_) => SyntaxShape::Any,
|
||||
Type::Signature => SyntaxShape::Signature,
|
||||
Type::MatchPattern => SyntaxShape::MatchPattern,
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,6 +116,7 @@ impl Type {
|
||||
Type::Record(_) => String::from("record"),
|
||||
Type::Table(_) => String::from("table"),
|
||||
Type::List(_) => String::from("list"),
|
||||
Type::MatchPattern => String::from("match pattern"),
|
||||
Type::Nothing => String::from("nothing"),
|
||||
Type::Number => String::from("number"),
|
||||
Type::String => String::from("string"),
|
||||
@ -180,6 +183,7 @@ impl Display for Type {
|
||||
Type::Binary => write!(f, "binary"),
|
||||
Type::Custom(custom) => write!(f, "{custom}"),
|
||||
Type::Signature => write!(f, "signature"),
|
||||
Type::MatchPattern => write!(f, "match pattern"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::ast::{CellPath, PathMember};
|
||||
use crate::ast::{CellPath, MatchPattern, PathMember};
|
||||
use crate::engine::{Block, Closure};
|
||||
use crate::ShellError;
|
||||
use crate::{Range, Spanned, Value};
|
||||
@ -563,3 +563,34 @@ impl FromValue for Spanned<Closure> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromValue for Spanned<MatchPattern> {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::MatchPattern { val, span } => Ok(Spanned {
|
||||
item: *val.clone(),
|
||||
span: *span,
|
||||
}),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "Match pattern".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromValue for MatchPattern {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::MatchPattern { val, .. } => Ok(*val.clone()),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "Match pattern".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ mod range;
|
||||
mod stream;
|
||||
mod unit;
|
||||
|
||||
use crate::ast::{Bits, Boolean, CellPath, Comparison, PathMember};
|
||||
use crate::ast::{Bits, Boolean, CellPath, Comparison, MatchPattern, PathMember};
|
||||
use crate::ast::{Math, Operator};
|
||||
use crate::engine::EngineState;
|
||||
use crate::ShellError;
|
||||
@ -113,6 +113,10 @@ pub enum Value {
|
||||
val: Box<dyn LazyRecord>,
|
||||
span: Span,
|
||||
},
|
||||
MatchPattern {
|
||||
val: Box<MatchPattern>,
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
impl Clone for Value {
|
||||
@ -185,6 +189,10 @@ impl Clone for Value {
|
||||
span: *span,
|
||||
},
|
||||
Value::CustomValue { val, span } => val.clone_value(*span),
|
||||
Value::MatchPattern { val, span } => Value::MatchPattern {
|
||||
val: val.clone(),
|
||||
span: *span,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -387,6 +395,7 @@ impl Value {
|
||||
Value::CellPath { span, .. } => Ok(*span),
|
||||
Value::CustomValue { span, .. } => Ok(*span),
|
||||
Value::LazyRecord { span, .. } => Ok(*span),
|
||||
Value::MatchPattern { span, .. } => Ok(*span),
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,6 +427,7 @@ impl Value {
|
||||
Value::Binary { span, .. } => *span = new_span,
|
||||
Value::CellPath { span, .. } => *span = new_span,
|
||||
Value::CustomValue { span, .. } => *span = new_span,
|
||||
Value::MatchPattern { span, .. } => *span = new_span,
|
||||
}
|
||||
|
||||
self
|
||||
@ -475,6 +485,7 @@ impl Value {
|
||||
Value::Binary { .. } => Type::Binary,
|
||||
Value::CellPath { .. } => Type::CellPath,
|
||||
Value::CustomValue { val, .. } => Type::Custom(val.typetag_name().into()),
|
||||
Value::MatchPattern { .. } => Type::MatchPattern,
|
||||
}
|
||||
}
|
||||
|
||||
@ -571,6 +582,7 @@ impl Value {
|
||||
Value::Binary { val, .. } => format!("{val:?}"),
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::CustomValue { val, .. } => val.value_string(),
|
||||
Value::MatchPattern { val, .. } => format!("<Pattern: {:?}>", val),
|
||||
}
|
||||
}
|
||||
|
||||
@ -622,6 +634,7 @@ impl Value {
|
||||
Value::Binary { val, .. } => format!("{val:?}"),
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::CustomValue { val, .. } => val.value_string(),
|
||||
Value::MatchPattern { .. } => "<Pattern>".into(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -673,6 +686,7 @@ impl Value {
|
||||
Value::Binary { val, .. } => format!("{val:?}"),
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::CustomValue { val, .. } => val.value_string(),
|
||||
Value::MatchPattern { val, .. } => format!("<Pattern {:?}>", val),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1720,6 +1734,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Int { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1740,6 +1755,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Float { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1760,6 +1776,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Filesize { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1780,6 +1797,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Duration { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1800,6 +1818,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Date { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1820,6 +1839,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Range { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1840,6 +1860,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::String { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1860,6 +1881,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(
|
||||
Value::Record {
|
||||
@ -1912,6 +1934,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::List { vals: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1932,6 +1955,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Block { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1952,6 +1976,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Closure { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1972,6 +1997,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Nothing { .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -1992,6 +2018,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Error { .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -2012,6 +2039,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Less),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::Binary { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -2032,6 +2060,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { val: rhs, .. } => lhs.partial_cmp(rhs),
|
||||
Value::CellPath { .. } => Some(Ordering::Less),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::CellPath { val: lhs, .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
@ -2052,6 +2081,7 @@ impl PartialOrd for Value {
|
||||
Value::Binary { .. } => Some(Ordering::Greater),
|
||||
Value::CellPath { val: rhs, .. } => lhs.partial_cmp(rhs),
|
||||
Value::CustomValue { .. } => Some(Ordering::Less),
|
||||
Value::MatchPattern { .. } => Some(Ordering::Less),
|
||||
},
|
||||
(Value::CustomValue { val: lhs, .. }, rhs) => lhs.partial_cmp(rhs),
|
||||
(Value::LazyRecord { val, .. }, rhs) => {
|
||||
@ -2061,6 +2091,27 @@ impl PartialOrd for Value {
|
||||
None
|
||||
}
|
||||
}
|
||||
(Value::MatchPattern { .. }, rhs) => match rhs {
|
||||
Value::Bool { .. } => Some(Ordering::Greater),
|
||||
Value::Int { .. } => Some(Ordering::Greater),
|
||||
Value::Float { .. } => Some(Ordering::Greater),
|
||||
Value::Filesize { .. } => Some(Ordering::Greater),
|
||||
Value::Duration { .. } => Some(Ordering::Greater),
|
||||
Value::Date { .. } => Some(Ordering::Greater),
|
||||
Value::Range { .. } => Some(Ordering::Greater),
|
||||
Value::String { .. } => Some(Ordering::Greater),
|
||||
Value::Record { .. } => Some(Ordering::Greater),
|
||||
Value::LazyRecord { .. } => Some(Ordering::Greater),
|
||||
Value::List { .. } => Some(Ordering::Greater),
|
||||
Value::Block { .. } => Some(Ordering::Greater),
|
||||
Value::Closure { .. } => Some(Ordering::Greater),
|
||||
Value::Nothing { .. } => Some(Ordering::Greater),
|
||||
Value::Error { .. } => Some(Ordering::Greater),
|
||||
Value::Binary { .. } => Some(Ordering::Greater),
|
||||
Value::CellPath { .. } => Some(Ordering::Greater),
|
||||
Value::CustomValue { .. } => Some(Ordering::Greater),
|
||||
Value::MatchPattern { .. } => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user