mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:25:38 +02:00
Canonical expr block (#1584)
* Add the canonical form for an expression block * Remove commented out code
This commit is contained in:
36
crates/nu-cli/src/commands/classified/expr.rs
Normal file
36
crates/nu-cli/src/commands/classified/expr.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use crate::evaluate::evaluate_baseline_expr;
|
||||
use crate::prelude::*;
|
||||
use log::{log_enabled, trace};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::hir::SpannedExpression;
|
||||
|
||||
use futures_util::pin_mut;
|
||||
use nu_protocol::Scope;
|
||||
|
||||
pub(crate) fn run_expression_block(
|
||||
expr: SpannedExpression,
|
||||
context: &mut Context,
|
||||
input: Option<InputStream>,
|
||||
) -> Result<Option<InputStream>, ShellError> {
|
||||
if log_enabled!(log::Level::Trace) {
|
||||
trace!(target: "nu::run::expr", "->");
|
||||
trace!(target: "nu::run::expr", "{:?}", expr);
|
||||
}
|
||||
|
||||
let registry = context.registry().clone();
|
||||
|
||||
let stream = async_stream! {
|
||||
if let Some(input) = input {
|
||||
let values = input.values;
|
||||
pin_mut!(values);
|
||||
|
||||
while let Some(row) = values.next().await {
|
||||
yield evaluate_baseline_expr(&expr, ®istry, &Scope::new(row));
|
||||
}
|
||||
} else {
|
||||
yield evaluate_baseline_expr(&expr, ®istry, &Scope::empty());
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Some(stream.to_input_stream()))
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod dynamic;
|
||||
pub(crate) mod expr;
|
||||
pub(crate) mod external;
|
||||
pub(crate) mod internal;
|
||||
pub(crate) mod pipeline;
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::commands::classified::expr::run_expression_block;
|
||||
use crate::commands::classified::external::run_external_command;
|
||||
use crate::commands::classified::internal::run_internal_command;
|
||||
use crate::context::Context;
|
||||
@ -21,9 +22,7 @@ pub(crate) async fn run_pipeline(
|
||||
return Err(ShellError::unimplemented("Dynamic commands"))
|
||||
}
|
||||
|
||||
// (Some(ClassifiedCommand::Expr(_)), _) | (_, Some(ClassifiedCommand::Expr(_))) => {
|
||||
// return Err(ShellError::unimplemented("Expression-only commands"))
|
||||
// }
|
||||
(Some(ClassifiedCommand::Expr(expr)), _) => run_expression_block(*expr, ctx, input)?,
|
||||
(Some(ClassifiedCommand::Error(err)), _) => return Err(err.into()),
|
||||
(_, Some(ClassifiedCommand::Error(err))) => return Err(err.clone().into()),
|
||||
|
||||
@ -38,7 +37,6 @@ pub(crate) async fn run_pipeline(
|
||||
}
|
||||
|
||||
(None, _) => break,
|
||||
_ => unimplemented!("Not yet implented cases in run_pipeline"),
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user