Skip to content

Commit

Permalink
generate AsFormat and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszotten committed Aug 25, 2023
1 parent 2a81c5b commit 515f892
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
72 changes: 72 additions & 0 deletions crates/ruff_python_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,78 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExceptHandlerExceptHandler
}
}

impl FormatRule<ast::FormattedValue, PyFormatContext<'_>>
for crate::other::formatted_value::FormatFormattedValue
{
#[inline]
fn fmt(&self, node: &ast::FormattedValue, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::FormattedValue>::fmt(self, node, f)
}
}
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::FormattedValue {
type Format<'a> = FormatRefWithRule<
'a,
ast::FormattedValue,
crate::other::formatted_value::FormatFormattedValue,
PyFormatContext<'ast>,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::other::formatted_value::FormatFormattedValue::default(),
)
}
}
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::FormattedValue {
type Format = FormatOwnedWithRule<
ast::FormattedValue,
crate::other::formatted_value::FormatFormattedValue,
PyFormatContext<'ast>,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::other::formatted_value::FormatFormattedValue::default(),
)
}
}

impl FormatRule<ast::PartialString, PyFormatContext<'_>>
for crate::other::partial_string::FormatPartialString
{
#[inline]
fn fmt(&self, node: &ast::PartialString, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::PartialString>::fmt(self, node, f)
}
}
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::PartialString {
type Format<'a> = FormatRefWithRule<
'a,
ast::PartialString,
crate::other::partial_string::FormatPartialString,
PyFormatContext<'ast>,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::other::partial_string::FormatPartialString::default(),
)
}
}
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::PartialString {
type Format = FormatOwnedWithRule<
ast::PartialString,
crate::other::partial_string::FormatPartialString,
PyFormatContext<'ast>,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::other::partial_string::FormatPartialString::default(),
)
}
}

impl FormatRule<ast::PatternMatchValue, PyFormatContext<'_>>
for crate::pattern::pattern_match_value::FormatPatternMatchValue
{
Expand Down
12 changes: 12 additions & 0 deletions crates/ruff_python_formatter/src/other/formatted_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult;
use ruff_python_ast::FormattedValue;

#[derive(Default)]
pub struct FormatFormattedValue;

impl FormatNodeRule<FormattedValue> for FormatFormattedValue {
fn fmt_fields(&self, _item: &FormattedValue, _f: &mut PyFormatter) -> FormatResult<()> {
unreachable!("Handled inside of `FormatExprFString");
}
}
2 changes: 2 additions & 0 deletions crates/ruff_python_formatter/src/other/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ pub(crate) mod comprehension;
pub(crate) mod decorator;
pub(crate) mod elif_else_clause;
pub(crate) mod except_handler_except_handler;
pub(crate) mod formatted_value;
pub(crate) mod identifier;
pub(crate) mod keyword;
pub(crate) mod match_case;
pub(crate) mod parameter;
pub(crate) mod parameter_with_default;
pub(crate) mod parameters;
pub(crate) mod partial_string;
pub(crate) mod with_item;
12 changes: 12 additions & 0 deletions crates/ruff_python_formatter/src/other/partial_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult;
use ruff_python_ast::PartialString;

#[derive(Default)]
pub struct FormatPartialString;

impl FormatNodeRule<PartialString> for FormatPartialString {
fn fmt_fields(&self, _item: &PartialString, _f: &mut PyFormatter) -> FormatResult<()> {
unreachable!("Handled inside of `FormatExprFString");
}
}

0 comments on commit 515f892

Please sign in to comment.