mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:25:42 +02:00
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:
@ -2,8 +2,8 @@ use crate::{current_dir_str, get_full_help};
|
||||
use nu_path::expand_path_with;
|
||||
use nu_protocol::{
|
||||
ast::{
|
||||
Argument, Assignment, Bits, Block, Boolean, Call, Comparison, Expr, Expression, Math,
|
||||
Operator, PathMember, PipelineElement, Redirection,
|
||||
eval_operator, Argument, Assignment, Bits, Block, Boolean, Call, Comparison, Expr,
|
||||
Expression, Math, Operator, PathMember, PipelineElement, Redirection,
|
||||
},
|
||||
engine::{EngineState, ProfilingConfig, Stack},
|
||||
record, DataSource, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
|
||||
@ -13,19 +13,6 @@ use nu_protocol::{
|
||||
use std::collections::HashMap;
|
||||
use std::time::Instant;
|
||||
|
||||
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,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval_call(
|
||||
engine_state: &EngineState,
|
||||
caller_stack: &mut Stack,
|
||||
|
@ -12,6 +12,6 @@ pub use documentation::get_full_help;
|
||||
pub use env::*;
|
||||
pub use eval::{
|
||||
eval_block, eval_block_with_early_return, eval_call, eval_expression,
|
||||
eval_expression_with_input, eval_operator, eval_subexpression, eval_variable, redirect_env,
|
||||
eval_expression_with_input, eval_subexpression, eval_variable, redirect_env,
|
||||
};
|
||||
pub use glob_from::glob_from;
|
||||
|
Reference in New Issue
Block a user