diff --git a/crates/nu-cli/src/completion/engine.rs b/crates/nu-cli/src/completion/engine.rs index 5000abc333..f99a6c1fab 100644 --- a/crates/nu-cli/src/completion/engine.rs +++ b/crates/nu-cli/src/completion/engine.rs @@ -25,7 +25,7 @@ impl<'s> Flatten<'s> { fn expression(&self, e: &SpannedExpression) -> Vec { match &e.expr { Expression::Block(block) => self.completion_locations(block), - Expression::Invocation(block) => self.completion_locations(block), + Expression::Subexpression(block) => self.completion_locations(block), Expression::List(exprs) => exprs.iter().flat_map(|v| self.expression(v)).collect(), Expression::Table(headers, cells) => headers .iter() diff --git a/crates/nu-cli/src/types/deduction.rs b/crates/nu-cli/src/types/deduction.rs index a5ad92c5eb..93feb1ce08 100644 --- a/crates/nu-cli/src/types/deduction.rs +++ b/crates/nu-cli/src/types/deduction.rs @@ -302,7 +302,7 @@ fn get_shape_of_expr(expr: &SpannedExpression) -> Option { Expression::ExternalCommand(_) => Some(SyntaxShape::String), Expression::Table(_, _) => Some(SyntaxShape::Table), Expression::Command => Some(SyntaxShape::String), - Expression::Invocation(_) => Some(SyntaxShape::Block), + Expression::Subexpression(_) => Some(SyntaxShape::Block), Expression::Garbage => unreachable!("Should have failed at parsing stage"), } } @@ -544,7 +544,7 @@ impl VarSyntaxShapeDeductor { match &path.head.expr { //PathMember can't be var yet (?) //TODO Iterate over path parts and find var when implemented - Expression::Invocation(b) => self.infer_shape(&b, scope)?, + Expression::Subexpression(b) => self.infer_shape(&b, scope)?, Expression::Variable(var_name, span) => { self.checked_insert( &VarUsage::new(var_name, span), @@ -588,8 +588,8 @@ impl VarSyntaxShapeDeductor { self.infer_shapes_in_expr((pipeline_idx, pipeline), expr, scope)?; } } - Expression::Invocation(invoc) => { - trace!("Inferring vars in invocation: {:?}", invoc); + Expression::Subexpression(invoc) => { + trace!("Inferring vars in subexpression: {:?}", invoc); self.infer_shape(invoc, scope)?; } Expression::Table(header, _rows) => { @@ -794,7 +794,7 @@ impl VarSyntaxShapeDeductor { | Expression::FilePath(_) | Expression::ExternalCommand(_) | Expression::Command - | Expression::Invocation(_) + | Expression::Subexpression(_) | Expression::Boolean(_) | Expression::Garbage => { unreachable!("Parser should have rejected code. In only applicable with rhs of type List") diff --git a/crates/nu-command/src/commands/any.rs b/crates/nu-command/src/commands/any.rs index d2ce5a99bd..0e435cf2c2 100644 --- a/crates/nu-command/src/commands/any.rs +++ b/crates/nu-command/src/commands/any.rs @@ -89,7 +89,7 @@ fn any(args: CommandArgs) -> Result { UntaggedValue::boolean(false).into_value(&tag), )); - // Variables in nu are immutable. Having the same variable accross invocations + // Variables in nu are immutable. Having the same variable across invocations // of evaluate_baseline_expr does not mutate the variables and thus each // invocations are independent of each other! scope.enter_scope(); diff --git a/crates/nu-command/tests/commands/insert.rs b/crates/nu-command/tests/commands/insert.rs index eb02d11a6a..4d162de95d 100644 --- a/crates/nu-command/tests/commands/insert.rs +++ b/crates/nu-command/tests/commands/insert.rs @@ -30,7 +30,7 @@ fn sets_the_column_from_a_block_full_stream_output() { } #[test] -fn sets_the_column_from_an_invocation() { +fn sets_the_column_from_a_subexpression() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" diff --git a/crates/nu-command/tests/commands/update.rs b/crates/nu-command/tests/commands/update.rs index c1273930d9..5506fb4880 100644 --- a/crates/nu-command/tests/commands/update.rs +++ b/crates/nu-command/tests/commands/update.rs @@ -45,7 +45,7 @@ fn sets_the_column_from_a_block_full_stream_output() { } #[test] -fn sets_the_column_from_an_invocation() { +fn sets_the_column_from_a_subexpression() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" diff --git a/crates/nu-engine/src/evaluate/evaluator.rs b/crates/nu-engine/src/evaluate/evaluator.rs index 1231c1a714..328a3d99f4 100644 --- a/crates/nu-engine/src/evaluate/evaluator.rs +++ b/crates/nu-engine/src/evaluate/evaluator.rs @@ -37,7 +37,7 @@ pub fn evaluate_baseline_expr( } Expression::Variable(var, s) => evaluate_reference(&var, ctx, *s), Expression::Command => unimplemented!(), - Expression::Invocation(block) => evaluate_invocation(block, ctx), + Expression::Subexpression(block) => evaluate_subexpression(block, ctx), Expression::ExternalCommand(_) => unimplemented!(), Expression::Binary(binary) => { // TODO: If we want to add short-circuiting, we'll need to move these down @@ -277,7 +277,10 @@ fn evaluate_reference( } } -fn evaluate_invocation(block: &hir::Block, ctx: &EvaluationContext) -> Result { +fn evaluate_subexpression( + block: &hir::Block, + ctx: &EvaluationContext, +) -> Result { // FIXME: we should use a real context here let input = match ctx.scope.get_var("$it") { Some(it) => InputStream::one(it), diff --git a/crates/nu-engine/tests/evaluate/mod.rs b/crates/nu-engine/tests/evaluate/mod.rs index 298581ade5..26045df067 100644 --- a/crates/nu-engine/tests/evaluate/mod.rs +++ b/crates/nu-engine/tests/evaluate/mod.rs @@ -1,3 +1,3 @@ -mod invocation; mod operator; +mod subexpression; mod variables; diff --git a/crates/nu-engine/tests/evaluate/invocation.rs b/crates/nu-engine/tests/evaluate/subexpression.rs similarity index 93% rename from crates/nu-engine/tests/evaluate/invocation.rs rename to crates/nu-engine/tests/evaluate/subexpression.rs index d606cc187e..20aa7c3ab1 100644 --- a/crates/nu-engine/tests/evaluate/invocation.rs +++ b/crates/nu-engine/tests/evaluate/subexpression.rs @@ -1,7 +1,7 @@ use nu_test_support::nu; #[test] -fn test_parse_invocation_with_range() { +fn test_parse_subexpression_with_range() { let actual = nu!( cwd: ".", r#" diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index 3f7d1967bc..218fe1b338 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -129,7 +129,7 @@ pub fn parse_full_column_path( if head.is_none() && current_part.starts_with('(') && current_part.ends_with(')') { let (invoc, err) = - parse_invocation(¤t_part.clone().spanned(part_span), scope); + parse_subexpression(¤t_part.clone().spanned(part_span), scope); if error.is_none() { error = err; } @@ -162,7 +162,7 @@ pub fn parse_full_column_path( if head.is_none() { if current_part.starts_with('(') && current_part.ends_with(')') { - let (invoc, err) = parse_invocation(¤t_part.spanned(part_span), scope); + let (invoc, err) = parse_subexpression(¤t_part.spanned(part_span), scope); if error.is_none() { error = err; } @@ -470,13 +470,12 @@ fn parse_filesize(lite_arg: &Spanned) -> (SpannedExpression, Option, scope: &dyn ParserScope, ) -> (SpannedExpression, Option) { let mut error = None; - // We have a command invocation let string: String = lite_arg .item .chars() @@ -502,7 +501,7 @@ fn parse_invocation( scope.exit_scope(); ( - SpannedExpression::new(Expression::Invocation(classified_block), lite_arg.span), + SpannedExpression::new(Expression::Subexpression(classified_block), lite_arg.span), error, ) } @@ -526,7 +525,7 @@ fn parse_variable( } /// Parses the given lite_arg starting with dollar returning /// a expression starting with $ -/// Currently either Variable, Invocation, FullColumnPath +/// Currently either Variable, String interpolation, FullColumnPath fn parse_dollar_expr( lite_arg: &Spanned, scope: &dyn ParserScope, @@ -676,7 +675,7 @@ fn parse_interpolated_string( match result { (classified_block, None) => { output.push(SpannedExpression { - expr: Expression::Invocation(classified_block), + expr: Expression::Subexpression(classified_block), span: c.span, }); } @@ -709,8 +708,8 @@ fn parse_interpolated_string( let group = Group::new(pipelines, lite_arg.span); let call = SpannedExpression { - expr: Expression::Invocation(Arc::new(Block::new( - Signature::new(""), + expr: Expression::Subexpression(Arc::new(Block::new( + Signature::new(""), vec![group], IndexMap::new(), lite_arg.span, @@ -729,7 +728,7 @@ fn parse_external_arg( if lite_arg.item.starts_with('$') { parse_dollar_expr(&lite_arg, scope) } else if lite_arg.item.starts_with('(') { - parse_invocation(&lite_arg, scope) + parse_subexpression(&lite_arg, scope) } else { ( SpannedExpression::new(Expression::string(lite_arg.item.clone()), lite_arg.span), diff --git a/crates/nu-parser/src/shapes.rs b/crates/nu-parser/src/shapes.rs index 0065c1afde..4760646c47 100644 --- a/crates/nu-parser/src/shapes.rs +++ b/crates/nu-parser/src/shapes.rs @@ -6,7 +6,7 @@ use nu_source::{Spanned, SpannedItem}; pub fn expression_to_flat_shape(e: &SpannedExpression) -> Vec> { match &e.expr { Expression::Block(exprs) => shapes(exprs), - Expression::Invocation(exprs) => shapes(exprs), + Expression::Subexpression(exprs) => shapes(exprs), Expression::FilePath(_) => vec![FlatShape::Path.spanned(e.span)], Expression::Garbage => vec![FlatShape::Garbage.spanned(e.span)], Expression::List(exprs) => { diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index 7ebf07f2b0..1e3cc061e9 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -772,7 +772,7 @@ impl PrettyDebugWithSource for SpannedExpression { Expression::Binary(binary) => binary.pretty_debug(source), Expression::Range(range) => range.pretty_debug(source), Expression::Block(_) => DbgDocBldr::opaque("block"), - Expression::Invocation(_) => DbgDocBldr::opaque("invocation"), + Expression::Subexpression(_) => DbgDocBldr::opaque("subexpression"), Expression::Garbage => DbgDocBldr::opaque("garbage"), Expression::List(list) => DbgDocBldr::delimit( "[", @@ -831,7 +831,7 @@ impl PrettyDebugWithSource for SpannedExpression { Expression::Binary(binary) => binary.pretty_debug(source), Expression::Range(range) => range.pretty_debug(source), Expression::Block(_) => DbgDocBldr::opaque("block"), - Expression::Invocation(_) => DbgDocBldr::opaque("invocation"), + Expression::Subexpression(_) => DbgDocBldr::opaque("subexpression"), Expression::Garbage => DbgDocBldr::opaque("garbage"), Expression::List(list) => DbgDocBldr::delimit( "[", @@ -1082,7 +1082,7 @@ pub enum Expression { FilePath(PathBuf), ExternalCommand(ExternalStringCommand), Command, - Invocation(Arc), + Subexpression(Arc), Boolean(bool), @@ -1106,7 +1106,7 @@ impl ShellTypeName for Expression { Expression::Binary(..) => "binary", Expression::Range(..) => "range", Expression::Block(..) => "block", - Expression::Invocation(..) => "command invocation", + Expression::Subexpression(..) => "subexpression", Expression::FullColumnPath(..) => "variable path", Expression::Boolean(..) => "boolean", Expression::ExternalCommand(..) => "external", @@ -1199,7 +1199,7 @@ impl Expression { || values.iter().any(|v| v.iter().any(|se| se.has_it_usage())) } Expression::List(list) => list.iter().any(|se| se.has_it_usage()), - Expression::Invocation(block) => block.has_it_usage(), + Expression::Subexpression(block) => block.has_it_usage(), Expression::Binary(binary) => binary.left.has_it_usage() || binary.right.has_it_usage(), Expression::FullColumnPath(path) => path.head.has_it_usage(), Expression::Range(range) => { @@ -1240,7 +1240,7 @@ impl Expression { output.extend(item.get_free_variables(known_variables)); } } - Expression::Invocation(block) | Expression::Block(block) => { + Expression::Subexpression(block) | Expression::Block(block) => { output.extend(block.get_free_variables(known_variables)); } Expression::Binary(binary) => { diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 2ddda4b9df..e5184258d8 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -116,7 +116,7 @@ fn tags_persist_through_vars() { } #[test] -fn invocation_properly_redirects() { +fn subexpression_properly_redirects() { let actual = nu!( cwd: ".", r#" @@ -128,7 +128,7 @@ fn invocation_properly_redirects() { } #[test] -fn argument_invocation() { +fn argument_subexpression() { let actual = nu!( cwd: ".", r#" @@ -140,8 +140,8 @@ fn argument_invocation() { } #[test] -fn invocation_handles_dot() { - Playground::setup("invocation_handles_dot", |dirs, sandbox| { +fn subexpression_handles_dot() { + Playground::setup("subexpression_handles_dot", |dirs, sandbox| { sandbox.with_files(vec![FileWithContentToBeTrimmed( "nu_times.csv", r#" @@ -575,7 +575,7 @@ fn run_dynamic_blocks() { #[cfg(feature = "which")] #[test] -fn argument_invocation_reports_errors() { +fn argument_subexpression_reports_errors() { let actual = nu!( cwd: ".", "echo (ferris_is_not_here.exe)"