Skip to content

Commit

Permalink
Revert that
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 23, 2023
1 parent 7c7990c commit 62857fc
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 3,898 deletions.
4 changes: 0 additions & 4 deletions crates/ruff_python_formatter/bar.py

This file was deleted.

8 changes: 0 additions & 8 deletions crates/ruff_python_formatter/foo.py

This file was deleted.

1 change: 0 additions & 1 deletion crates/ruff_python_formatter/src/comments/placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,6 @@ fn handle_match_case_comment<'a>(
comment: DecoratedComment<'a>,
match_case: &'a MatchCase,
) -> CommentPlacement<'a> {
println!("handle_match_case_comment: {:?}", comment);
if comment.line_position().is_end_of_line() && comment.start() < match_case.pattern.start() {
CommentPlacement::dangling(comment.enclosing_node(), comment)
} else {
Expand Down
8 changes: 2 additions & 6 deletions crates/ruff_python_formatter/src/pattern/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::expression::parentheses::parenthesized;
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::Pattern;
use std::slice;

use crate::prelude::*;

Expand All @@ -19,7 +17,7 @@ pub struct FormatPattern;

impl FormatRule<Pattern, PyFormatContext<'_>> for FormatPattern {
fn fmt(&self, item: &Pattern, f: &mut PyFormatter) -> FormatResult<()> {
let format_pattern = format_with(|f| match item {
match item {
Pattern::MatchValue(p) => p.format().fmt(f),
Pattern::MatchSingleton(p) => p.format().fmt(f),
Pattern::MatchSequence(p) => p.format().fmt(f),
Expand All @@ -28,9 +26,7 @@ impl FormatRule<Pattern, PyFormatContext<'_>> for FormatPattern {
Pattern::MatchStar(p) => p.format().fmt(f),
Pattern::MatchAs(p) => p.format().fmt(f),
Pattern::MatchOr(p) => p.format().fmt(f),
});

format_pattern.fmt(f)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchValue;

use crate::expression::parentheses::Parentheses;
use crate::{AsFormat, FormatNodeRule, PyFormatter};

#[derive(Default)]
pub struct FormatPatternMatchValue;

impl FormatNodeRule<PatternMatchValue> for FormatPatternMatchValue {
fn fmt_fields(&self, item: &PatternMatchValue, f: &mut PyFormatter) -> FormatResult<()> {
// TODO(charlie): Avoid double parentheses for parenthesized top-level `PatternMatchValue`.
let PatternMatchValue { value, range: _ } = item;
let formatted = value.format();
write!(f, [formatted])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,23 @@ match foo:
match foo:
case 1:
y = 0
case (1):
case ((1)):
y = 1
case ( # comment
1
(1)
):
y = 1
case (
# comment
1
(1)
):
y = 1
case (
1 # comment
(1) # comment
):
y = 1
case (
1
(1)
# comment
):
y = 1
Expand Down
36 changes: 1 addition & 35 deletions crates/ruff_python_parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -590,41 +590,7 @@ ClosedPattern: ast::Pattern = {

SequencePattern: ast::Pattern = {
// A single-item tuple is a special case: it's a group pattern, _not_ a sequence pattern.
// Expand the range to include the parentheses.
<location:@L> "(" <pattern:Pattern> ")" <end_location:@R> => match pattern {
ast::Pattern::MatchValue(pattern) => ast::Pattern::MatchValue(ast::PatternMatchValue {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchSingleton(pattern) => ast::Pattern::MatchSingleton(ast::PatternMatchSingleton {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchSequence(pattern) => ast::Pattern::MatchSequence(ast::PatternMatchSequence {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchMapping(pattern) => ast::Pattern::MatchMapping(ast::PatternMatchMapping {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchClass(pattern) => ast::Pattern::MatchClass(ast::PatternMatchClass {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchStar(pattern) => ast::Pattern::MatchStar(ast::PatternMatchStar {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchAs(pattern) => ast::Pattern::MatchAs(ast::PatternMatchAs {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchOr(pattern) => ast::Pattern::MatchOr(ast::PatternMatchOr {
range: (location..end_location).into(),
..pattern
}),
},
<location:@L> "(" <pattern:Pattern> ")" <end_location:@R> => pattern,
<location:@L> "(" ")" <end_location:@R> => ast::PatternMatchSequence {
patterns: vec![],
range: (location..end_location).into()
Expand Down
37 changes: 2 additions & 35 deletions crates/ruff_python_parser/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// auto-generated: "lalrpop 0.20.0"
// sha3: 674e8225f7210c11b2339bea117c3c1bd00b690d886377f57e63df2eb7208eb2
// sha3: 6ec03d3255ad27917601bff9ad0b1df5f8702124139879a78e7dca689ca1b113
use num_bigint::BigInt;
use ruff_text_size::TextSize;
use ruff_python_ast::{self as ast, Ranged, IpyEscapeKind};
Expand Down Expand Up @@ -34234,40 +34234,7 @@ fn __action105<
(_, end_location, _): (TextSize, TextSize, TextSize),
) -> ast::Pattern
{
match pattern {
ast::Pattern::MatchValue(pattern) => ast::Pattern::MatchValue(ast::PatternMatchValue {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchSingleton(pattern) => ast::Pattern::MatchSingleton(ast::PatternMatchSingleton {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchSequence(pattern) => ast::Pattern::MatchSequence(ast::PatternMatchSequence {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchMapping(pattern) => ast::Pattern::MatchMapping(ast::PatternMatchMapping {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchClass(pattern) => ast::Pattern::MatchClass(ast::PatternMatchClass {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchStar(pattern) => ast::Pattern::MatchStar(ast::PatternMatchStar {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchAs(pattern) => ast::Pattern::MatchAs(ast::PatternMatchAs {
range: (location..end_location).into(),
..pattern
}),
ast::Pattern::MatchOr(pattern) => ast::Pattern::MatchOr(ast::PatternMatchOr {
range: (location..end_location).into(),
..pattern
}),
}
pattern
}

#[allow(unused_variables)]
Expand Down
Loading

0 comments on commit 62857fc

Please sign in to comment.