Skip to content

Commit

Permalink
Remove Expr::MatchPattern (nushell#11367)
Browse files Browse the repository at this point in the history
# Description
Following from nushell#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`.
  • Loading branch information
IanManske authored and dmatos2012 committed Feb 20, 2024
1 parent 7860619 commit fa99c79
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 47 deletions.
1 change: 0 additions & 1 deletion crates/nu-cli/src/syntax_highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions crates/nu-command/src/formats/from/nuon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 0 additions & 4 deletions crates/nu-parser/src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];

Expand Down
15 changes: 1 addition & 14 deletions crates/nu-parser/src/parse_patterns.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use nu_protocol::{
ast::{Expr, Expression, MatchPattern, Pattern},
ast::{MatchPattern, Pattern},
engine::StateWorkingSet,
ParseError, Span, SyntaxShape, Type, VarId,
};
Expand All @@ -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);

Expand Down
8 changes: 1 addition & 7 deletions crates/nu-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion crates/nu-protocol/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions crates/nu-protocol/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ impl Expression {
}
false
}
Expr::MatchPattern(_) => false,
Expr::Operator(_) => false,
Expr::MatchBlock(_) => false,
Expr::Range(left, middle, right, ..) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions crates/nu-protocol/src/eval_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down
5 changes: 0 additions & 5 deletions crates/nu-protocol/src/syntax_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ pub enum SyntaxShape {
/// A block of matches, used by `match`
MatchBlock,

/// A match pattern, eg `{a: $foo}`
MatchPattern,

/// Nothing
Nothing,

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 0 additions & 4 deletions crates/nu-protocol/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub enum Type {
Int,
List(Box<Type>),
ListStream,
MatchPattern,
#[default]
Nothing,
Number,
Expand Down Expand Up @@ -110,7 +109,6 @@ impl Type {
Type::Binary => SyntaxShape::Binary,
Type::Custom(_) => SyntaxShape::Any,
Type::Signature => SyntaxShape::Signature,
Type::MatchPattern => SyntaxShape::MatchPattern,
}
}

Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
}
}
}
Expand Down

0 comments on commit fa99c79

Please sign in to comment.