mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 20:57:49 +02:00
Aliasing math expression shows error earlier (#8779)
This commit is contained in:
@ -109,6 +109,13 @@ pub enum ParseError {
|
||||
)]
|
||||
CantAliasKeyword(String, #[label("not supported in alias")] Span),
|
||||
|
||||
#[error("Can't create alias to expression.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::cant_alias_expression),
|
||||
help("Only command calls can be aliased.")
|
||||
)]
|
||||
CantAliasExpression(String, #[label("aliasing {0} is not supported")] Span),
|
||||
|
||||
#[error("Unknown operator")]
|
||||
#[diagnostic(code(nu::parser::unknown_operator), help("{1}"))]
|
||||
UnknownOperator(
|
||||
@ -434,6 +441,7 @@ impl ParseError {
|
||||
ParseError::ExpectedKeyword(_, s) => *s,
|
||||
ParseError::UnexpectedKeyword(_, s) => *s,
|
||||
ParseError::CantAliasKeyword(_, s) => *s,
|
||||
ParseError::CantAliasExpression(_, s) => *s,
|
||||
ParseError::BuiltinCommandInPipeline(_, s) => *s,
|
||||
ParseError::AssignInPipeline(_, _, _, s) => *s,
|
||||
ParseError::LetBuiltinVar(_, s) => *s,
|
||||
|
@ -18,13 +18,14 @@ pub const PLUGIN_DIRS_VAR: &str = "NU_PLUGIN_DIRS";
|
||||
|
||||
use crate::{
|
||||
eval::{eval_constant, value_as_string},
|
||||
is_math_expression_like,
|
||||
known_external::KnownExternal,
|
||||
lex,
|
||||
lite_parser::{lite_parse, LiteCommand, LiteElement},
|
||||
parser::{
|
||||
check_call, check_name, garbage, garbage_pipeline, parse, parse_call, parse_import_pattern,
|
||||
parse_internal_call, parse_multispan_value, parse_signature, parse_string, parse_value,
|
||||
parse_var_with_opt_type, trim_quotes, ParsedInternalCall,
|
||||
check_call, check_name, garbage, garbage_pipeline, parse, parse_call, parse_expression,
|
||||
parse_import_pattern, parse_internal_call, parse_multispan_value, parse_signature,
|
||||
parse_string, parse_value, parse_var_with_opt_type, trim_quotes, ParsedInternalCall,
|
||||
},
|
||||
unescape_unquote_string, ParseError, Token, TokenContents,
|
||||
};
|
||||
@ -798,6 +799,27 @@ pub fn parse_alias(
|
||||
|
||||
let replacement_spans = &spans[(split_id + 2)..];
|
||||
|
||||
if is_math_expression_like(working_set, replacement_spans[0], expand_aliases_denylist) {
|
||||
// TODO: Maybe we need to implement a Display trait for Expression?
|
||||
let (expr, _) = parse_expression(
|
||||
working_set,
|
||||
replacement_spans,
|
||||
expand_aliases_denylist,
|
||||
false,
|
||||
);
|
||||
|
||||
let msg = format!("{:?}", expr.expr);
|
||||
let msg_parts: Vec<&str> = msg.split('(').collect();
|
||||
|
||||
return (
|
||||
alias_pipeline,
|
||||
Some(ParseError::CantAliasExpression(
|
||||
msg_parts[0].to_string(),
|
||||
replacement_spans[0],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
let (expr, err) = parse_call(
|
||||
working_set,
|
||||
replacement_spans,
|
||||
|
Reference in New Issue
Block a user