mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-03 18:29:04 +00:00
rustpython-literal
This commit is contained in:
parent
bd64603950
commit
80109b1fe0
9 changed files with 773 additions and 7 deletions
|
@ -35,17 +35,17 @@ impl From<BigInt> for Constant {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustpython-common")]
|
||||
#[cfg(feature = "rustpython-literal")]
|
||||
impl std::fmt::Display for Constant {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Constant::None => f.pad("None"),
|
||||
Constant::Bool(b) => f.pad(if *b { "True" } else { "False" }),
|
||||
Constant::Str(s) => rustpython_common::escape::UnicodeEscape::new_repr(s.as_str())
|
||||
Constant::Str(s) => rustpython_literal::escape::UnicodeEscape::new_repr(s.as_str())
|
||||
.str_repr()
|
||||
.write(f),
|
||||
Constant::Bytes(b) => {
|
||||
let escape = rustpython_common::escape::AsciiEscape::new_repr(b);
|
||||
let escape = rustpython_literal::escape::AsciiEscape::new_repr(b);
|
||||
let repr = escape.bytes_repr().to_string().unwrap();
|
||||
f.pad(&repr)
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ impl std::fmt::Display for Constant {
|
|||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
Constant::Float(fp) => f.pad(&rustpython_common::float_ops::to_string(*fp)),
|
||||
Constant::Float(fp) => f.pad(&rustpython_literal::float::to_string(*fp)),
|
||||
Constant::Complex { real, imag } => {
|
||||
if *real == 0.0 {
|
||||
write!(f, "{imag}j")
|
||||
|
|
|
@ -511,7 +511,7 @@ impl<'a> Unparser<'a> {
|
|||
} else {
|
||||
self.p("f")?;
|
||||
let body = to_string_fmt(|f| Unparser::new(f).unparse_fstring_body(values, is_spec));
|
||||
rustpython_common::escape::UnicodeEscape::new_repr(&body)
|
||||
rustpython_literal::escape::UnicodeEscape::new_repr(&body)
|
||||
.str_repr()
|
||||
.write(&mut self.f)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue