forked from Rust-related/RustPython
Use format and cformat from rustpython-literal (#4968)
* Use `format` and `cformat` from `rustpython-literal` * Remove unused dependencies, use `rustpython-format`
This commit is contained in:
44
Cargo.lock
generated
44
Cargo.lock
generated
@@ -911,15 +911,6 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.53"
|
||||
@@ -1804,7 +1795,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruff_source_location"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119"
|
||||
source = "git+https://github.com/RustPython/Parser.git?rev=a983f4383fb1ad8c1c66acb1d5b0016e59f95a49#a983f4383fb1ad8c1c66acb1d5b0016e59f95a49"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"once_cell",
|
||||
@@ -1814,7 +1805,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruff_text_size"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119"
|
||||
source = "git+https://github.com/RustPython/Parser.git?rev=a983f4383fb1ad8c1c66acb1d5b0016e59f95a49#a983f4383fb1ad8c1c66acb1d5b0016e59f95a49"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
@@ -1872,8 +1863,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustpython-ast"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119"
|
||||
source = "git+https://github.com/RustPython/Parser.git?rev=a983f4383fb1ad8c1c66acb1d5b0016e59f95a49#a983f4383fb1ad8c1c66acb1d5b0016e59f95a49"
|
||||
dependencies = [
|
||||
"is-macro",
|
||||
"num-bigint",
|
||||
"rustpython-literal",
|
||||
"rustpython-parser-core",
|
||||
@@ -1909,13 +1901,12 @@ dependencies = [
|
||||
"libc",
|
||||
"lock_api",
|
||||
"num-bigint",
|
||||
"num-complex",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"radium",
|
||||
"rand",
|
||||
"rustpython-literal",
|
||||
"rustpython-format",
|
||||
"siphasher",
|
||||
"volatile",
|
||||
"widestring",
|
||||
@@ -1956,7 +1947,6 @@ dependencies = [
|
||||
name = "rustpython-derive-impl"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"itertools",
|
||||
"maplit",
|
||||
"once_cell",
|
||||
@@ -1978,6 +1968,18 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-format"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/RustPython/Parser.git?rev=a983f4383fb1ad8c1c66acb1d5b0016e59f95a49#a983f4383fb1ad8c1c66acb1d5b0016e59f95a49"
|
||||
dependencies = [
|
||||
"bitflags 2.2.1",
|
||||
"itertools",
|
||||
"num-bigint",
|
||||
"num-traits",
|
||||
"rustpython-literal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-jit"
|
||||
version = "0.2.0"
|
||||
@@ -1996,7 +1998,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustpython-literal"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119"
|
||||
source = "git+https://github.com/RustPython/Parser.git?rev=a983f4383fb1ad8c1c66acb1d5b0016e59f95a49#a983f4383fb1ad8c1c66acb1d5b0016e59f95a49"
|
||||
dependencies = [
|
||||
"hexf-parse",
|
||||
"lexical-parse-float",
|
||||
@@ -2007,7 +2009,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustpython-parser"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119"
|
||||
source = "git+https://github.com/RustPython/Parser.git?rev=a983f4383fb1ad8c1c66acb1d5b0016e59f95a49#a983f4383fb1ad8c1c66acb1d5b0016e59f95a49"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools",
|
||||
@@ -2029,12 +2031,8 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustpython-parser-core"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119"
|
||||
source = "git+https://github.com/RustPython/Parser.git?rev=a983f4383fb1ad8c1c66acb1d5b0016e59f95a49#a983f4383fb1ad8c1c66acb1d5b0016e59f95a49"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"lz4_flex",
|
||||
"num-bigint",
|
||||
"num-complex",
|
||||
"ruff_source_location",
|
||||
"ruff_text_size",
|
||||
]
|
||||
@@ -2069,7 +2067,6 @@ dependencies = [
|
||||
"foreign-types-shared",
|
||||
"gethostname",
|
||||
"hex",
|
||||
"hmac",
|
||||
"itertools",
|
||||
"libc",
|
||||
"libsqlite3-sys",
|
||||
@@ -2169,6 +2166,7 @@ dependencies = [
|
||||
"rustpython-compiler",
|
||||
"rustpython-compiler-core",
|
||||
"rustpython-derive",
|
||||
"rustpython-format",
|
||||
"rustpython-jit",
|
||||
"rustpython-literal",
|
||||
"rustpython-parser",
|
||||
|
||||
18
Cargo.toml
18
Cargo.toml
@@ -29,14 +29,16 @@ rustpython-pylib = { path = "pylib" }
|
||||
rustpython-stdlib = { path = "stdlib" }
|
||||
rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" }
|
||||
|
||||
rustpython-literal = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" }
|
||||
rustpython-parser-core = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" }
|
||||
rustpython-parser = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" }
|
||||
rustpython-ast = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" }
|
||||
# rustpython-literal = { path = "../RustPython-parser/literal" }
|
||||
# rustpython-parser-core = { path = "../RustPython-parser/core" }
|
||||
# rustpython-parser = { path = "../RustPython-parser/parser" }
|
||||
# rustpython-ast = { path = "../RustPython-parser/ast" }
|
||||
rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "a983f4383fb1ad8c1c66acb1d5b0016e59f95a49" }
|
||||
rustpython-parser-core = { git = "https://github.com/RustPython/Parser.git", rev = "a983f4383fb1ad8c1c66acb1d5b0016e59f95a49" }
|
||||
rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "a983f4383fb1ad8c1c66acb1d5b0016e59f95a49" }
|
||||
rustpython-ast = { git = "https://github.com/RustPython/Parser.git", rev = "a983f4383fb1ad8c1c66acb1d5b0016e59f95a49" }
|
||||
rustpython-format = { git = "https://github.com/RustPython/Parser.git", rev = "a983f4383fb1ad8c1c66acb1d5b0016e59f95a49" }
|
||||
#rustpython-literal = { path = "../RustPython-parser/literal" }
|
||||
#rustpython-parser-core = { path = "../RustPython-parser/core" }
|
||||
#rustpython-parser = { path = "../RustPython-parser/parser" }
|
||||
#rustpython-ast = { path = "../RustPython-parser/ast" }
|
||||
#rustpython-format = { path = "../RustPython-parser/format" }
|
||||
|
||||
ahash = "0.7.6"
|
||||
anyhow = "1.0.45"
|
||||
|
||||
@@ -11,7 +11,7 @@ license = "MIT"
|
||||
threading = ["parking_lot"]
|
||||
|
||||
[dependencies]
|
||||
rustpython-literal = { workspace = true }
|
||||
rustpython-format = { workspace = true }
|
||||
|
||||
ascii = { workspace = true }
|
||||
bitflags = { workspace = true }
|
||||
@@ -20,7 +20,6 @@ cfg-if = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
num-bigint = { workspace = true }
|
||||
num-complex = { workspace = true }
|
||||
num-traits = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
parking_lot = { workspace = true, optional = true }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1191
common/src/format.rs
1191
common/src/format.rs
File diff suppressed because it is too large
Load Diff
@@ -7,13 +7,11 @@ pub use macros::*;
|
||||
pub mod atomic;
|
||||
pub mod borrow;
|
||||
pub mod boxvec;
|
||||
pub mod cformat;
|
||||
pub mod cmp;
|
||||
#[cfg(any(unix, windows, target_os = "wasi"))]
|
||||
pub mod crt_fd;
|
||||
pub mod encodings;
|
||||
pub mod float_ops;
|
||||
pub mod format;
|
||||
pub mod hash;
|
||||
pub mod int;
|
||||
pub mod linked_list;
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::{
|
||||
hash::PyHash,
|
||||
};
|
||||
use ascii::AsciiString;
|
||||
use rustpython_format::CharLen;
|
||||
use std::ops::{Bound, RangeBounds};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -139,6 +140,12 @@ impl std::fmt::Display for BorrowedStr<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl CharLen for BorrowedStr<'_> {
|
||||
fn char_len(&self) -> usize {
|
||||
self.char_len()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_get_chars(s: &str, range: impl RangeBounds<usize>) -> Option<&str> {
|
||||
let mut chars = s.chars();
|
||||
let start = match range.start_bound() {
|
||||
|
||||
@@ -908,7 +908,7 @@ impl Compiler {
|
||||
| ast::ExprKind::UnaryOp(ast::ExprUnaryOp { .. }) => {
|
||||
return Err(self.error(CodegenErrorType::Delete("expression")))
|
||||
}
|
||||
_ => return Err(self.error(CodegenErrorType::Delete(expression.node.name()))),
|
||||
_ => return Err(self.error(CodegenErrorType::Delete(expression.node.python_name()))),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1823,7 +1823,7 @@ impl Compiler {
|
||||
ast::ExprKind::Starred { .. } => CodegenErrorType::SyntaxError(
|
||||
"starred assignment target must be in a list or tuple".to_owned(),
|
||||
),
|
||||
_ => CodegenErrorType::Assign(target.node.name()),
|
||||
_ => CodegenErrorType::Assign(target.node.python_name()),
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -1866,7 +1866,7 @@ impl Compiler {
|
||||
AugAssignKind::Attr { idx }
|
||||
}
|
||||
_ => {
|
||||
return Err(self.error(CodegenErrorType::Assign(target.node.name())));
|
||||
return Err(self.error(CodegenErrorType::Assign(target.node.python_name())));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ rustpython-compiler-core = { workspace = true }
|
||||
rustpython-parser-core = { workspace = true }
|
||||
rustpython-doc = { workspace = true }
|
||||
|
||||
indexmap = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
syn = { workspace = true, features = ["full", "extra-traits"] }
|
||||
|
||||
@@ -55,7 +55,6 @@ sha-1 = "0.10.0"
|
||||
sha2 = "0.10.2"
|
||||
sha3 = "0.10.1"
|
||||
blake2 = "0.10.4"
|
||||
hmac = "0.12.1"
|
||||
|
||||
## unicode stuff
|
||||
unicode_names2 = { workspace = true }
|
||||
|
||||
@@ -35,6 +35,7 @@ rustpython-parser = { workspace = true, optional = true }
|
||||
rustpython-compiler-core = { workspace = true }
|
||||
rustpython-parser-core = { workspace = true }
|
||||
rustpython-literal = { workspace = true }
|
||||
rustpython-format = { workspace = true }
|
||||
|
||||
ascii = { workspace = true }
|
||||
ahash = { workspace = true }
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::{PyInt, PyStrRef, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
class::PyClassImpl,
|
||||
common::format::FormatSpec,
|
||||
convert::{IntoPyException, ToPyObject, ToPyResult},
|
||||
function::OptionalArg,
|
||||
identifier,
|
||||
@@ -12,6 +11,7 @@ use crate::{
|
||||
};
|
||||
use num_bigint::Sign;
|
||||
use num_traits::Zero;
|
||||
use rustpython_format::FormatSpec;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
impl ToPyObject for bool {
|
||||
|
||||
@@ -5,7 +5,6 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
class::PyClassImpl,
|
||||
common::format::FormatSpec,
|
||||
common::{float_ops, hash},
|
||||
convert::{IntoPyException, ToPyObject, ToPyResult},
|
||||
function::{
|
||||
@@ -22,6 +21,7 @@ use num_bigint::{BigInt, ToBigInt};
|
||||
use num_complex::Complex64;
|
||||
use num_rational::Ratio;
|
||||
use num_traits::{Signed, ToPrimitive, Zero};
|
||||
use rustpython_format::FormatSpec;
|
||||
|
||||
#[pyclass(module = false, name = "float")]
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::{
|
||||
bytesinner::PyBytesInner,
|
||||
class::PyClassImpl,
|
||||
common::{
|
||||
format::FormatSpec,
|
||||
hash,
|
||||
int::{bigint_to_finite_float, bytes_to_int},
|
||||
},
|
||||
@@ -22,6 +21,7 @@ use num_bigint::{BigInt, Sign};
|
||||
use num_integer::Integer;
|
||||
use num_rational::Ratio;
|
||||
use num_traits::{One, Pow, PrimInt, Signed, ToPrimitive, Zero};
|
||||
use rustpython_format::FormatSpec;
|
||||
use std::ops::{Div, Neg};
|
||||
use std::{fmt, ops::Not};
|
||||
|
||||
|
||||
@@ -7,10 +7,7 @@ use crate::{
|
||||
anystr::{self, adjust_indices, AnyStr, AnyStrContainer, AnyStrWrapper},
|
||||
atomic_func,
|
||||
class::PyClassImpl,
|
||||
common::{
|
||||
format::{FormatSpec, FormatString, FromTemplate},
|
||||
str::{BorrowedStr, PyStrKind, PyStrKindData},
|
||||
},
|
||||
common::str::{BorrowedStr, PyStrKind, PyStrKindData},
|
||||
convert::{IntoPyException, ToPyException, ToPyObject, ToPyResult},
|
||||
format::{format, format_map},
|
||||
function::{ArgIterable, ArgSize, FuncArgs, OptionalArg, OptionalOption, PyComparisonValue},
|
||||
@@ -37,6 +34,7 @@ use rustpython_common::{
|
||||
hash,
|
||||
lock::PyMutex,
|
||||
};
|
||||
use rustpython_format::{FormatSpec, FormatString, FromTemplate};
|
||||
use std::{char, fmt, ops::Range, string::ToString};
|
||||
use unic_ucd_bidi::BidiClass;
|
||||
use unic_ucd_category::GeneralCategory;
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::{
|
||||
builtins::{
|
||||
try_f64_to_bigint, tuple, PyBaseExceptionRef, PyByteArray, PyBytes, PyFloat, PyInt, PyStr,
|
||||
},
|
||||
common::cformat::*,
|
||||
function::ArgIntoFloat,
|
||||
protocol::PyBuffer,
|
||||
stdlib::builtins,
|
||||
@@ -13,6 +12,7 @@ use crate::{
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use rustpython_format::cformat::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
fn spec_format_bytes(
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use crate::{
|
||||
builtins::PyBaseExceptionRef,
|
||||
common::format::*,
|
||||
convert::{IntoPyException, ToPyException},
|
||||
function::FuncArgs,
|
||||
stdlib::builtins,
|
||||
PyObject, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
use rustpython_format::*;
|
||||
|
||||
impl IntoPyException for FormatSpecError {
|
||||
fn into_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef {
|
||||
match self {
|
||||
|
||||
@@ -8,13 +8,13 @@ mod _string {
|
||||
use crate::common::ascii;
|
||||
use crate::{
|
||||
builtins::{PyList, PyStrRef},
|
||||
common::format::{
|
||||
FieldName, FieldNamePart, FieldType, FormatPart, FormatString, FromTemplate,
|
||||
},
|
||||
convert::ToPyException,
|
||||
convert::ToPyObject,
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use rustpython_format::{
|
||||
FieldName, FieldNamePart, FieldType, FormatPart, FormatString, FromTemplate,
|
||||
};
|
||||
use std::mem;
|
||||
|
||||
fn create_format_part(
|
||||
|
||||
Reference in New Issue
Block a user