mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 07:11:29 +02:00
Add support for positive integer ranges
Including support for variables and subexpressions as range bounds.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::{Call, Expression, Operator};
|
||||
use super::{Call, Expression, Operator, RangeOperator};
|
||||
use crate::{BlockId, Signature, Span, VarId};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -6,6 +6,11 @@ pub enum Expr {
|
||||
Bool(bool),
|
||||
Int(i64),
|
||||
Float(f64),
|
||||
Range(
|
||||
Option<Box<Expression>>,
|
||||
Option<Box<Expression>>,
|
||||
RangeOperator,
|
||||
),
|
||||
Var(VarId),
|
||||
Call(Box<Call>),
|
||||
ExternalCall(Vec<u8>, Vec<Vec<u8>>),
|
||||
|
@@ -7,6 +7,7 @@ pub struct Expression {
|
||||
pub span: Span,
|
||||
pub ty: Type,
|
||||
}
|
||||
|
||||
impl Expression {
|
||||
pub fn garbage(span: Span) -> Expression {
|
||||
Expression {
|
||||
@@ -15,6 +16,7 @@ impl Expression {
|
||||
ty: Type::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn precedence(&self) -> usize {
|
||||
match &self.expr {
|
||||
Expr::Operator(operator) => {
|
||||
|
@@ -1,3 +1,5 @@
|
||||
use crate::Span;
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -46,3 +48,24 @@ impl Display for Operator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum RangeInclusion {
|
||||
Inclusive,
|
||||
RightExclusive,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RangeOperator {
|
||||
pub inclusion: RangeInclusion,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
impl Display for RangeOperator {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.inclusion {
|
||||
RangeInclusion::Inclusive => write!(f, ".."),
|
||||
RangeInclusion::RightExclusive => write!(f, "..<"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user