mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-23 13:06:07 +00:00
Make AST nodes Clone-able
This commit is contained in:
parent
15e2ac3fd7
commit
9a1d0e9a41
3 changed files with 21 additions and 21 deletions
|
@ -190,7 +190,7 @@ class StructVisitor(TypeInfoEmitVisitor):
|
||||||
self.sum_with_constructors(sum, name, depth)
|
self.sum_with_constructors(sum, name, depth)
|
||||||
|
|
||||||
def emit_attrs(self, depth):
|
def emit_attrs(self, depth):
|
||||||
self.emit("#[derive(Debug, PartialEq)]", depth)
|
self.emit("#[derive(Clone, Debug, PartialEq)]", depth)
|
||||||
|
|
||||||
def simple_sum(self, sum, name, depth):
|
def simple_sum(self, sum, name, depth):
|
||||||
rustname = get_rust_type(name)
|
rustname = get_rust_type(name)
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub use crate::Location;
|
||||||
|
|
||||||
type Ident = String;
|
type Ident = String;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Located<T, U = ()> {
|
pub struct Located<T, U = ()> {
|
||||||
pub location: Location,
|
pub location: Location,
|
||||||
pub custom: U,
|
pub custom: U,
|
||||||
|
@ -24,7 +24,7 @@ impl<T> Located<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Mod<U = ()> {
|
pub enum Mod<U = ()> {
|
||||||
Module {
|
Module {
|
||||||
body: Vec<Stmt<U>>,
|
body: Vec<Stmt<U>>,
|
||||||
|
@ -42,7 +42,7 @@ pub enum Mod<U = ()> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum StmtKind<U = ()> {
|
pub enum StmtKind<U = ()> {
|
||||||
FunctionDef {
|
FunctionDef {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
|
@ -164,7 +164,7 @@ pub enum StmtKind<U = ()> {
|
||||||
}
|
}
|
||||||
pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
|
pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ExprKind<U = ()> {
|
pub enum ExprKind<U = ()> {
|
||||||
BoolOp {
|
BoolOp {
|
||||||
op: Boolop,
|
op: Boolop,
|
||||||
|
@ -281,20 +281,20 @@ pub enum ExprKind<U = ()> {
|
||||||
}
|
}
|
||||||
pub type Expr<U = ()> = Located<ExprKind<U>, U>;
|
pub type Expr<U = ()> = Located<ExprKind<U>, U>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ExprContext {
|
pub enum ExprContext {
|
||||||
Load,
|
Load,
|
||||||
Store,
|
Store,
|
||||||
Del,
|
Del,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Boolop {
|
pub enum Boolop {
|
||||||
And,
|
And,
|
||||||
Or,
|
Or,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Operator {
|
pub enum Operator {
|
||||||
Add,
|
Add,
|
||||||
Sub,
|
Sub,
|
||||||
|
@ -311,7 +311,7 @@ pub enum Operator {
|
||||||
FloorDiv,
|
FloorDiv,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Unaryop {
|
pub enum Unaryop {
|
||||||
Invert,
|
Invert,
|
||||||
Not,
|
Not,
|
||||||
|
@ -319,7 +319,7 @@ pub enum Unaryop {
|
||||||
USub,
|
USub,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Cmpop {
|
pub enum Cmpop {
|
||||||
Eq,
|
Eq,
|
||||||
NotEq,
|
NotEq,
|
||||||
|
@ -333,7 +333,7 @@ pub enum Cmpop {
|
||||||
NotIn,
|
NotIn,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Comprehension<U = ()> {
|
pub struct Comprehension<U = ()> {
|
||||||
pub target: Box<Expr<U>>,
|
pub target: Box<Expr<U>>,
|
||||||
pub iter: Box<Expr<U>>,
|
pub iter: Box<Expr<U>>,
|
||||||
|
@ -341,7 +341,7 @@ pub struct Comprehension<U = ()> {
|
||||||
pub is_async: usize,
|
pub is_async: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ExcepthandlerKind<U = ()> {
|
pub enum ExcepthandlerKind<U = ()> {
|
||||||
ExceptHandler {
|
ExceptHandler {
|
||||||
type_: Option<Box<Expr<U>>>,
|
type_: Option<Box<Expr<U>>>,
|
||||||
|
@ -351,7 +351,7 @@ pub enum ExcepthandlerKind<U = ()> {
|
||||||
}
|
}
|
||||||
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
|
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Arguments<U = ()> {
|
pub struct Arguments<U = ()> {
|
||||||
pub posonlyargs: Vec<Arg<U>>,
|
pub posonlyargs: Vec<Arg<U>>,
|
||||||
pub args: Vec<Arg<U>>,
|
pub args: Vec<Arg<U>>,
|
||||||
|
@ -362,7 +362,7 @@ pub struct Arguments<U = ()> {
|
||||||
pub defaults: Vec<Expr<U>>,
|
pub defaults: Vec<Expr<U>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct ArgData<U = ()> {
|
pub struct ArgData<U = ()> {
|
||||||
pub arg: Ident,
|
pub arg: Ident,
|
||||||
pub annotation: Option<Box<Expr<U>>>,
|
pub annotation: Option<Box<Expr<U>>>,
|
||||||
|
@ -370,34 +370,34 @@ pub struct ArgData<U = ()> {
|
||||||
}
|
}
|
||||||
pub type Arg<U = ()> = Located<ArgData<U>, U>;
|
pub type Arg<U = ()> = Located<ArgData<U>, U>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct KeywordData<U = ()> {
|
pub struct KeywordData<U = ()> {
|
||||||
pub arg: Option<Ident>,
|
pub arg: Option<Ident>,
|
||||||
pub value: Box<Expr<U>>,
|
pub value: Box<Expr<U>>,
|
||||||
}
|
}
|
||||||
pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
|
pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct AliasData {
|
pub struct AliasData {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub asname: Option<Ident>,
|
pub asname: Option<Ident>,
|
||||||
}
|
}
|
||||||
pub type Alias<U = ()> = Located<AliasData, U>;
|
pub type Alias<U = ()> = Located<AliasData, U>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Withitem<U = ()> {
|
pub struct Withitem<U = ()> {
|
||||||
pub context_expr: Box<Expr<U>>,
|
pub context_expr: Box<Expr<U>>,
|
||||||
pub optional_vars: Option<Box<Expr<U>>>,
|
pub optional_vars: Option<Box<Expr<U>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct MatchCase<U = ()> {
|
pub struct MatchCase<U = ()> {
|
||||||
pub pattern: Box<Pattern<U>>,
|
pub pattern: Box<Pattern<U>>,
|
||||||
pub guard: Option<Box<Expr<U>>>,
|
pub guard: Option<Box<Expr<U>>>,
|
||||||
pub body: Vec<Stmt<U>>,
|
pub body: Vec<Stmt<U>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum PatternKind<U = ()> {
|
pub enum PatternKind<U = ()> {
|
||||||
MatchValue {
|
MatchValue {
|
||||||
value: Box<Expr<U>>,
|
value: Box<Expr<U>>,
|
||||||
|
@ -432,7 +432,7 @@ pub enum PatternKind<U = ()> {
|
||||||
}
|
}
|
||||||
pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
|
pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum TypeIgnore {
|
pub enum TypeIgnore {
|
||||||
TypeIgnore { lineno: usize, tag: String },
|
TypeIgnore { lineno: usize, tag: String },
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
pub use rustpython_compiler_core::ConversionFlag;
|
pub use rustpython_compiler_core::ConversionFlag;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Constant {
|
pub enum Constant {
|
||||||
None,
|
None,
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue