Remove Expr::MatchPattern (#11367)

# Description
Following from #11356, it looks like `Expr::MatchPattern` is no longer
used in any way. This PR removes `Expr::MatchPattern` alongside
`Type::MatchPattern` and `SyntaxShape::MatchPattern`.

# User-Facing Changes
Breaking API change for `nu_protocol`.
This commit is contained in:
Ian Manske 2023-12-20 17:52:28 +00:00 committed by GitHub
parent 03ae01f11e
commit ff6a67d293
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 3 additions and 47 deletions

View File

@ -329,7 +329,6 @@ fn find_matching_block_end_in_expr(
Expr::ImportPattern(_) => None,
Expr::Overlay(_) => None,
Expr::Signature(_) => None,
Expr::MatchPattern(_) => None,
Expr::MatchBlock(_) => None,
Expr::Nothing => None,
Expr::Garbage => None,

View File

@ -242,12 +242,6 @@ fn convert_to_value(
msg: "extra tokens in input file".into(),
span: expr.span,
}),
Expr::MatchPattern(..) => Err(ShellError::OutsideSpannedLabeledError {
src: original_text.to_string(),
error: "Error when loading".into(),
msg: "extra tokens in input file".into(),
span: expr.span,
}),
Expr::GlobPattern(val) => Ok(Value::string(val, span)),
Expr::ImportPattern(..) => Err(ShellError::OutsideSpannedLabeledError {
src: original_text.to_string(),

View File

@ -264,10 +264,6 @@ pub fn flatten_expression(
Expr::Float(_) => {
vec![(expr.span, FlatShape::Float)]
}
Expr::MatchPattern(pattern) => {
// FIXME: do nicer flattening later
flatten_pattern(pattern)
}
Expr::MatchBlock(matches) => {
let mut output = vec![];

View File

@ -1,5 +1,5 @@
use nu_protocol::{
ast::{Expr, Expression, MatchPattern, Pattern},
ast::{MatchPattern, Pattern},
engine::StateWorkingSet,
ParseError, Span, SyntaxShape, Type, VarId,
};
@ -18,19 +18,6 @@ pub fn garbage(span: Span) -> MatchPattern {
}
}
pub fn parse_match_pattern(working_set: &mut StateWorkingSet, span: Span) -> Expression {
working_set.enter_scope();
let output = parse_pattern(working_set, span);
working_set.exit_scope();
Expression {
expr: Expr::MatchPattern(Box::new(output)),
span,
ty: Type::Any,
custom_completion: None,
}
}
pub fn parse_pattern(working_set: &mut StateWorkingSet, span: Span) -> MatchPattern {
let bytes = working_set.get_span_contents(span);

View File

@ -2,7 +2,7 @@ use crate::{
lex::{lex, lex_signature},
lite_parser::{lite_parse, LiteCommand, LiteElement, LitePipeline},
parse_mut,
parse_patterns::{parse_match_pattern, parse_pattern},
parse_patterns::parse_pattern,
parse_shape_specs::{parse_shape_name, parse_type, ShapeDescriptorUse},
type_check::{self, math_result_type, type_compatible},
Token, TokenContents,
@ -4475,10 +4475,6 @@ pub fn parse_value(
_ => {}
}
if matches!(shape, SyntaxShape::MatchPattern) {
return parse_match_pattern(working_set, span);
}
match bytes[0] {
b'$' => return parse_dollar_expr(working_set, span),
b'(' => return parse_paren_expr(working_set, span, shape),
@ -4516,7 +4512,6 @@ pub fn parse_value(
SyntaxShape::GlobPattern => parse_glob_pattern(working_set, span),
SyntaxShape::String => parse_string(working_set, span),
SyntaxShape::Binary => parse_binary(working_set, span),
SyntaxShape::MatchPattern => parse_match_pattern(working_set, span),
SyntaxShape::Signature => {
if bytes.starts_with(b"[") {
parse_signature(working_set, span)
@ -5960,7 +5955,6 @@ pub fn discover_captures_in_expr(
discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?;
}
}
Expr::MatchPattern(_) => {}
Expr::MatchBlock(match_block) => {
for match_ in match_block {
discover_captures_in_pattern(&match_.0, seen);

View File

@ -44,7 +44,6 @@ pub enum Expr {
Overlay(Option<BlockId>), // block ID of the overlay's origin module
Signature(Box<Signature>),
StringInterpolation(Vec<Expression>),
MatchPattern(Box<MatchPattern>),
Spread(Box<Expression>),
Nothing,
Garbage,

View File

@ -221,7 +221,6 @@ impl Expression {
}
false
}
Expr::MatchPattern(_) => false,
Expr::Operator(_) => false,
Expr::MatchBlock(_) => false,
Expr::Range(left, middle, right, ..) => {
@ -407,7 +406,6 @@ impl Expression {
Expr::Nothing => {}
Expr::GlobPattern(_) => {}
Expr::Int(_) => {}
Expr::MatchPattern(_) => {}
Expr::MatchBlock(_) => {}
Expr::Keyword(_, _, expr) => expr.replace_in_variable(working_set, new_var_id),
Expr::List(list) => {
@ -576,7 +574,6 @@ impl Expression {
Expr::Garbage => {}
Expr::Nothing => {}
Expr::GlobPattern(_) => {}
Expr::MatchPattern(_) => {}
Expr::MatchBlock(_) => {}
Expr::Int(_) => {}
Expr::Keyword(_, _, expr) => expr.replace_span(working_set, replaced, new_span),

View File

@ -277,8 +277,7 @@ pub trait Eval {
Expr::GlobPattern(pattern) => {
Self::eval_glob_pattern(state, mut_state, pattern.clone(), expr.span)
}
Expr::MatchPattern(_) // match patterns are handled directly by commands
| Expr::MatchBlock(_) // match blocks are handled by `match`
Expr::MatchBlock(_) // match blocks are handled by `match`
| Expr::VarDecl(_)
| Expr::ImportPattern(_)
| Expr::Signature(_)

View File

@ -82,9 +82,6 @@ pub enum SyntaxShape {
/// A block of matches, used by `match`
MatchBlock,
/// A match pattern, eg `{a: $foo}`
MatchPattern,
/// Nothing
Nothing,
@ -163,7 +160,6 @@ impl SyntaxShape {
}
SyntaxShape::Keyword(_, expr) => expr.to_type(),
SyntaxShape::MatchBlock => Type::Any,
SyntaxShape::MatchPattern => Type::Any,
SyntaxShape::MathExpression => Type::Any,
SyntaxShape::Nothing => Type::Nothing,
SyntaxShape::Number => Type::Number,
@ -240,7 +236,6 @@ impl Display for SyntaxShape {
SyntaxShape::MathExpression => write!(f, "variable"),
SyntaxShape::VarWithOptType => write!(f, "vardecl"),
SyntaxShape::Signature => write!(f, "signature"),
SyntaxShape::MatchPattern => write!(f, "match-pattern"),
SyntaxShape::MatchBlock => write!(f, "match-block"),
SyntaxShape::Expression => write!(f, "expression"),
SyntaxShape::Boolean => write!(f, "bool"),

View File

@ -24,7 +24,6 @@ pub enum Type {
Int,
List(Box<Type>),
ListStream,
MatchPattern,
#[default]
Nothing,
Number,
@ -110,7 +109,6 @@ impl Type {
Type::Binary => SyntaxShape::Binary,
Type::Custom(_) => SyntaxShape::Any,
Type::Signature => SyntaxShape::Signature,
Type::MatchPattern => SyntaxShape::MatchPattern,
}
}
@ -131,7 +129,6 @@ impl Type {
Type::Record(_) => String::from("record"),
Type::Table(_) => String::from("table"),
Type::List(_) => String::from("list"),
Type::MatchPattern => String::from("match-pattern"),
Type::Nothing => String::from("nothing"),
Type::Number => String::from("number"),
Type::String => String::from("string"),
@ -198,7 +195,6 @@ impl Display for Type {
Type::Binary => write!(f, "binary"),
Type::Custom(custom) => write!(f, "{custom}"),
Type::Signature => write!(f, "signature"),
Type::MatchPattern => write!(f, "match-pattern"),
}
}
}