File tree 9 files changed +773
-7
lines changed
9 files changed +773
-7
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,10 @@ license = "MIT"
11
11
default = [" constant-optimization" , " fold" ]
12
12
constant-optimization = [" fold" ]
13
13
fold = []
14
- unparse = [" rustpython-common " ]
14
+ unparse = [" rustpython-literal " ]
15
15
16
16
[dependencies ]
17
17
rustpython-compiler-core = { path = " ../core" , version = " 0.2.0" }
18
- rustpython-common = { path = " ../../common " , version = " 0.2.0" , optional = true }
18
+ rustpython-literal = { path = " ../literal " , version = " 0.2.0" , optional = true }
19
19
20
20
num-bigint = { workspace = true }
Original file line number Diff line number Diff line change @@ -35,17 +35,17 @@ impl From<BigInt> for Constant {
35
35
}
36
36
}
37
37
38
- #[ cfg( feature = "rustpython-common " ) ]
38
+ #[ cfg( feature = "rustpython-literal " ) ]
39
39
impl std:: fmt:: Display for Constant {
40
40
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
41
41
match self {
42
42
Constant :: None => f. pad ( "None" ) ,
43
43
Constant :: Bool ( b) => f. pad ( if * b { "True" } else { "False" } ) ,
44
- Constant :: Str ( s) => rustpython_common :: escape:: UnicodeEscape :: new_repr ( s. as_str ( ) )
44
+ Constant :: Str ( s) => rustpython_literal :: escape:: UnicodeEscape :: new_repr ( s. as_str ( ) )
45
45
. str_repr ( )
46
46
. write ( f) ,
47
47
Constant :: Bytes ( b) => {
48
- let escape = rustpython_common :: escape:: AsciiEscape :: new_repr ( b) ;
48
+ let escape = rustpython_literal :: escape:: AsciiEscape :: new_repr ( b) ;
49
49
let repr = escape. bytes_repr ( ) . to_string ( ) . unwrap ( ) ;
50
50
f. pad ( & repr)
51
51
}
@@ -64,7 +64,7 @@ impl std::fmt::Display for Constant {
64
64
f. write_str ( ")" )
65
65
}
66
66
}
67
- Constant :: Float ( fp) => f. pad ( & rustpython_common :: float_ops :: to_string ( * fp) ) ,
67
+ Constant :: Float ( fp) => f. pad ( & rustpython_literal :: float :: to_string ( * fp) ) ,
68
68
Constant :: Complex { real, imag } => {
69
69
if * real == 0.0 {
70
70
write ! ( f, "{imag}j" )
Original file line number Diff line number Diff line change @@ -511,7 +511,7 @@ impl<'a> Unparser<'a> {
511
511
} else {
512
512
self . p ( "f" ) ?;
513
513
let body = to_string_fmt ( |f| Unparser :: new ( f) . unparse_fstring_body ( values, is_spec) ) ;
514
- rustpython_common :: escape:: UnicodeEscape :: new_repr ( & body)
514
+ rustpython_literal :: escape:: UnicodeEscape :: new_repr ( & body)
515
515
. str_repr ( )
516
516
. write ( & mut self . f )
517
517
}
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " rustpython-literal"
3
+ version = " 0.2.0"
4
+ description = " Common literal handling utilities mostly useful for unparse and repr."
5
+ authors = [" RustPython Team" ]
6
+ edition = " 2021"
7
+ repository = " https://github.com/RustPython/RustPython"
8
+ license = " MIT"
9
+
10
+ [dependencies ]
11
+ num-traits = { workspace = true }
12
+
13
+ hexf-parse = " 0.2.1"
14
+ lexical-parse-float = { version = " 0.8.0" , features = [" format" ] }
15
+ unic-ucd-category = " 0.9"
16
+
17
+ [dev-dependencies ]
18
+ rand = { workspace = true }
Original file line number Diff line number Diff line change
1
+ use unic_ucd_category:: GeneralCategory ;
2
+
3
+ /// According to python following categories aren't printable:
4
+ /// * Cc (Other, Control)
5
+ /// * Cf (Other, Format)
6
+ /// * Cs (Other, Surrogate)
7
+ /// * Co (Other, Private Use)
8
+ /// * Cn (Other, Not Assigned)
9
+ /// * Zl Separator, Line ('\u2028', LINE SEPARATOR)
10
+ /// * Zp Separator, Paragraph ('\u2029', PARAGRAPH SEPARATOR)
11
+ /// * Zs (Separator, Space) other than ASCII space('\x20').
12
+ pub fn is_printable ( c : char ) -> bool {
13
+ let cat = GeneralCategory :: of ( c) ;
14
+ !( cat. is_other ( ) || cat. is_separator ( ) )
15
+ }
You can’t perform that action at this time.
0 commit comments