Enum mamba::generate::ast::node::Core

source ·
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

Fields

§from: Option<Box<Core>>
§import: Vec<Core>
§alias: Vec<Core>
§

ClassDef

Fields

§name: Box<Core>
§parent_names: Vec<Core>
§body: Box<Core>
§

FunctionCall

Fields

§function: Box<Core>
§args: Vec<Core>
§

PropertyCall

Fields

§object: Box<Core>
§property: Box<Core>
§

Id

Fields

§lit: String
§

Type

Fields

§lit: String
§generics: Vec<Core>
§

ExpressionType

Fields

§expr: Box<Core>
§ty: Box<Core>
§

Assign

Fields

§left: Box<Core>
§right: Box<Core>
§

VarDef

Fields

§var: Box<Core>
§expr: Option<Box<Core>>
§

FunDefOp

Fields

§arg: Vec<Core>
§body: Box<Core>
§

FunDef

Fields

§dec: Vec<String>
§arg: Vec<Core>
§body: Box<Core>
§

FunArg

Fields

§vararg: bool
§var: Box<Core>
§default: Option<Box<Core>>
§

AnonFun

Fields

§args: Vec<Core>
§body: Box<Core>
§

Block

Fields

§statements: Vec<Core>
§

Float

Fields

§float: String
§

Int

Fields

§int: String
§

ENum

Fields

§num: String
§exp: String
§

DocStr

Fields

§string: String
§

Str

Fields

§string: String
§

FStr

Fields

§string: String
§

Bool

Fields

§boolean: bool
§

Tuple

Fields

§elements: Vec<Core>
§

TupleLiteral

Fields

§elements: Vec<Core>
§

DictComprehension

Fields

§from: Box<Core>
§to: Box<Core>
§col: Box<Core>
§conds: Vec<Core>
§

Comprehension

Fields

§expr: Box<Core>
§col: Box<Core>
§conds: Vec<Core>
§

Dictionary

Fields

§elements: Vec<(Core, Core)>
§

Set

Fields

§elements: Vec<Core>
§

List

Fields

§elements: Vec<Core>
§

Index

Fields

§item: Box<Core>
§range: Box<Core>
§

Ge

Fields

§left: Box<Core>
§right: Box<Core>
§

Geq

Fields

§left: Box<Core>
§right: Box<Core>
§

Le

Fields

§left: Box<Core>
§right: Box<Core>
§

Leq

Fields

§left: Box<Core>
§right: Box<Core>
§

Not

Fields

§expr: Box<Core>
§

Is

Fields

§left: Box<Core>
§right: Box<Core>
§

IsN

Fields

§left: Box<Core>
§right: Box<Core>
§

Eq

Fields

§left: Box<Core>
§right: Box<Core>
§

Neq

Fields

§left: Box<Core>
§right: Box<Core>
§

IsA

Fields

§left: Box<Core>
§right: Box<Core>
§

And

Fields

§left: Box<Core>
§right: Box<Core>
§

Or

Fields

§left: Box<Core>
§right: Box<Core>
§

Add

Fields

§left: Box<Core>
§right: Box<Core>
§

AddU

Fields

§expr: Box<Core>
§

Sub

Fields

§left: Box<Core>
§right: Box<Core>
§

SubU

Fields

§expr: Box<Core>
§

Mul

Fields

§left: Box<Core>
§right: Box<Core>
§

Mod

Fields

§left: Box<Core>
§right: Box<Core>
§

Pow

Fields

§left: Box<Core>
§right: Box<Core>
§

Div

Fields

§left: Box<Core>
§right: Box<Core>
§

FDiv

Fields

§left: Box<Core>
§right: Box<Core>
§

Sqrt

Fields

§expr: Box<Core>
§

BAnd

Fields

§left: Box<Core>
§right: Box<Core>
§

BOr

Fields

§left: Box<Core>
§right: Box<Core>
§

BXOr

Fields

§left: Box<Core>
§right: Box<Core>
§

BOneCmpl

Fields

§expr: Box<Core>
§

BLShift

Fields

§left: Box<Core>
§right: Box<Core>
§

BRShift

Fields

§left: Box<Core>
§right: Box<Core>
§

For

Fields

§expr: Box<Core>
§col: Box<Core>
§body: Box<Core>
§

If

Fields

§cond: Box<Core>
§then: Box<Core>
§

IfElse

Fields

§cond: Box<Core>
§then: Box<Core>
§el: Box<Core>
§

Match

Fields

§expr: Box<Core>
§cases: Vec<Core>
§

Case

Fields

§expr: Box<Core>
§body: Box<Core>
§

Ternary

Fields

§cond: Box<Core>
§then: Box<Core>
§el: Box<Core>
§

KeyValue

Fields

§key: Box<Core>
§value: Box<Core>
§

While

Fields

§cond: Box<Core>
§body: Box<Core>
§

In

Fields

§left: Box<Core>
§right: Box<Core>
§

Break

§

Continue

§

Return

Fields

§expr: Box<Core>
§

UnderScore

§

Pass

§

None

§

Empty

§

TryExcept

Fields

§setup: Option<Box<Core>>
§attempt: Box<Core>
§except: Vec<Core>
§

ExceptId

Fields

§id: Box<Core>
§class: Box<Core>
§body: Box<Core>
§

Except

Fields

§class: Box<Core>
§body: Box<Core>
§

Raise

Fields

§error: Box<Core>
§

With

Fields

§resource: Box<Core>
§expr: Box<Core>
§

WithAs

Fields

§resource: Box<Core>
§alias: Box<Core>
§expr: Box<Core>

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

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");
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.