Rename the use of invocation to subexpression ()

* Rename the use of invocation to subexpression

* Fix test name
This commit is contained in:
JT 2021-06-07 20:08:35 +12:00 committed by GitHub
parent e376c2d0d4
commit 16faafb7a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 37 additions and 35 deletions
crates
nu-cli/src
completion
types
nu-command
src/commands
tests/commands
nu-engine
src/evaluate
tests/evaluate
nu-parser/src
nu-protocol/src
tests/shell/pipeline/commands

View File

@ -25,7 +25,7 @@ impl<'s> Flatten<'s> {
fn expression(&self, e: &SpannedExpression) -> Vec<CompletionLocation> { fn expression(&self, e: &SpannedExpression) -> Vec<CompletionLocation> {
match &e.expr { match &e.expr {
Expression::Block(block) => self.completion_locations(block), 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::List(exprs) => exprs.iter().flat_map(|v| self.expression(v)).collect(),
Expression::Table(headers, cells) => headers Expression::Table(headers, cells) => headers
.iter() .iter()

View File

@ -302,7 +302,7 @@ fn get_shape_of_expr(expr: &SpannedExpression) -> Option<SyntaxShape> {
Expression::ExternalCommand(_) => Some(SyntaxShape::String), Expression::ExternalCommand(_) => Some(SyntaxShape::String),
Expression::Table(_, _) => Some(SyntaxShape::Table), Expression::Table(_, _) => Some(SyntaxShape::Table),
Expression::Command => Some(SyntaxShape::String), Expression::Command => Some(SyntaxShape::String),
Expression::Invocation(_) => Some(SyntaxShape::Block), Expression::Subexpression(_) => Some(SyntaxShape::Block),
Expression::Garbage => unreachable!("Should have failed at parsing stage"), Expression::Garbage => unreachable!("Should have failed at parsing stage"),
} }
} }
@ -544,7 +544,7 @@ impl VarSyntaxShapeDeductor {
match &path.head.expr { match &path.head.expr {
//PathMember can't be var yet (?) //PathMember can't be var yet (?)
//TODO Iterate over path parts and find var when implemented //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) => { Expression::Variable(var_name, span) => {
self.checked_insert( self.checked_insert(
&VarUsage::new(var_name, span), &VarUsage::new(var_name, span),
@ -588,8 +588,8 @@ impl VarSyntaxShapeDeductor {
self.infer_shapes_in_expr((pipeline_idx, pipeline), expr, scope)?; self.infer_shapes_in_expr((pipeline_idx, pipeline), expr, scope)?;
} }
} }
Expression::Invocation(invoc) => { Expression::Subexpression(invoc) => {
trace!("Inferring vars in invocation: {:?}", invoc); trace!("Inferring vars in subexpression: {:?}", invoc);
self.infer_shape(invoc, scope)?; self.infer_shape(invoc, scope)?;
} }
Expression::Table(header, _rows) => { Expression::Table(header, _rows) => {
@ -794,7 +794,7 @@ impl VarSyntaxShapeDeductor {
| Expression::FilePath(_) | Expression::FilePath(_)
| Expression::ExternalCommand(_) | Expression::ExternalCommand(_)
| Expression::Command | Expression::Command
| Expression::Invocation(_) | Expression::Subexpression(_)
| Expression::Boolean(_) | Expression::Boolean(_)
| Expression::Garbage => { | Expression::Garbage => {
unreachable!("Parser should have rejected code. In only applicable with rhs of type List") unreachable!("Parser should have rejected code. In only applicable with rhs of type List")

View File

@ -89,7 +89,7 @@ fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
UntaggedValue::boolean(false).into_value(&tag), 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 // of evaluate_baseline_expr does not mutate the variables and thus each
// invocations are independent of each other! // invocations are independent of each other!
scope.enter_scope(); scope.enter_scope();

View File

@ -30,7 +30,7 @@ fn sets_the_column_from_a_block_full_stream_output() {
} }
#[test] #[test]
fn sets_the_column_from_an_invocation() { fn sets_the_column_from_a_subexpression() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" r#"

View File

@ -45,7 +45,7 @@ fn sets_the_column_from_a_block_full_stream_output() {
} }
#[test] #[test]
fn sets_the_column_from_an_invocation() { fn sets_the_column_from_a_subexpression() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" r#"

View File

@ -37,7 +37,7 @@ pub fn evaluate_baseline_expr(
} }
Expression::Variable(var, s) => evaluate_reference(&var, ctx, *s), Expression::Variable(var, s) => evaluate_reference(&var, ctx, *s),
Expression::Command => unimplemented!(), Expression::Command => unimplemented!(),
Expression::Invocation(block) => evaluate_invocation(block, ctx), Expression::Subexpression(block) => evaluate_subexpression(block, ctx),
Expression::ExternalCommand(_) => unimplemented!(), Expression::ExternalCommand(_) => unimplemented!(),
Expression::Binary(binary) => { Expression::Binary(binary) => {
// TODO: If we want to add short-circuiting, we'll need to move these down // 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<Value, ShellError> { fn evaluate_subexpression(
block: &hir::Block,
ctx: &EvaluationContext,
) -> Result<Value, ShellError> {
// FIXME: we should use a real context here // FIXME: we should use a real context here
let input = match ctx.scope.get_var("$it") { let input = match ctx.scope.get_var("$it") {
Some(it) => InputStream::one(it), Some(it) => InputStream::one(it),

View File

@ -1,3 +1,3 @@
mod invocation;
mod operator; mod operator;
mod subexpression;
mod variables; mod variables;

View File

@ -1,7 +1,7 @@
use nu_test_support::nu; use nu_test_support::nu;
#[test] #[test]
fn test_parse_invocation_with_range() { fn test_parse_subexpression_with_range() {
let actual = nu!( let actual = nu!(
cwd: ".", cwd: ".",
r#" r#"

View File

@ -129,7 +129,7 @@ pub fn parse_full_column_path(
if head.is_none() && current_part.starts_with('(') && current_part.ends_with(')') { if head.is_none() && current_part.starts_with('(') && current_part.ends_with(')') {
let (invoc, err) = let (invoc, err) =
parse_invocation(&current_part.clone().spanned(part_span), scope); parse_subexpression(&current_part.clone().spanned(part_span), scope);
if error.is_none() { if error.is_none() {
error = err; error = err;
} }
@ -162,7 +162,7 @@ pub fn parse_full_column_path(
if head.is_none() { if head.is_none() {
if current_part.starts_with('(') && current_part.ends_with(')') { if current_part.starts_with('(') && current_part.ends_with(')') {
let (invoc, err) = parse_invocation(&current_part.spanned(part_span), scope); let (invoc, err) = parse_subexpression(&current_part.spanned(part_span), scope);
if error.is_none() { if error.is_none() {
error = err; error = err;
} }
@ -470,13 +470,12 @@ fn parse_filesize(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<Pars
) )
} }
fn parse_invocation( fn parse_subexpression(
lite_arg: &Spanned<String>, lite_arg: &Spanned<String>,
scope: &dyn ParserScope, scope: &dyn ParserScope,
) -> (SpannedExpression, Option<ParseError>) { ) -> (SpannedExpression, Option<ParseError>) {
let mut error = None; let mut error = None;
// We have a command invocation
let string: String = lite_arg let string: String = lite_arg
.item .item
.chars() .chars()
@ -502,7 +501,7 @@ fn parse_invocation(
scope.exit_scope(); scope.exit_scope();
( (
SpannedExpression::new(Expression::Invocation(classified_block), lite_arg.span), SpannedExpression::new(Expression::Subexpression(classified_block), lite_arg.span),
error, error,
) )
} }
@ -526,7 +525,7 @@ fn parse_variable(
} }
/// Parses the given lite_arg starting with dollar returning /// Parses the given lite_arg starting with dollar returning
/// a expression starting with $ /// a expression starting with $
/// Currently either Variable, Invocation, FullColumnPath /// Currently either Variable, String interpolation, FullColumnPath
fn parse_dollar_expr( fn parse_dollar_expr(
lite_arg: &Spanned<String>, lite_arg: &Spanned<String>,
scope: &dyn ParserScope, scope: &dyn ParserScope,
@ -676,7 +675,7 @@ fn parse_interpolated_string(
match result { match result {
(classified_block, None) => { (classified_block, None) => {
output.push(SpannedExpression { output.push(SpannedExpression {
expr: Expression::Invocation(classified_block), expr: Expression::Subexpression(classified_block),
span: c.span, span: c.span,
}); });
} }
@ -709,8 +708,8 @@ fn parse_interpolated_string(
let group = Group::new(pipelines, lite_arg.span); let group = Group::new(pipelines, lite_arg.span);
let call = SpannedExpression { let call = SpannedExpression {
expr: Expression::Invocation(Arc::new(Block::new( expr: Expression::Subexpression(Arc::new(Block::new(
Signature::new("<invocation>"), Signature::new("<subexpression>"),
vec![group], vec![group],
IndexMap::new(), IndexMap::new(),
lite_arg.span, lite_arg.span,
@ -729,7 +728,7 @@ fn parse_external_arg(
if lite_arg.item.starts_with('$') { if lite_arg.item.starts_with('$') {
parse_dollar_expr(&lite_arg, scope) parse_dollar_expr(&lite_arg, scope)
} else if lite_arg.item.starts_with('(') { } else if lite_arg.item.starts_with('(') {
parse_invocation(&lite_arg, scope) parse_subexpression(&lite_arg, scope)
} else { } else {
( (
SpannedExpression::new(Expression::string(lite_arg.item.clone()), lite_arg.span), SpannedExpression::new(Expression::string(lite_arg.item.clone()), lite_arg.span),

View File

@ -6,7 +6,7 @@ use nu_source::{Spanned, SpannedItem};
pub fn expression_to_flat_shape(e: &SpannedExpression) -> Vec<Spanned<FlatShape>> { pub fn expression_to_flat_shape(e: &SpannedExpression) -> Vec<Spanned<FlatShape>> {
match &e.expr { match &e.expr {
Expression::Block(exprs) => shapes(exprs), Expression::Block(exprs) => shapes(exprs),
Expression::Invocation(exprs) => shapes(exprs), Expression::Subexpression(exprs) => shapes(exprs),
Expression::FilePath(_) => vec![FlatShape::Path.spanned(e.span)], Expression::FilePath(_) => vec![FlatShape::Path.spanned(e.span)],
Expression::Garbage => vec![FlatShape::Garbage.spanned(e.span)], Expression::Garbage => vec![FlatShape::Garbage.spanned(e.span)],
Expression::List(exprs) => { Expression::List(exprs) => {

View File

@ -772,7 +772,7 @@ impl PrettyDebugWithSource for SpannedExpression {
Expression::Binary(binary) => binary.pretty_debug(source), Expression::Binary(binary) => binary.pretty_debug(source),
Expression::Range(range) => range.pretty_debug(source), Expression::Range(range) => range.pretty_debug(source),
Expression::Block(_) => DbgDocBldr::opaque("block"), Expression::Block(_) => DbgDocBldr::opaque("block"),
Expression::Invocation(_) => DbgDocBldr::opaque("invocation"), Expression::Subexpression(_) => DbgDocBldr::opaque("subexpression"),
Expression::Garbage => DbgDocBldr::opaque("garbage"), Expression::Garbage => DbgDocBldr::opaque("garbage"),
Expression::List(list) => DbgDocBldr::delimit( Expression::List(list) => DbgDocBldr::delimit(
"[", "[",
@ -831,7 +831,7 @@ impl PrettyDebugWithSource for SpannedExpression {
Expression::Binary(binary) => binary.pretty_debug(source), Expression::Binary(binary) => binary.pretty_debug(source),
Expression::Range(range) => range.pretty_debug(source), Expression::Range(range) => range.pretty_debug(source),
Expression::Block(_) => DbgDocBldr::opaque("block"), Expression::Block(_) => DbgDocBldr::opaque("block"),
Expression::Invocation(_) => DbgDocBldr::opaque("invocation"), Expression::Subexpression(_) => DbgDocBldr::opaque("subexpression"),
Expression::Garbage => DbgDocBldr::opaque("garbage"), Expression::Garbage => DbgDocBldr::opaque("garbage"),
Expression::List(list) => DbgDocBldr::delimit( Expression::List(list) => DbgDocBldr::delimit(
"[", "[",
@ -1082,7 +1082,7 @@ pub enum Expression {
FilePath(PathBuf), FilePath(PathBuf),
ExternalCommand(ExternalStringCommand), ExternalCommand(ExternalStringCommand),
Command, Command,
Invocation(Arc<hir::Block>), Subexpression(Arc<hir::Block>),
Boolean(bool), Boolean(bool),
@ -1106,7 +1106,7 @@ impl ShellTypeName for Expression {
Expression::Binary(..) => "binary", Expression::Binary(..) => "binary",
Expression::Range(..) => "range", Expression::Range(..) => "range",
Expression::Block(..) => "block", Expression::Block(..) => "block",
Expression::Invocation(..) => "command invocation", Expression::Subexpression(..) => "subexpression",
Expression::FullColumnPath(..) => "variable path", Expression::FullColumnPath(..) => "variable path",
Expression::Boolean(..) => "boolean", Expression::Boolean(..) => "boolean",
Expression::ExternalCommand(..) => "external", Expression::ExternalCommand(..) => "external",
@ -1199,7 +1199,7 @@ impl Expression {
|| values.iter().any(|v| v.iter().any(|se| se.has_it_usage())) || values.iter().any(|v| v.iter().any(|se| se.has_it_usage()))
} }
Expression::List(list) => list.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::Binary(binary) => binary.left.has_it_usage() || binary.right.has_it_usage(),
Expression::FullColumnPath(path) => path.head.has_it_usage(), Expression::FullColumnPath(path) => path.head.has_it_usage(),
Expression::Range(range) => { Expression::Range(range) => {
@ -1240,7 +1240,7 @@ impl Expression {
output.extend(item.get_free_variables(known_variables)); 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)); output.extend(block.get_free_variables(known_variables));
} }
Expression::Binary(binary) => { Expression::Binary(binary) => {

View File

@ -116,7 +116,7 @@ fn tags_persist_through_vars() {
} }
#[test] #[test]
fn invocation_properly_redirects() { fn subexpression_properly_redirects() {
let actual = nu!( let actual = nu!(
cwd: ".", cwd: ".",
r#" r#"
@ -128,7 +128,7 @@ fn invocation_properly_redirects() {
} }
#[test] #[test]
fn argument_invocation() { fn argument_subexpression() {
let actual = nu!( let actual = nu!(
cwd: ".", cwd: ".",
r#" r#"
@ -140,8 +140,8 @@ fn argument_invocation() {
} }
#[test] #[test]
fn invocation_handles_dot() { fn subexpression_handles_dot() {
Playground::setup("invocation_handles_dot", |dirs, sandbox| { Playground::setup("subexpression_handles_dot", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed( sandbox.with_files(vec![FileWithContentToBeTrimmed(
"nu_times.csv", "nu_times.csv",
r#" r#"
@ -575,7 +575,7 @@ fn run_dynamic_blocks() {
#[cfg(feature = "which")] #[cfg(feature = "which")]
#[test] #[test]
fn argument_invocation_reports_errors() { fn argument_subexpression_reports_errors() {
let actual = nu!( let actual = nu!(
cwd: ".", cwd: ".",
"echo (ferris_is_not_here.exe)" "echo (ferris_is_not_here.exe)"