forked from extern/nushell
Implement exclusive and inclusive ranges with ..< and .. (#2541)
* Implement exclusive and inclusive ranges with .. and ..= This commit adds right-exclusive ranges. The original a..b inclusive syntax was changed to reflect the Rust notation. New a..=b syntax was introduced to have the old behavior. Currently, both a.. and b..= is valid, and it is unclear whether it's valid to impose restrictions. The original issue suggests .. for inclusive and ..< for exclusive ranges, this can be implemented by making simple changes to this commit. * Fix collect tests by changing ranges to ..= * Fix clippy lints in exclusive range matching * Implement exclusive ranges using `..<`
This commit is contained in:
@ -5,7 +5,7 @@ use crate::prelude::*;
|
||||
use async_recursion::async_recursion;
|
||||
use log::trace;
|
||||
use nu_errors::{ArgumentError, ShellError};
|
||||
use nu_protocol::hir::{self, Expression, ExternalRedirection, SpannedExpression};
|
||||
use nu_protocol::hir::{self, Expression, ExternalRedirection, RangeOperator, SpannedExpression};
|
||||
use nu_protocol::{
|
||||
ColumnPath, Primitive, RangeInclusion, UnspannedPathMember, UntaggedValue, Value,
|
||||
};
|
||||
@ -82,7 +82,10 @@ pub(crate) async fn evaluate_baseline_expr(
|
||||
);
|
||||
let right = (
|
||||
right.as_primitive()?.spanned(right_span),
|
||||
RangeInclusion::Inclusive,
|
||||
match &range.operator.item {
|
||||
RangeOperator::Inclusive => RangeInclusion::Inclusive,
|
||||
RangeOperator::RightExclusive => RangeInclusion::Exclusive,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(UntaggedValue::range(left, right).into_value(tag))
|
||||
|
@ -26,6 +26,9 @@ impl Palette for DefaultPalette {
|
||||
}
|
||||
FlatShape::Type => single_style_span(Color::Blue.bold(), shape.span),
|
||||
FlatShape::Operator => single_style_span(Color::Yellow.normal(), shape.span),
|
||||
FlatShape::DotDotLeftAngleBracket => {
|
||||
single_style_span(Color::Yellow.bold(), shape.span)
|
||||
}
|
||||
FlatShape::DotDot => single_style_span(Color::Yellow.bold(), shape.span),
|
||||
FlatShape::Dot => single_style_span(Style::new().fg(Color::White), shape.span),
|
||||
FlatShape::InternalCommand => single_style_span(Color::Cyan.bold(), shape.span),
|
||||
@ -91,6 +94,9 @@ impl Palette for ThemedPalette {
|
||||
FlatShape::Identifier => single_style_span(self.theme.identifier.normal(), shape.span),
|
||||
FlatShape::Type => single_style_span(self.theme.r#type.bold(), shape.span),
|
||||
FlatShape::Operator => single_style_span(self.theme.operator.normal(), shape.span),
|
||||
FlatShape::DotDotLeftAngleBracket => {
|
||||
single_style_span(self.theme.dot_dot.bold(), shape.span)
|
||||
}
|
||||
FlatShape::DotDot => single_style_span(self.theme.dot_dot.bold(), shape.span),
|
||||
FlatShape::Dot => single_style_span(Style::new().fg(*self.theme.dot), shape.span),
|
||||
FlatShape::InternalCommand => {
|
||||
|
Reference in New Issue
Block a user