forked from extern/nushell
Allow operator in constants (#10212)
This pr fixes https://github.com/nushell/nushell/issues/10200 # Description Allow unary and binary operators in constants, e.g. ```bash const a = 1 + 2 const b = [0, 1, 2, 3] ++ [4] ``` # User-Facing Changes Now constants can contain operators. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting None --------- Co-authored-by: Horasal <horsal@horsal.dev>
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
use crate::Span;
|
||||
use crate::{ShellError, Span};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::{Expr, Expression};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Comparison {
|
||||
Equal,
|
||||
@ -128,3 +130,16 @@ impl Display for RangeOperator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval_operator(op: &Expression) -> Result<Operator, ShellError> {
|
||||
match op {
|
||||
Expression {
|
||||
expr: Expr::Operator(operator),
|
||||
..
|
||||
} => Ok(operator.clone()),
|
||||
Expression { span, expr, .. } => Err(ShellError::UnknownOperator {
|
||||
op_token: format!("{expr:?}"),
|
||||
span: *span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user