Skip to content

Commit

Permalink
Remove single string literal pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Sep 12, 2023
1 parent 60855f0 commit ea4b035
Show file tree
Hide file tree
Showing 3 changed files with 9,576 additions and 10,050 deletions.
21 changes: 3 additions & 18 deletions crates/ruff_python_parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,7 @@ LiteralPattern: ast::Pattern = {
value: Box::new(value.into()),
range: (location..end_location).into()
}.into(),
<location:@L> <string:StringLiteralOrFString> <end_location:@R> => ast::PatternMatchValue {
value: Box::new(string.with_range((location..end_location).into()).into()),
range: (location..end_location).into()
}.into(),
<location:@L> <strings:TwoOrMoreConsecutive<StringLiteralOrFString>> <end_location:@L> =>? Ok(ast::PatternMatchValue {
<location:@L> <strings:StringLiteralOrFString+> <end_location:@L> =>? Ok(ast::PatternMatchValue {
value: Box::new(concatenate_strings(strings, (location..end_location).into())?),
range: (location..end_location).into()
}.into()),
Expand Down Expand Up @@ -731,8 +727,7 @@ MappingKey: ast::Expr = {
value: false.into(),
range: (location..end_location).into()
}.into(),
<location:@L> <string:StringLiteralOrFString> <end_location:@R> => string.with_range((location..end_location).into()).into(),
<location:@L> <strings:TwoOrMoreConsecutive<StringLiteralOrFString>> <end_location:@L> =>? Ok(concatenate_strings(strings, (location..end_location).into())?),
<location:@L> <strings:StringLiteralOrFString+> <end_location:@L> =>? Ok(concatenate_strings(strings, (location..end_location).into())?),
}

MatchMappingEntry: (ast::Expr, ast::Pattern) = {
Expand Down Expand Up @@ -1671,8 +1666,7 @@ FStringConversion: (TextSize, ast::ConversionFlag) = {
};

Atom<Goal>: ast::ParenthesizedExpr = {
<location:@L> <string:StringLiteralOrFString> <end_location:@R> => string.with_range((location..end_location).into()).into(),
<location:@L> <strings:TwoOrMoreConsecutive<StringLiteralOrFString>> <end_location:@L> =>? Ok(concatenate_strings(strings, (location..end_location).into())?.into()),
<location:@L> <strings:StringLiteralOrFString+> <end_location:@L> =>? Ok(concatenate_strings(strings, (location..end_location).into())?.into()),
<location:@L> <value:Constant> <end_location:@R> => ast::ExprConstant {
value,
range: (location..end_location).into(),
Expand Down Expand Up @@ -1921,15 +1915,6 @@ TwoOrMore<T, Sep>: Vec<T> = {
}
};

/// Two or more consecutive items
TwoOrMoreConsecutive<T>: Vec<T> = {
<e1:T> <e2:T> => vec![e1, e2],
<mut v: TwoOrMoreConsecutive<T>> <e:T> => {
v.push(e);
v
}
};

Constant: ast::Constant = {
<value:int> => ast::Constant::Int(value),
<value:float> => ast::Constant::Float(value),
Expand Down
Loading

0 comments on commit ea4b035

Please sign in to comment.