mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Fix custom
This commit is contained in:
parent
904f5c8b37
commit
26aea4030e
5 changed files with 551 additions and 77 deletions
|
@ -344,14 +344,14 @@ class StructVisitor(EmitVisitor):
|
|||
depth,
|
||||
)
|
||||
|
||||
# if not sum_type_info.has_attributes:
|
||||
# self.emit('#[cfg(feature = "more-attributes")]', depth)
|
||||
# self.emit(f"impl Ranged for {payload_name}<TextRange> {{", depth)
|
||||
# self.emit("#[inline]", depth + 1)
|
||||
# self.emit("fn range(&self) -> TextRange {", depth + 1)
|
||||
# self.emit("self.custom", depth + 2)
|
||||
# self.emit("}", depth + 1)
|
||||
# self.emit("}", depth)
|
||||
if not sum_type_info.has_attributes:
|
||||
self.emit('#[cfg(feature = "more-attributes")]', depth)
|
||||
self.emit(f"impl<U> Custom<U> for {payload_name}<U> {{", depth)
|
||||
self.emit("#[inline]", depth + 1)
|
||||
self.emit("fn custom(self) -> U {", depth + 1)
|
||||
self.emit("self.custom", depth + 2)
|
||||
self.emit("}", depth + 1)
|
||||
self.emit("}", depth)
|
||||
self.emit("", depth)
|
||||
|
||||
def visitConstructor(self, cons, parent, depth):
|
||||
|
@ -402,13 +402,13 @@ class StructVisitor(EmitVisitor):
|
|||
self.emit_custom(product.attributes, depth + 1)
|
||||
self.emit("}", depth)
|
||||
|
||||
# self.emit('#[cfg(feature = "more-attributes")]', depth)
|
||||
# self.emit(f"impl Ranged for {product_name}<TextRange> {{", depth)
|
||||
# self.emit("#[inline]", depth + 1)
|
||||
# self.emit("fn range(&self) -> TextRange {", depth + 1)
|
||||
# self.emit("self.custom", depth + 2)
|
||||
# self.emit("}", depth + 1)
|
||||
# self.emit("}", depth)
|
||||
self.emit('#[cfg(feature = "more-attributes")]', depth)
|
||||
self.emit(f"impl<T> Custom<U> for {product_name}<U> {{", depth)
|
||||
self.emit("#[inline]", depth + 1)
|
||||
self.emit("fn custom(&self) -> U {", depth + 1)
|
||||
self.emit("self.custom", depth + 2)
|
||||
self.emit("}", depth + 1)
|
||||
self.emit("}", depth)
|
||||
self.emit("", depth)
|
||||
|
||||
|
||||
|
@ -421,14 +421,6 @@ class FoldTraitDefVisitor(EmitVisitor):
|
|||
"fn map_user(&mut self, user: U) -> Result<Self::TargetU, Self::Error>;",
|
||||
depth + 1,
|
||||
)
|
||||
self.emit(
|
||||
"""
|
||||
fn map_attributed<T>(&mut self, attributed: Attributed<T, U>) -> Result<Attributed<T, Self::TargetU>, Self::Error> where T: Ranged{
|
||||
let custom = self.map_user(attributed.custom)?;
|
||||
Ok(Attributed { custom, node: attributed.node })
|
||||
}""",
|
||||
depth + 1,
|
||||
)
|
||||
self.emit(
|
||||
"""
|
||||
fn fold<X: Foldable<U, Self::TargetU>>(&mut self, node: X) -> Result<X::Mapped, Self::Error> {
|
||||
|
@ -968,7 +960,7 @@ def write_ast_def(mod, type_info, f):
|
|||
|
||||
def write_fold_def(mod, type_info, f):
|
||||
f.write("""
|
||||
use crate::Ranged;
|
||||
use crate::generic::Custom;
|
||||
""")
|
||||
FoldModuleVisitor(f, type_info).visit(mod)
|
||||
|
||||
|
|
|
@ -204,44 +204,6 @@ impl std::fmt::Display for Constant {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Attributed<T, U = ()> {
|
||||
pub custom: U,
|
||||
pub node: T,
|
||||
}
|
||||
|
||||
impl<T, U> Attributed<T, U> {
|
||||
/// Returns the node
|
||||
#[inline]
|
||||
pub fn node(&self) -> &T {
|
||||
&self.node
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Attributed<T, ()> {
|
||||
/// Creates a new node that spans the position specified by `range`.
|
||||
pub fn new(node: impl Into<T>) -> Self {
|
||||
Self {
|
||||
custom: (),
|
||||
node: node.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes self and returns the node.
|
||||
#[inline]
|
||||
pub fn into_node(self) -> T {
|
||||
self.node
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> std::ops::Deref for Attributed<T, U> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.node
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -1,26 +1,12 @@
|
|||
// File automatically generated by ast/asdl_rs.py.
|
||||
|
||||
use crate::fold_helpers::Foldable;
|
||||
use crate::Ranged;
|
||||
use crate::generic::Custom;
|
||||
pub trait Fold<U> {
|
||||
type TargetU;
|
||||
type Error;
|
||||
fn map_user(&mut self, user: U) -> Result<Self::TargetU, Self::Error>;
|
||||
|
||||
fn map_attributed<T>(
|
||||
&mut self,
|
||||
attributed: Attributed<T, U>,
|
||||
) -> Result<Attributed<T, Self::TargetU>, Self::Error>
|
||||
where
|
||||
T: Ranged,
|
||||
{
|
||||
let custom = self.map_user(attributed.custom)?;
|
||||
Ok(Attributed {
|
||||
custom,
|
||||
node: attributed.node,
|
||||
})
|
||||
}
|
||||
|
||||
fn fold<X: Foldable<U, Self::TargetU>>(&mut self, node: X) -> Result<X::Mapped, Self::Error> {
|
||||
node.fold(self)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,14 @@ impl<U> From<ModModule<U>> for Mod<U> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<U> Custom<U> for ModModule<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ModInteractive<U> {
|
||||
pub body: Vec<Stmt<U>>,
|
||||
|
@ -31,6 +39,14 @@ impl<U> From<ModInteractive<U>> for Mod<U> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<U> Custom<U> for ModInteractive<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ModExpression<U> {
|
||||
pub body: Box<Expr<U>>,
|
||||
|
@ -46,6 +62,14 @@ impl<U> From<ModExpression<U>> for Mod<U> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<U> Custom<U> for ModExpression<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ModFunctionType<U> {
|
||||
pub argtypes: Vec<Expr<U>>,
|
||||
|
@ -62,6 +86,14 @@ impl<U> From<ModFunctionType<U>> for Mod<U> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<U> Custom<U> for ModFunctionType<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
pub enum Mod<U> {
|
||||
Module(ModModule<U>),
|
||||
|
@ -87,6 +119,13 @@ impl<U> From<StmtFunctionDef<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtFunctionDef<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAsyncFunctionDef<U> {
|
||||
pub name: Identifier,
|
||||
|
@ -104,6 +143,13 @@ impl<U> From<StmtAsyncFunctionDef<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtAsyncFunctionDef<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtClassDef<U> {
|
||||
pub name: Identifier,
|
||||
|
@ -120,6 +166,13 @@ impl<U> From<StmtClassDef<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtClassDef<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtReturn<U> {
|
||||
pub value: Option<Box<Expr<U>>>,
|
||||
|
@ -132,6 +185,13 @@ impl<U> From<StmtReturn<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtReturn<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtDelete<U> {
|
||||
pub targets: Vec<Expr<U>>,
|
||||
|
@ -144,6 +204,13 @@ impl<U> From<StmtDelete<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtDelete<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAssign<U> {
|
||||
pub targets: Vec<Expr<U>>,
|
||||
|
@ -158,6 +225,13 @@ impl<U> From<StmtAssign<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtAssign<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAugAssign<U> {
|
||||
pub target: Box<Expr<U>>,
|
||||
|
@ -172,6 +246,13 @@ impl<U> From<StmtAugAssign<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtAugAssign<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAnnAssign<U> {
|
||||
pub target: Box<Expr<U>>,
|
||||
|
@ -187,6 +268,13 @@ impl<U> From<StmtAnnAssign<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtAnnAssign<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtFor<U> {
|
||||
pub target: Box<Expr<U>>,
|
||||
|
@ -203,6 +291,13 @@ impl<U> From<StmtFor<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtFor<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAsyncFor<U> {
|
||||
pub target: Box<Expr<U>>,
|
||||
|
@ -219,6 +314,13 @@ impl<U> From<StmtAsyncFor<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtAsyncFor<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtWhile<U> {
|
||||
pub test: Box<Expr<U>>,
|
||||
|
@ -233,6 +335,13 @@ impl<U> From<StmtWhile<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtWhile<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtIf<U> {
|
||||
pub test: Box<Expr<U>>,
|
||||
|
@ -247,6 +356,13 @@ impl<U> From<StmtIf<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtIf<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtWith<U> {
|
||||
pub items: Vec<Withitem<U>>,
|
||||
|
@ -261,6 +377,13 @@ impl<U> From<StmtWith<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtWith<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAsyncWith<U> {
|
||||
pub items: Vec<Withitem<U>>,
|
||||
|
@ -275,6 +398,13 @@ impl<U> From<StmtAsyncWith<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtAsyncWith<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtMatch<U> {
|
||||
pub subject: Box<Expr<U>>,
|
||||
|
@ -288,6 +418,13 @@ impl<U> From<StmtMatch<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtMatch<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtRaise<U> {
|
||||
pub exc: Option<Box<Expr<U>>>,
|
||||
|
@ -301,6 +438,13 @@ impl<U> From<StmtRaise<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtRaise<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtTry<U> {
|
||||
pub body: Vec<Stmt<U>>,
|
||||
|
@ -316,6 +460,13 @@ impl<U> From<StmtTry<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtTry<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtTryStar<U> {
|
||||
pub body: Vec<Stmt<U>>,
|
||||
|
@ -331,6 +482,13 @@ impl<U> From<StmtTryStar<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtTryStar<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAssert<U> {
|
||||
pub test: Box<Expr<U>>,
|
||||
|
@ -344,6 +502,13 @@ impl<U> From<StmtAssert<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtAssert<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtImport<U> {
|
||||
pub names: Vec<Alias<U>>,
|
||||
|
@ -356,6 +521,13 @@ impl<U> From<StmtImport<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtImport<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtImportFrom<U> {
|
||||
pub module: Option<Identifier>,
|
||||
|
@ -370,6 +542,13 @@ impl<U> From<StmtImportFrom<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtImportFrom<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtGlobal<U> {
|
||||
pub names: Vec<Identifier>,
|
||||
|
@ -382,6 +561,13 @@ impl<U> From<StmtGlobal<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtGlobal<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtNonlocal<U> {
|
||||
pub names: Vec<Identifier>,
|
||||
|
@ -394,6 +580,13 @@ impl<U> From<StmtNonlocal<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtNonlocal<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtExpr<U> {
|
||||
pub value: Box<Expr<U>>,
|
||||
|
@ -406,6 +599,13 @@ impl<U> From<StmtExpr<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtExpr<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtPass<U> {
|
||||
pub custom: U,
|
||||
|
@ -417,6 +617,13 @@ impl<U> From<StmtPass<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtPass<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtBreak<U> {
|
||||
pub custom: U,
|
||||
|
@ -428,6 +635,13 @@ impl<U> From<StmtBreak<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtBreak<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtContinue<U> {
|
||||
pub custom: U,
|
||||
|
@ -439,6 +653,13 @@ impl<U> From<StmtContinue<U>> for Stmt<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for StmtContinue<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
pub enum Stmt<U> {
|
||||
#[is(name = "function_def_stmt")]
|
||||
|
@ -510,6 +731,13 @@ impl<U> From<ExprBoolOp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprBoolOp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprNamedExpr<U> {
|
||||
pub target: Box<Expr<U>>,
|
||||
|
@ -523,6 +751,13 @@ impl<U> From<ExprNamedExpr<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprNamedExpr<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprBinOp<U> {
|
||||
pub left: Box<Expr<U>>,
|
||||
|
@ -537,6 +772,13 @@ impl<U> From<ExprBinOp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprBinOp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprUnaryOp<U> {
|
||||
pub op: Unaryop,
|
||||
|
@ -550,6 +792,13 @@ impl<U> From<ExprUnaryOp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprUnaryOp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprLambda<U> {
|
||||
pub args: Box<Arguments<U>>,
|
||||
|
@ -563,6 +812,13 @@ impl<U> From<ExprLambda<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprLambda<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprIfExp<U> {
|
||||
pub test: Box<Expr<U>>,
|
||||
|
@ -577,6 +833,13 @@ impl<U> From<ExprIfExp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprIfExp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprDict<U> {
|
||||
pub keys: Vec<Option<Expr<U>>>,
|
||||
|
@ -590,6 +853,13 @@ impl<U> From<ExprDict<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprDict<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprSet<U> {
|
||||
pub elts: Vec<Expr<U>>,
|
||||
|
@ -602,6 +872,13 @@ impl<U> From<ExprSet<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprSet<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprListComp<U> {
|
||||
pub elt: Box<Expr<U>>,
|
||||
|
@ -615,6 +892,13 @@ impl<U> From<ExprListComp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprListComp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprSetComp<U> {
|
||||
pub elt: Box<Expr<U>>,
|
||||
|
@ -628,6 +912,13 @@ impl<U> From<ExprSetComp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprSetComp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprDictComp<U> {
|
||||
pub key: Box<Expr<U>>,
|
||||
|
@ -642,6 +933,13 @@ impl<U> From<ExprDictComp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprDictComp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprGeneratorExp<U> {
|
||||
pub elt: Box<Expr<U>>,
|
||||
|
@ -655,6 +953,13 @@ impl<U> From<ExprGeneratorExp<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprGeneratorExp<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprAwait<U> {
|
||||
pub value: Box<Expr<U>>,
|
||||
|
@ -667,6 +972,13 @@ impl<U> From<ExprAwait<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprAwait<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprYield<U> {
|
||||
pub value: Option<Box<Expr<U>>>,
|
||||
|
@ -679,6 +991,13 @@ impl<U> From<ExprYield<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprYield<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprYieldFrom<U> {
|
||||
pub value: Box<Expr<U>>,
|
||||
|
@ -691,6 +1010,13 @@ impl<U> From<ExprYieldFrom<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprYieldFrom<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprCompare<U> {
|
||||
pub left: Box<Expr<U>>,
|
||||
|
@ -705,6 +1031,13 @@ impl<U> From<ExprCompare<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprCompare<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprCall<U> {
|
||||
pub func: Box<Expr<U>>,
|
||||
|
@ -719,6 +1052,13 @@ impl<U> From<ExprCall<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprCall<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprFormattedValue<U> {
|
||||
pub value: Box<Expr<U>>,
|
||||
|
@ -733,6 +1073,13 @@ impl<U> From<ExprFormattedValue<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprFormattedValue<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprJoinedStr<U> {
|
||||
pub values: Vec<Expr<U>>,
|
||||
|
@ -745,6 +1092,13 @@ impl<U> From<ExprJoinedStr<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprJoinedStr<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprConstant<U> {
|
||||
pub value: Constant,
|
||||
|
@ -758,6 +1112,13 @@ impl<U> From<ExprConstant<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprConstant<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprAttribute<U> {
|
||||
pub value: Box<Expr<U>>,
|
||||
|
@ -772,6 +1133,13 @@ impl<U> From<ExprAttribute<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprAttribute<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprSubscript<U> {
|
||||
pub value: Box<Expr<U>>,
|
||||
|
@ -786,6 +1154,13 @@ impl<U> From<ExprSubscript<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprSubscript<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprStarred<U> {
|
||||
pub value: Box<Expr<U>>,
|
||||
|
@ -799,6 +1174,13 @@ impl<U> From<ExprStarred<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprStarred<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprName<U> {
|
||||
pub id: Identifier,
|
||||
|
@ -812,6 +1194,13 @@ impl<U> From<ExprName<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprName<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprList<U> {
|
||||
pub elts: Vec<Expr<U>>,
|
||||
|
@ -825,6 +1214,13 @@ impl<U> From<ExprList<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprList<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprTuple<U> {
|
||||
pub elts: Vec<Expr<U>>,
|
||||
|
@ -838,6 +1234,13 @@ impl<U> From<ExprTuple<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprTuple<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprSlice<U> {
|
||||
pub lower: Option<Box<Expr<U>>>,
|
||||
|
@ -852,6 +1255,13 @@ impl<U> From<ExprSlice<U>> for Expr<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExprSlice<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
pub enum Expr<U> {
|
||||
#[is(name = "bool_op_expr")]
|
||||
|
@ -973,6 +1383,13 @@ pub struct Comprehension<U> {
|
|||
#[cfg(not(feature = "more-attributes"))]
|
||||
pub custom: std::marker::PhantomData<U>,
|
||||
}
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<T> Custom<U> for Comprehension<U> {
|
||||
#[inline]
|
||||
fn custom(&self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExcepthandlerExceptHandler<U> {
|
||||
|
@ -988,6 +1405,13 @@ impl<U> From<ExcepthandlerExceptHandler<U>> for Excepthandler<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for ExcepthandlerExceptHandler<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
pub enum Excepthandler<U> {
|
||||
ExceptHandler(ExcepthandlerExceptHandler<U>),
|
||||
|
@ -1007,6 +1431,13 @@ pub struct Arguments<U> {
|
|||
#[cfg(not(feature = "more-attributes"))]
|
||||
pub custom: std::marker::PhantomData<U>,
|
||||
}
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<T> Custom<U> for Arguments<U> {
|
||||
#[inline]
|
||||
fn custom(&self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Arg<U> {
|
||||
|
@ -1015,6 +1446,13 @@ pub struct Arg<U> {
|
|||
pub type_comment: Option<String>,
|
||||
pub custom: U,
|
||||
}
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<T> Custom<U> for Arg<U> {
|
||||
#[inline]
|
||||
fn custom(&self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Keyword<U> {
|
||||
|
@ -1022,6 +1460,13 @@ pub struct Keyword<U> {
|
|||
pub value: Expr<U>,
|
||||
pub custom: U,
|
||||
}
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<T> Custom<U> for Keyword<U> {
|
||||
#[inline]
|
||||
fn custom(&self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Alias<U> {
|
||||
|
@ -1029,6 +1474,13 @@ pub struct Alias<U> {
|
|||
pub asname: Option<Identifier>,
|
||||
pub custom: U,
|
||||
}
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<T> Custom<U> for Alias<U> {
|
||||
#[inline]
|
||||
fn custom(&self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Withitem<U> {
|
||||
|
@ -1039,6 +1491,13 @@ pub struct Withitem<U> {
|
|||
#[cfg(not(feature = "more-attributes"))]
|
||||
pub custom: std::marker::PhantomData<U>,
|
||||
}
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<T> Custom<U> for Withitem<U> {
|
||||
#[inline]
|
||||
fn custom(&self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct MatchCase<U> {
|
||||
|
@ -1050,6 +1509,13 @@ pub struct MatchCase<U> {
|
|||
#[cfg(not(feature = "more-attributes"))]
|
||||
pub custom: std::marker::PhantomData<U>,
|
||||
}
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<T> Custom<U> for MatchCase<U> {
|
||||
#[inline]
|
||||
fn custom(&self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchValue<U> {
|
||||
|
@ -1063,6 +1529,13 @@ impl<U> From<PatternMatchValue<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchValue<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchSingleton<U> {
|
||||
pub value: Constant,
|
||||
|
@ -1075,6 +1548,13 @@ impl<U> From<PatternMatchSingleton<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchSingleton<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchSequence<U> {
|
||||
pub patterns: Vec<Pattern<U>>,
|
||||
|
@ -1087,6 +1567,13 @@ impl<U> From<PatternMatchSequence<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchSequence<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchMapping<U> {
|
||||
pub keys: Vec<Expr<U>>,
|
||||
|
@ -1101,6 +1588,13 @@ impl<U> From<PatternMatchMapping<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchMapping<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchClass<U> {
|
||||
pub cls: Box<Expr<U>>,
|
||||
|
@ -1116,6 +1610,13 @@ impl<U> From<PatternMatchClass<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchClass<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchStar<U> {
|
||||
pub name: Option<Identifier>,
|
||||
|
@ -1128,6 +1629,13 @@ impl<U> From<PatternMatchStar<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchStar<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchAs<U> {
|
||||
pub pattern: Option<Box<Pattern<U>>>,
|
||||
|
@ -1141,6 +1649,13 @@ impl<U> From<PatternMatchAs<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchAs<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchOr<U> {
|
||||
pub patterns: Vec<Pattern<U>>,
|
||||
|
@ -1153,6 +1668,13 @@ impl<U> From<PatternMatchOr<U>> for Pattern<U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> Custom<U> for PatternMatchOr<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
pub enum Pattern<U> {
|
||||
MatchValue(PatternMatchValue<U>),
|
||||
|
@ -1181,6 +1703,14 @@ impl<U> From<TypeIgnoreTypeIgnore<U>> for TypeIgnore<U> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl<U> Custom<U> for TypeIgnoreTypeIgnore<U> {
|
||||
#[inline]
|
||||
fn custom(self) -> U {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
pub enum TypeIgnore<U> {
|
||||
TypeIgnore(TypeIgnoreTypeIgnore<U>),
|
||||
|
|
|
@ -5,6 +5,10 @@ pub mod generic {
|
|||
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||
pub use crate::builtin::*;
|
||||
|
||||
pub trait Custom<U> {
|
||||
fn custom(self) -> U;
|
||||
}
|
||||
|
||||
include!("gen/generic.rs");
|
||||
}
|
||||
pub mod ranged;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue