Introduce Token element (#7048)

This commit is contained in:
Micha Reiser 2023-09-02 10:05:47 +02:00 committed by GitHub
parent 2f3a950f6f
commit c05e4628b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 733 additions and 723 deletions

View file

@ -12,6 +12,6 @@ impl FormatNodeRule<PatternKeyword> for FormatPatternKeyword {
attr,
pattern,
} = item;
write!(f, [attr.format(), text("="), pattern.format()])
write!(f, [attr.format(), token("="), pattern.format()])
}
}

View file

@ -29,7 +29,7 @@ impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
write!(f, [space()])?;
}
write!(f, [text("as")])?;
write!(f, [token("as")])?;
let trailing_as_comments = comments.dangling(item);
if trailing_as_comments.is_empty() {
@ -45,7 +45,7 @@ impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
name.format().fmt(f)
} else {
debug_assert!(pattern.is_none());
text("_").fmt(f)
token("_").fmt(f)
}
}

View file

@ -130,7 +130,7 @@ impl Format<PyFormatContext<'_>> for RestPattern<'_> {
f,
[
leading_comments(self.comments),
text("**"),
token("**"),
self.identifier.format()
]
)
@ -156,7 +156,7 @@ impl Format<PyFormatContext<'_>> for KeyPatternPair<'_> {
f,
[group(&format_args![
self.key.format(),
text(":"),
token(":"),
space(),
self.pattern.format()
])]

View file

@ -35,7 +35,7 @@ impl FormatNodeRule<PatternMatchOr> for FormatPatternMatchOr {
[hard_line_break(), leading_comments(leading_value_comments)]
)?;
}
write!(f, [text("|"), space(), pattern.format()])?;
write!(f, [token("|"), space(), pattern.format()])?;
}
Ok(())

View file

@ -10,9 +10,9 @@ pub struct FormatPatternMatchSingleton;
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
fn fmt_fields(&self, item: &PatternMatchSingleton, f: &mut PyFormatter) -> FormatResult<()> {
match item.value {
Constant::None => text("None").fmt(f),
Constant::Bool(true) => text("True").fmt(f),
Constant::Bool(false) => text("False").fmt(f),
Constant::None => token("None").fmt(f),
Constant::Bool(true) => token("True").fmt(f),
Constant::Bool(false) => token("False").fmt(f),
_ => unreachable!(),
}
}

View file

@ -16,11 +16,11 @@ impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
let comments = f.context().comments().clone();
let dangling = comments.dangling(item);
write!(f, [text("*"), dangling_comments(dangling)])?;
write!(f, [token("*"), dangling_comments(dangling)])?;
match name {
Some(name) => write!(f, [name.format()]),
None => write!(f, [text("_")]),
None => write!(f, [token("_")]),
}
}