mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-04 02:39:22 +00:00
Merge pull request #4218 from charliermarsh/charlie/clone
Make AST nodes Clone-able
This commit is contained in:
commit
48c0cb5599
3 changed files with 21 additions and 21 deletions
|
@ -190,7 +190,7 @@ class StructVisitor(TypeInfoEmitVisitor):
|
|||
self.sum_with_constructors(sum, name, 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):
|
||||
rustname = get_rust_type(name)
|
||||
|
|
|
@ -7,7 +7,7 @@ pub use crate::Location;
|
|||
|
||||
type Ident = String;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Located<T, U = ()> {
|
||||
pub location: Location,
|
||||
pub end_location: Option<Location>,
|
||||
|
@ -26,7 +26,7 @@ impl<T> Located<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Mod<U = ()> {
|
||||
Module {
|
||||
body: Vec<Stmt<U>>,
|
||||
|
@ -44,7 +44,7 @@ pub enum Mod<U = ()> {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum StmtKind<U = ()> {
|
||||
FunctionDef {
|
||||
name: Ident,
|
||||
|
@ -166,7 +166,7 @@ pub enum StmtKind<U = ()> {
|
|||
}
|
||||
pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ExprKind<U = ()> {
|
||||
BoolOp {
|
||||
op: Boolop,
|
||||
|
@ -283,20 +283,20 @@ pub enum ExprKind<U = ()> {
|
|||
}
|
||||
pub type Expr<U = ()> = Located<ExprKind<U>, U>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ExprContext {
|
||||
Load,
|
||||
Store,
|
||||
Del,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Boolop {
|
||||
And,
|
||||
Or,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Operator {
|
||||
Add,
|
||||
Sub,
|
||||
|
@ -313,7 +313,7 @@ pub enum Operator {
|
|||
FloorDiv,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Unaryop {
|
||||
Invert,
|
||||
Not,
|
||||
|
@ -321,7 +321,7 @@ pub enum Unaryop {
|
|||
USub,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Cmpop {
|
||||
Eq,
|
||||
NotEq,
|
||||
|
@ -335,7 +335,7 @@ pub enum Cmpop {
|
|||
NotIn,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Comprehension<U = ()> {
|
||||
pub target: Box<Expr<U>>,
|
||||
pub iter: Box<Expr<U>>,
|
||||
|
@ -343,7 +343,7 @@ pub struct Comprehension<U = ()> {
|
|||
pub is_async: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ExcepthandlerKind<U = ()> {
|
||||
ExceptHandler {
|
||||
type_: Option<Box<Expr<U>>>,
|
||||
|
@ -353,7 +353,7 @@ pub enum ExcepthandlerKind<U = ()> {
|
|||
}
|
||||
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Arguments<U = ()> {
|
||||
pub posonlyargs: Vec<Arg<U>>,
|
||||
pub args: Vec<Arg<U>>,
|
||||
|
@ -364,7 +364,7 @@ pub struct Arguments<U = ()> {
|
|||
pub defaults: Vec<Expr<U>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ArgData<U = ()> {
|
||||
pub arg: Ident,
|
||||
pub annotation: Option<Box<Expr<U>>>,
|
||||
|
@ -372,34 +372,34 @@ pub struct ArgData<U = ()> {
|
|||
}
|
||||
pub type Arg<U = ()> = Located<ArgData<U>, U>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct KeywordData<U = ()> {
|
||||
pub arg: Option<Ident>,
|
||||
pub value: Box<Expr<U>>,
|
||||
}
|
||||
pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct AliasData {
|
||||
pub name: Ident,
|
||||
pub asname: Option<Ident>,
|
||||
}
|
||||
pub type Alias<U = ()> = Located<AliasData, U>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Withitem<U = ()> {
|
||||
pub context_expr: Box<Expr<U>>,
|
||||
pub optional_vars: Option<Box<Expr<U>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct MatchCase<U = ()> {
|
||||
pub pattern: Box<Pattern<U>>,
|
||||
pub guard: Option<Box<Expr<U>>>,
|
||||
pub body: Vec<Stmt<U>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum PatternKind<U = ()> {
|
||||
MatchValue {
|
||||
value: Box<Expr<U>>,
|
||||
|
@ -434,7 +434,7 @@ pub enum PatternKind<U = ()> {
|
|||
}
|
||||
pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum TypeIgnore {
|
||||
TypeIgnore { lineno: usize, tag: String },
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use num_bigint::BigInt;
|
||||
pub use rustpython_compiler_core::ConversionFlag;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Constant {
|
||||
None,
|
||||
Bool(bool),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue