mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
Rename the use of invocation to subexpression (#3568)
* Rename the use of invocation to subexpression * Fix test name
This commit is contained in:
parent
e376c2d0d4
commit
16faafb7a8
@ -25,7 +25,7 @@ impl<'s> Flatten<'s> {
|
||||
fn expression(&self, e: &SpannedExpression) -> Vec<CompletionLocation> {
|
||||
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()
|
||||
|
@ -302,7 +302,7 @@ fn get_shape_of_expr(expr: &SpannedExpression) -> Option<SyntaxShape> {
|
||||
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")
|
||||
|
@ -89,7 +89,7 @@ fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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();
|
||||
|
@ -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#"
|
||||
|
@ -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#"
|
||||
|
@ -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<Value, ShellError> {
|
||||
fn evaluate_subexpression(
|
||||
block: &hir::Block,
|
||||
ctx: &EvaluationContext,
|
||||
) -> Result<Value, ShellError> {
|
||||
// FIXME: we should use a real context here
|
||||
let input = match ctx.scope.get_var("$it") {
|
||||
Some(it) => InputStream::one(it),
|
||||
|
@ -1,3 +1,3 @@
|
||||
mod invocation;
|
||||
mod operator;
|
||||
mod subexpression;
|
||||
mod variables;
|
||||
|
@ -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#"
|
@ -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<String>) -> (SpannedExpression, Option<Pars
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_invocation(
|
||||
fn parse_subexpression(
|
||||
lite_arg: &Spanned<String>,
|
||||
scope: &dyn ParserScope,
|
||||
) -> (SpannedExpression, Option<ParseError>) {
|
||||
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<String>,
|
||||
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("<invocation>"),
|
||||
expr: Expression::Subexpression(Arc::new(Block::new(
|
||||
Signature::new("<subexpression>"),
|
||||
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),
|
||||
|
@ -6,7 +6,7 @@ use nu_source::{Spanned, SpannedItem};
|
||||
pub fn expression_to_flat_shape(e: &SpannedExpression) -> Vec<Spanned<FlatShape>> {
|
||||
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) => {
|
||||
|
@ -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<hir::Block>),
|
||||
Subexpression(Arc<hir::Block>),
|
||||
|
||||
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) => {
|
||||
|
@ -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)"
|
||||
|
Loading…
Reference in New Issue
Block a user