pub enum Core {
Show 79 variants
Import {
from: Option<Box<Core>>,
import: Vec<Core>,
alias: Vec<Core>,
},
ClassDef {
name: Box<Core>,
parent_names: Vec<Core>,
body: Box<Core>,
},
FunctionCall {
function: Box<Core>,
args: Vec<Core>,
},
PropertyCall {
object: Box<Core>,
property: Box<Core>,
},
Id {
lit: String,
},
Type {
lit: String,
generics: Vec<Core>,
},
ExpressionType {
expr: Box<Core>,
ty: Box<Core>,
},
Assign {
left: Box<Core>,
right: Box<Core>,
op: CoreOp,
},
VarDef {
var: Box<Core>,
ty: Option<Box<Core>>,
expr: Option<Box<Core>>,
},
FunDefOp {
op: CoreFunOp,
arg: Vec<Core>,
ty: Option<Box<Core>>,
body: Box<Core>,
},
FunDef {
dec: Vec<String>,
id: String,
arg: Vec<Core>,
ty: Option<Box<Core>>,
body: Box<Core>,
},
FunArg {
vararg: bool,
var: Box<Core>,
ty: Option<Box<Core>>,
default: Option<Box<Core>>,
},
AnonFun {
args: Vec<Core>,
body: Box<Core>,
},
Block {
statements: Vec<Core>,
},
Float {
float: String,
},
Int {
int: String,
},
ENum {
num: String,
exp: String,
},
DocStr {
string: String,
},
Str {
string: String,
},
FStr {
string: String,
},
Bool {
boolean: bool,
},
Tuple {
elements: Vec<Core>,
},
TupleLiteral {
elements: Vec<Core>,
},
DictComprehension {
from: Box<Core>,
to: Box<Core>,
col: Box<Core>,
conds: Vec<Core>,
},
Comprehension {
expr: Box<Core>,
col: Box<Core>,
conds: Vec<Core>,
},
Dictionary {
elements: Vec<(Core, Core)>,
},
Set {
elements: Vec<Core>,
},
List {
elements: Vec<Core>,
},
Index {
item: Box<Core>,
range: Box<Core>,
},
Ge {
left: Box<Core>,
right: Box<Core>,
},
Geq {
left: Box<Core>,
right: Box<Core>,
},
Le {
left: Box<Core>,
right: Box<Core>,
},
Leq {
left: Box<Core>,
right: Box<Core>,
},
Not {
expr: Box<Core>,
},
Is {
left: Box<Core>,
right: Box<Core>,
},
IsN {
left: Box<Core>,
right: Box<Core>,
},
Eq {
left: Box<Core>,
right: Box<Core>,
},
Neq {
left: Box<Core>,
right: Box<Core>,
},
IsA {
left: Box<Core>,
right: Box<Core>,
},
And {
left: Box<Core>,
right: Box<Core>,
},
Or {
left: Box<Core>,
right: Box<Core>,
},
Add {
left: Box<Core>,
right: Box<Core>,
},
AddU {
expr: Box<Core>,
},
Sub {
left: Box<Core>,
right: Box<Core>,
},
SubU {
expr: Box<Core>,
},
Mul {
left: Box<Core>,
right: Box<Core>,
},
Mod {
left: Box<Core>,
right: Box<Core>,
},
Pow {
left: Box<Core>,
right: Box<Core>,
},
Div {
left: Box<Core>,
right: Box<Core>,
},
FDiv {
left: Box<Core>,
right: Box<Core>,
},
Sqrt {
expr: Box<Core>,
},
BAnd {
left: Box<Core>,
right: Box<Core>,
},
BOr {
left: Box<Core>,
right: Box<Core>,
},
BXOr {
left: Box<Core>,
right: Box<Core>,
},
BOneCmpl {
expr: Box<Core>,
},
BLShift {
left: Box<Core>,
right: Box<Core>,
},
BRShift {
left: Box<Core>,
right: Box<Core>,
},
For {
expr: Box<Core>,
col: Box<Core>,
body: Box<Core>,
},
If {
cond: Box<Core>,
then: Box<Core>,
},
IfElse {
cond: Box<Core>,
then: Box<Core>,
el: Box<Core>,
},
Match {
expr: Box<Core>,
cases: Vec<Core>,
},
Case {
expr: Box<Core>,
body: Box<Core>,
},
Ternary {
cond: Box<Core>,
then: Box<Core>,
el: Box<Core>,
},
KeyValue {
key: Box<Core>,
value: Box<Core>,
},
While {
cond: Box<Core>,
body: Box<Core>,
},
In {
left: Box<Core>,
right: Box<Core>,
},
Break,
Continue,
Return {
expr: Box<Core>,
},
UnderScore,
Pass,
None,
Empty,
TryExcept {
setup: Option<Box<Core>>,
attempt: Box<Core>,
except: Vec<Core>,
},
ExceptId {
id: Box<Core>,
class: Box<Core>,
body: Box<Core>,
},
Except {
class: Box<Core>,
body: Box<Core>,
},
Raise {
error: Box<Core>,
},
With {
resource: Box<Core>,
expr: Box<Core>,
},
WithAs {
resource: Box<Core>,
alias: Box<Core>,
expr: Box<Core>,
},
}
Variants§
Import
ClassDef
FunctionCall
PropertyCall
Id
Type
ExpressionType
Assign
VarDef
FunDefOp
FunDef
FunArg
AnonFun
Block
Float
Int
ENum
DocStr
Str
FStr
Bool
Tuple
TupleLiteral
DictComprehension
Comprehension
Dictionary
Set
List
Index
Ge
Geq
Le
Leq
Not
Is
IsN
Eq
Neq
IsA
And
Or
Add
AddU
Sub
SubU
Mul
Mod
Pow
Div
FDiv
Sqrt
BAnd
BOr
BXOr
BOneCmpl
BLShift
BRShift
For
If
IfElse
Match
Case
Ternary
KeyValue
While
In
Break
Continue
Return
UnderScore
Pass
None
Empty
TryExcept
ExceptId
Except
Raise
With
WithAs
Trait Implementations§
source§impl Display for Core
impl Display for Core
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Convert Core to a String which represent python source code.
Takes Core nodes as-is, meaning that this should never panic, unless a certain generate.ast construct can still not be converted.
Examples
Writing a Return statement:
let core_node = Core::Return { expr: Box::from(Core::None) };
let py_source = format!("{core_node}");
assert_eq!(py_source, "return None\n");
Writing an If statement:
let core_node = Core::IfElse {
cond: Box::from(Core::Id { lit: String::from("a") }),
then: Box::from(Core::Str { string: String::from("b") }),
el: Box::from(Core::Str { string: String::from("c") })
};
assert_eq!(format!("{core_node}"), "if a: \n \"b\"\nelse: \n \"c\"\n");