From 64d83142c3f8068116be6f0f019b0d91d671cec4 Mon Sep 17 00:00:00 2001 From: JT Date: Sat, 9 Oct 2021 11:30:10 +1300 Subject: [PATCH] More external cleanup --- crates/nu-engine/src/eval.rs | 29 +++++++++-------------------- crates/nu-parser/src/flatten.rs | 4 ++-- crates/nu-parser/src/parser.rs | 5 +++-- crates/nu-protocol/src/ast/expr.rs | 2 +- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index ca755c665..1a44d6fff 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -2,8 +2,6 @@ use nu_protocol::ast::{Block, Call, Expr, Expression, Operator, Statement}; use nu_protocol::engine::EvaluationContext; use nu_protocol::{Range, ShellError, Span, Type, Unit, Value}; -use crate::FromValue; - pub fn eval_operator(op: &Expression) -> Result { match op { Expression { @@ -72,7 +70,8 @@ fn eval_call(context: &EvaluationContext, call: &Call, input: Value) -> Result eval_expression(context, expr), Expr::Call(call) => eval_call(context, call, Value::nothing()), - Expr::ExternalCall(name, args) => { - eval_external(context, name, args, Value::nothing(), true) + Expr::ExternalCall(name, span, args) => { + eval_external(context, name, span, args, Value::nothing(), true) } Expr::Operator(_) => Ok(Value::Nothing { span: expr.span }), Expr::BinaryOp(lhs, op, rhs) => { @@ -283,12 +271,13 @@ pub fn eval_block( input = eval_call(context, call, input)?; } Expression { - expr: Expr::ExternalCall(name, args), + expr: Expr::ExternalCall(name, name_span, args), .. } => { input = eval_external( context, name, + name_span, args, input, i == pipeline.expressions.len() - 1, diff --git a/crates/nu-parser/src/flatten.rs b/crates/nu-parser/src/flatten.rs index 26eae7e91..db94d622b 100644 --- a/crates/nu-parser/src/flatten.rs +++ b/crates/nu-parser/src/flatten.rs @@ -63,8 +63,8 @@ pub fn flatten_expression( } output } - Expr::ExternalCall(name, args) => { - let mut output = vec![(*name, FlatShape::External)]; + Expr::ExternalCall(_, name_span, args) => { + let mut output = vec![(*name_span, FlatShape::External)]; for arg in args { //output.push((*arg, FlatShape::ExternalArg)); diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 2f1ae7b50..dbd2ddc29 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -108,7 +108,8 @@ pub fn parse_external_call( spans: &[Span], ) -> (Expression, Option) { let mut args = vec![]; - let name = spans[0]; + let name_span = spans[0]; + let name = String::from_utf8_lossy(working_set.get_span_contents(name_span)).to_string(); let mut error = None; for span in &spans[1..] { @@ -129,7 +130,7 @@ pub fn parse_external_call( } ( Expression { - expr: Expr::ExternalCall(name, args), + expr: Expr::ExternalCall(name, name_span, args), span: span(spans), ty: Type::Unknown, custom_completion: None, diff --git a/crates/nu-protocol/src/ast/expr.rs b/crates/nu-protocol/src/ast/expr.rs index 6eb0b539d..718dec5f6 100644 --- a/crates/nu-protocol/src/ast/expr.rs +++ b/crates/nu-protocol/src/ast/expr.rs @@ -14,7 +14,7 @@ pub enum Expr { ), Var(VarId), Call(Box), - ExternalCall(Span, Vec), + ExternalCall(String, Span, Vec), Operator(Operator), RowCondition(VarId, Box), BinaryOp(Box, Box, Box), //lhs, op, rhs