forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
64 lines (58 loc) · 2.38 KB
/
lib.rs
File metadata and controls
64 lines (58 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Compile a Python AST or source code into bytecode consumable by RustPython.
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
#![doc(html_root_url = "https://docs.rs/rustpython-compiler/")]
#[macro_use]
extern crate log;
type IndexMap<K, V> = indexmap::IndexMap<K, V, ahash::RandomState>;
type IndexSet<T> = indexmap::IndexSet<T, ahash::RandomState>;
pub mod compile;
pub mod error;
pub mod ir;
mod string_parser;
pub mod symboltable;
mod unparse;
pub use compile::CompileOpts;
use ruff_python_ast::Expr;
pub trait ToPythonName {
/// Returns a short name for the node suitable for use in error messages.
fn python_name(&self) -> &'static str;
}
impl ToPythonName for Expr {
fn python_name(&self) -> &'static str {
match self {
Expr::BoolOp { .. } | Expr::BinOp { .. } | Expr::UnaryOp { .. } => "operator",
Expr::Subscript { .. } => "subscript",
Expr::Await { .. } => "await expression",
Expr::Yield { .. } | Expr::YieldFrom { .. } => "yield expression",
Expr::Compare { .. } => "comparison",
Expr::Attribute { .. } => "attribute",
Expr::Call { .. } => "function call",
Expr::BooleanLiteral(b) => {
if b.value {
"True"
} else {
"False"
}
}
Expr::EllipsisLiteral(_) => "ellipsis",
Expr::NoneLiteral(_) => "None",
Expr::NumberLiteral(_) | Expr::BytesLiteral(_) | Expr::StringLiteral(_) => "literal",
Expr::Tuple(_) => "tuple",
Expr::List { .. } => "list",
Expr::Dict { .. } => "dict display",
Expr::Set { .. } => "set display",
Expr::ListComp { .. } => "list comprehension",
Expr::DictComp { .. } => "dict comprehension",
Expr::SetComp { .. } => "set comprehension",
Expr::Generator { .. } => "generator expression",
Expr::Starred { .. } => "starred",
Expr::Slice { .. } => "slice",
Expr::FString { .. } => "f-string expression",
Expr::Name { .. } => "name",
Expr::Lambda { .. } => "lambda",
Expr::If { .. } => "conditional expression",
Expr::Named { .. } => "named expression",
Expr::IpyEscapeCommand(_) => todo!(),
}
}
}