mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-04 02:39:22 +00:00
Rename unconventional nodes (#74)
This commit is contained in:
parent
5270020423
commit
69d27d924c
19 changed files with 2407 additions and 2302 deletions
|
@ -31,6 +31,14 @@ BUILTIN_INT_NAMES = {
|
|||
"conversion": "ConversionFlag",
|
||||
}
|
||||
|
||||
RENAME_MAP = {
|
||||
"cmpop": "cmp_op",
|
||||
"unaryop": "unary_op",
|
||||
"boolop": "bool_op",
|
||||
"excepthandler": "except_handler",
|
||||
"withitem": "with_item",
|
||||
}
|
||||
|
||||
RUST_KEYWORDS = {
|
||||
"if",
|
||||
"while",
|
||||
|
@ -124,6 +132,7 @@ def rust_type_name(name):
|
|||
|
||||
This function special cases the default types provided by asdl.
|
||||
"""
|
||||
name = RENAME_MAP.get(name, name)
|
||||
if name in asdl.builtin_types:
|
||||
builtin = BUILTIN_TYPE_NAMES[name]
|
||||
return builtin
|
||||
|
@ -444,7 +453,9 @@ class StructVisitor(EmitVisitor):
|
|||
def visitType(self, type, depth=0):
|
||||
if hasattr(type, "doc"):
|
||||
doc = "/// " + type.doc.replace("\n", "\n/// ") + "\n"
|
||||
self.emit(doc, depth)
|
||||
else:
|
||||
doc = f"/// See also [{type.name}](https://docs.python.org/3/library/ast.html#ast.{type.name})"
|
||||
self.emit(doc, depth)
|
||||
self.visit(type.value, type, depth)
|
||||
|
||||
def visitSum(self, sum, type, depth):
|
||||
|
@ -525,11 +536,6 @@ class StructVisitor(EmitVisitor):
|
|||
def sum_with_constructors(self, sum, type, depth):
|
||||
type_info = self.type_info[type.name]
|
||||
rust_name = rust_type_name(type.name)
|
||||
# all the attributes right now are for location, so if it has attrs we
|
||||
# can just wrap it in Attributed<>
|
||||
|
||||
for t in sum.types:
|
||||
self.sum_subtype_struct(type_info, t, rust_name, depth)
|
||||
|
||||
self.emit_attrs(depth)
|
||||
self.emit("#[derive(is_macro::Is)]", depth)
|
||||
|
@ -545,7 +551,12 @@ class StructVisitor(EmitVisitor):
|
|||
self.emit("}", depth)
|
||||
self.emit("", depth)
|
||||
|
||||
for t in sum.types:
|
||||
self.sum_subtype_struct(type_info, t, rust_name, depth)
|
||||
|
||||
|
||||
def sum_subtype_struct(self, sum_type_info, t, rust_name, depth):
|
||||
self.emit(f"""/// See also [{t.name}](https://docs.python.org/3/library/ast.html#ast.{t.name})""", depth)
|
||||
self.emit_attrs(depth)
|
||||
payload_name = f"{rust_name}{t.name}"
|
||||
self.emit(f"pub struct {payload_name}<R = TextRange> {{", depth)
|
||||
|
|
|
@ -390,16 +390,16 @@ pub trait Fold<U> {
|
|||
fn fold_expr_context(&mut self, node: ExprContext) -> Result<ExprContext, Self::Error> {
|
||||
fold_expr_context(self, node)
|
||||
}
|
||||
fn fold_boolop(&mut self, node: Boolop) -> Result<Boolop, Self::Error> {
|
||||
fn fold_boolop(&mut self, node: BoolOp) -> Result<BoolOp, Self::Error> {
|
||||
fold_boolop(self, node)
|
||||
}
|
||||
fn fold_operator(&mut self, node: Operator) -> Result<Operator, Self::Error> {
|
||||
fold_operator(self, node)
|
||||
}
|
||||
fn fold_unaryop(&mut self, node: Unaryop) -> Result<Unaryop, Self::Error> {
|
||||
fn fold_unaryop(&mut self, node: UnaryOp) -> Result<UnaryOp, Self::Error> {
|
||||
fold_unaryop(self, node)
|
||||
}
|
||||
fn fold_cmpop(&mut self, node: Cmpop) -> Result<Cmpop, Self::Error> {
|
||||
fn fold_cmpop(&mut self, node: CmpOp) -> Result<CmpOp, Self::Error> {
|
||||
fold_cmpop(self, node)
|
||||
}
|
||||
fn fold_comprehension(
|
||||
|
@ -410,14 +410,14 @@ pub trait Fold<U> {
|
|||
}
|
||||
fn fold_excepthandler(
|
||||
&mut self,
|
||||
node: Excepthandler<U>,
|
||||
) -> Result<Excepthandler<Self::TargetU>, Self::Error> {
|
||||
node: ExceptHandler<U>,
|
||||
) -> Result<ExceptHandler<Self::TargetU>, Self::Error> {
|
||||
fold_excepthandler(self, node)
|
||||
}
|
||||
fn fold_excepthandler_except_handler(
|
||||
&mut self,
|
||||
node: ExcepthandlerExceptHandler<U>,
|
||||
) -> Result<ExcepthandlerExceptHandler<Self::TargetU>, Self::Error> {
|
||||
node: ExceptHandlerExceptHandler<U>,
|
||||
) -> Result<ExceptHandlerExceptHandler<Self::TargetU>, Self::Error> {
|
||||
fold_excepthandler_except_handler(self, node)
|
||||
}
|
||||
fn fold_arguments(
|
||||
|
@ -435,7 +435,7 @@ pub trait Fold<U> {
|
|||
fn fold_alias(&mut self, node: Alias<U>) -> Result<Alias<Self::TargetU>, Self::Error> {
|
||||
fold_alias(self, node)
|
||||
}
|
||||
fn fold_withitem(&mut self, node: Withitem<U>) -> Result<Withitem<Self::TargetU>, Self::Error> {
|
||||
fn fold_withitem(&mut self, node: WithItem<U>) -> Result<WithItem<Self::TargetU>, Self::Error> {
|
||||
fold_withitem(self, node)
|
||||
}
|
||||
fn fold_match_case(
|
||||
|
@ -2210,8 +2210,8 @@ pub fn fold_expr_context<U, F: Fold<U> + ?Sized>(
|
|||
) -> Result<ExprContext, F::Error> {
|
||||
Ok(node)
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Boolop {
|
||||
type Mapped = Boolop;
|
||||
impl<T, U> Foldable<T, U> for BoolOp {
|
||||
type Mapped = BoolOp;
|
||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
|
@ -2221,8 +2221,8 @@ impl<T, U> Foldable<T, U> for Boolop {
|
|||
}
|
||||
pub fn fold_boolop<U, F: Fold<U> + ?Sized>(
|
||||
#[allow(unused)] folder: &mut F,
|
||||
node: Boolop,
|
||||
) -> Result<Boolop, F::Error> {
|
||||
node: BoolOp,
|
||||
) -> Result<BoolOp, F::Error> {
|
||||
Ok(node)
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Operator {
|
||||
|
@ -2240,8 +2240,8 @@ pub fn fold_operator<U, F: Fold<U> + ?Sized>(
|
|||
) -> Result<Operator, F::Error> {
|
||||
Ok(node)
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Unaryop {
|
||||
type Mapped = Unaryop;
|
||||
impl<T, U> Foldable<T, U> for UnaryOp {
|
||||
type Mapped = UnaryOp;
|
||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
|
@ -2251,12 +2251,12 @@ impl<T, U> Foldable<T, U> for Unaryop {
|
|||
}
|
||||
pub fn fold_unaryop<U, F: Fold<U> + ?Sized>(
|
||||
#[allow(unused)] folder: &mut F,
|
||||
node: Unaryop,
|
||||
) -> Result<Unaryop, F::Error> {
|
||||
node: UnaryOp,
|
||||
) -> Result<UnaryOp, F::Error> {
|
||||
Ok(node)
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Cmpop {
|
||||
type Mapped = Cmpop;
|
||||
impl<T, U> Foldable<T, U> for CmpOp {
|
||||
type Mapped = CmpOp;
|
||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
|
@ -2266,8 +2266,8 @@ impl<T, U> Foldable<T, U> for Cmpop {
|
|||
}
|
||||
pub fn fold_cmpop<U, F: Fold<U> + ?Sized>(
|
||||
#[allow(unused)] folder: &mut F,
|
||||
node: Cmpop,
|
||||
) -> Result<Cmpop, F::Error> {
|
||||
node: CmpOp,
|
||||
) -> Result<CmpOp, F::Error> {
|
||||
Ok(node)
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Comprehension<T> {
|
||||
|
@ -2304,8 +2304,8 @@ pub fn fold_comprehension<U, F: Fold<U> + ?Sized>(
|
|||
range,
|
||||
})
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Excepthandler<T> {
|
||||
type Mapped = Excepthandler<U>;
|
||||
impl<T, U> Foldable<T, U> for ExceptHandler<T> {
|
||||
type Mapped = ExceptHandler<U>;
|
||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
|
@ -2315,17 +2315,17 @@ impl<T, U> Foldable<T, U> for Excepthandler<T> {
|
|||
}
|
||||
pub fn fold_excepthandler<U, F: Fold<U> + ?Sized>(
|
||||
#[allow(unused)] folder: &mut F,
|
||||
node: Excepthandler<U>,
|
||||
) -> Result<Excepthandler<F::TargetU>, F::Error> {
|
||||
node: ExceptHandler<U>,
|
||||
) -> Result<ExceptHandler<F::TargetU>, F::Error> {
|
||||
let folded = match node {
|
||||
Excepthandler::ExceptHandler(cons) => {
|
||||
Excepthandler::ExceptHandler(Foldable::fold(cons, folder)?)
|
||||
ExceptHandler::ExceptHandler(cons) => {
|
||||
ExceptHandler::ExceptHandler(Foldable::fold(cons, folder)?)
|
||||
}
|
||||
};
|
||||
Ok(folded)
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for ExcepthandlerExceptHandler<T> {
|
||||
type Mapped = ExcepthandlerExceptHandler<U>;
|
||||
impl<T, U> Foldable<T, U> for ExceptHandlerExceptHandler<T> {
|
||||
type Mapped = ExceptHandlerExceptHandler<U>;
|
||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
|
@ -2335,9 +2335,9 @@ impl<T, U> Foldable<T, U> for ExcepthandlerExceptHandler<T> {
|
|||
}
|
||||
pub fn fold_excepthandler_except_handler<U, F: Fold<U> + ?Sized>(
|
||||
#[allow(unused)] folder: &mut F,
|
||||
node: ExcepthandlerExceptHandler<U>,
|
||||
) -> Result<ExcepthandlerExceptHandler<F::TargetU>, F::Error> {
|
||||
let ExcepthandlerExceptHandler {
|
||||
node: ExceptHandlerExceptHandler<U>,
|
||||
) -> Result<ExceptHandlerExceptHandler<F::TargetU>, F::Error> {
|
||||
let ExceptHandlerExceptHandler {
|
||||
type_,
|
||||
name,
|
||||
body,
|
||||
|
@ -2349,7 +2349,7 @@ pub fn fold_excepthandler_except_handler<U, F: Fold<U> + ?Sized>(
|
|||
let name = Foldable::fold(name, folder)?;
|
||||
let body = Foldable::fold(body, folder)?;
|
||||
let range = folder.map_user(range, context)?;
|
||||
Ok(ExcepthandlerExceptHandler {
|
||||
Ok(ExceptHandlerExceptHandler {
|
||||
type_,
|
||||
name,
|
||||
body,
|
||||
|
@ -2472,8 +2472,8 @@ pub fn fold_alias<U, F: Fold<U> + ?Sized>(
|
|||
range,
|
||||
})
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Withitem<T> {
|
||||
type Mapped = Withitem<U>;
|
||||
impl<T, U> Foldable<T, U> for WithItem<T> {
|
||||
type Mapped = WithItem<U>;
|
||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
|
@ -2483,9 +2483,9 @@ impl<T, U> Foldable<T, U> for Withitem<T> {
|
|||
}
|
||||
pub fn fold_withitem<U, F: Fold<U> + ?Sized>(
|
||||
#[allow(unused)] folder: &mut F,
|
||||
node: Withitem<U>,
|
||||
) -> Result<Withitem<F::TargetU>, F::Error> {
|
||||
let Withitem {
|
||||
node: WithItem<U>,
|
||||
) -> Result<WithItem<F::TargetU>, F::Error> {
|
||||
let WithItem {
|
||||
context_expr,
|
||||
optional_vars,
|
||||
range,
|
||||
|
@ -2494,7 +2494,7 @@ pub fn fold_withitem<U, F: Fold<U> + ?Sized>(
|
|||
let context_expr = Foldable::fold(context_expr, folder)?;
|
||||
let optional_vars = Foldable::fold(optional_vars, folder)?;
|
||||
let range = folder.map_user_cfg(range, context)?;
|
||||
Ok(Withitem {
|
||||
Ok(WithItem {
|
||||
context_expr,
|
||||
optional_vars,
|
||||
range,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -989,11 +989,11 @@ pub type ExprContextStore = crate::generic::ExprContextStore;
|
|||
|
||||
pub type ExprContextDel = crate::generic::ExprContextDel;
|
||||
|
||||
pub type Boolop = crate::generic::Boolop;
|
||||
pub type BoolOp = crate::generic::BoolOp;
|
||||
|
||||
pub type BoolopAnd = crate::generic::BoolopAnd;
|
||||
pub type BoolOpAnd = crate::generic::BoolOpAnd;
|
||||
|
||||
pub type BoolopOr = crate::generic::BoolopOr;
|
||||
pub type BoolOpOr = crate::generic::BoolOpOr;
|
||||
|
||||
pub type Operator = crate::generic::Operator;
|
||||
|
||||
|
@ -1023,37 +1023,37 @@ pub type OperatorBitAnd = crate::generic::OperatorBitAnd;
|
|||
|
||||
pub type OperatorFloorDiv = crate::generic::OperatorFloorDiv;
|
||||
|
||||
pub type Unaryop = crate::generic::Unaryop;
|
||||
pub type UnaryOp = crate::generic::UnaryOp;
|
||||
|
||||
pub type UnaryopInvert = crate::generic::UnaryopInvert;
|
||||
pub type UnaryOpInvert = crate::generic::UnaryOpInvert;
|
||||
|
||||
pub type UnaryopNot = crate::generic::UnaryopNot;
|
||||
pub type UnaryOpNot = crate::generic::UnaryOpNot;
|
||||
|
||||
pub type UnaryopUAdd = crate::generic::UnaryopUAdd;
|
||||
pub type UnaryOpUAdd = crate::generic::UnaryOpUAdd;
|
||||
|
||||
pub type UnaryopUSub = crate::generic::UnaryopUSub;
|
||||
pub type UnaryOpUSub = crate::generic::UnaryOpUSub;
|
||||
|
||||
pub type Cmpop = crate::generic::Cmpop;
|
||||
pub type CmpOp = crate::generic::CmpOp;
|
||||
|
||||
pub type CmpopEq = crate::generic::CmpopEq;
|
||||
pub type CmpOpEq = crate::generic::CmpOpEq;
|
||||
|
||||
pub type CmpopNotEq = crate::generic::CmpopNotEq;
|
||||
pub type CmpOpNotEq = crate::generic::CmpOpNotEq;
|
||||
|
||||
pub type CmpopLt = crate::generic::CmpopLt;
|
||||
pub type CmpOpLt = crate::generic::CmpOpLt;
|
||||
|
||||
pub type CmpopLtE = crate::generic::CmpopLtE;
|
||||
pub type CmpOpLtE = crate::generic::CmpOpLtE;
|
||||
|
||||
pub type CmpopGt = crate::generic::CmpopGt;
|
||||
pub type CmpOpGt = crate::generic::CmpOpGt;
|
||||
|
||||
pub type CmpopGtE = crate::generic::CmpopGtE;
|
||||
pub type CmpOpGtE = crate::generic::CmpOpGtE;
|
||||
|
||||
pub type CmpopIs = crate::generic::CmpopIs;
|
||||
pub type CmpOpIs = crate::generic::CmpOpIs;
|
||||
|
||||
pub type CmpopIsNot = crate::generic::CmpopIsNot;
|
||||
pub type CmpOpIsNot = crate::generic::CmpOpIsNot;
|
||||
|
||||
pub type CmpopIn = crate::generic::CmpopIn;
|
||||
pub type CmpOpIn = crate::generic::CmpOpIn;
|
||||
|
||||
pub type CmpopNotIn = crate::generic::CmpopNotIn;
|
||||
pub type CmpOpNotIn = crate::generic::CmpOpNotIn;
|
||||
|
||||
pub type Comprehension = crate::generic::Comprehension<SourceRange>;
|
||||
|
||||
|
@ -1070,23 +1070,23 @@ impl LocatedMut for Comprehension {
|
|||
}
|
||||
}
|
||||
|
||||
pub type Excepthandler = crate::generic::Excepthandler<SourceRange>;
|
||||
pub type ExceptHandler = crate::generic::ExceptHandler<SourceRange>;
|
||||
|
||||
pub type ExcepthandlerExceptHandler = crate::generic::ExcepthandlerExceptHandler<SourceRange>;
|
||||
pub type ExceptHandlerExceptHandler = crate::generic::ExceptHandlerExceptHandler<SourceRange>;
|
||||
|
||||
impl Located for ExcepthandlerExceptHandler {
|
||||
impl Located for ExceptHandlerExceptHandler {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
|
||||
impl LocatedMut for ExcepthandlerExceptHandler {
|
||||
impl LocatedMut for ExceptHandlerExceptHandler {
|
||||
fn range_mut(&mut self) -> &mut SourceRange {
|
||||
&mut self.range
|
||||
}
|
||||
}
|
||||
|
||||
impl Located for Excepthandler {
|
||||
impl Located for ExceptHandler {
|
||||
fn range(&self) -> SourceRange {
|
||||
match self {
|
||||
Self::ExceptHandler(node) => node.range(),
|
||||
|
@ -1094,7 +1094,7 @@ impl Located for Excepthandler {
|
|||
}
|
||||
}
|
||||
|
||||
impl LocatedMut for Excepthandler {
|
||||
impl LocatedMut for ExceptHandler {
|
||||
fn range_mut(&mut self) -> &mut SourceRange {
|
||||
match self {
|
||||
Self::ExceptHandler(node) => node.range_mut(),
|
||||
|
@ -1159,16 +1159,16 @@ impl LocatedMut for Alias {
|
|||
}
|
||||
}
|
||||
|
||||
pub type Withitem = crate::generic::Withitem<SourceRange>;
|
||||
pub type WithItem = crate::generic::WithItem<SourceRange>;
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Located for Withitem {
|
||||
impl Located for WithItem {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl LocatedMut for Withitem {
|
||||
impl LocatedMut for WithItem {
|
||||
fn range_mut(&mut self) -> &mut SourceRange {
|
||||
&mut self.range
|
||||
}
|
||||
|
|
|
@ -380,12 +380,12 @@ impl Ranged for crate::generic::Comprehension<TextRange> {
|
|||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExcepthandlerExceptHandler<TextRange> {
|
||||
impl Ranged for crate::generic::ExceptHandlerExceptHandler<TextRange> {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::Excepthandler {
|
||||
impl Ranged for crate::ExceptHandler {
|
||||
fn range(&self) -> TextRange {
|
||||
match self {
|
||||
Self::ExceptHandler(node) => node.range(),
|
||||
|
@ -415,7 +415,7 @@ impl Ranged for crate::generic::Alias<TextRange> {
|
|||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::Withitem<TextRange> {
|
||||
impl Ranged for crate::generic::WithItem<TextRange> {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
|
|
|
@ -665,38 +665,38 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
|||
self.generic_visit_expr_context(node)
|
||||
}
|
||||
fn generic_visit_expr_context(&mut self, node: ExprContext) {}
|
||||
fn visit_boolop(&mut self, node: Boolop) {
|
||||
fn visit_boolop(&mut self, node: BoolOp) {
|
||||
self.generic_visit_boolop(node)
|
||||
}
|
||||
fn generic_visit_boolop(&mut self, node: Boolop) {}
|
||||
fn generic_visit_boolop(&mut self, node: BoolOp) {}
|
||||
fn visit_operator(&mut self, node: Operator) {
|
||||
self.generic_visit_operator(node)
|
||||
}
|
||||
fn generic_visit_operator(&mut self, node: Operator) {}
|
||||
fn visit_unaryop(&mut self, node: Unaryop) {
|
||||
fn visit_unaryop(&mut self, node: UnaryOp) {
|
||||
self.generic_visit_unaryop(node)
|
||||
}
|
||||
fn generic_visit_unaryop(&mut self, node: Unaryop) {}
|
||||
fn visit_cmpop(&mut self, node: Cmpop) {
|
||||
fn generic_visit_unaryop(&mut self, node: UnaryOp) {}
|
||||
fn visit_cmpop(&mut self, node: CmpOp) {
|
||||
self.generic_visit_cmpop(node)
|
||||
}
|
||||
fn generic_visit_cmpop(&mut self, node: Cmpop) {}
|
||||
fn generic_visit_cmpop(&mut self, node: CmpOp) {}
|
||||
fn visit_comprehension(&mut self, node: Comprehension<R>) {
|
||||
self.generic_visit_comprehension(node)
|
||||
}
|
||||
fn generic_visit_comprehension(&mut self, node: Comprehension<R>) {}
|
||||
fn visit_excepthandler(&mut self, node: Excepthandler<R>) {
|
||||
fn visit_excepthandler(&mut self, node: ExceptHandler<R>) {
|
||||
self.generic_visit_excepthandler(node)
|
||||
}
|
||||
fn generic_visit_excepthandler(&mut self, node: Excepthandler<R>) {
|
||||
fn generic_visit_excepthandler(&mut self, node: ExceptHandler<R>) {
|
||||
match node {
|
||||
Excepthandler::ExceptHandler(data) => self.visit_excepthandler_except_handler(data),
|
||||
ExceptHandler::ExceptHandler(data) => self.visit_excepthandler_except_handler(data),
|
||||
}
|
||||
}
|
||||
fn visit_excepthandler_except_handler(&mut self, node: ExcepthandlerExceptHandler<R>) {
|
||||
fn visit_excepthandler_except_handler(&mut self, node: ExceptHandlerExceptHandler<R>) {
|
||||
self.generic_visit_excepthandler_except_handler(node)
|
||||
}
|
||||
fn generic_visit_excepthandler_except_handler(&mut self, node: ExcepthandlerExceptHandler<R>) {
|
||||
fn generic_visit_excepthandler_except_handler(&mut self, node: ExceptHandlerExceptHandler<R>) {
|
||||
if let Some(value) = node.type_ {
|
||||
self.visit_expr(*value);
|
||||
}
|
||||
|
@ -720,10 +720,10 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
|||
self.generic_visit_alias(node)
|
||||
}
|
||||
fn generic_visit_alias(&mut self, node: Alias<R>) {}
|
||||
fn visit_withitem(&mut self, node: Withitem<R>) {
|
||||
fn visit_withitem(&mut self, node: WithItem<R>) {
|
||||
self.generic_visit_withitem(node)
|
||||
}
|
||||
fn generic_visit_withitem(&mut self, node: Withitem<R>) {}
|
||||
fn generic_visit_withitem(&mut self, node: WithItem<R>) {}
|
||||
fn visit_match_case(&mut self, node: MatchCase<R>) {
|
||||
self.generic_visit_match_case(node)
|
||||
}
|
||||
|
|
|
@ -54,19 +54,19 @@ impl<R> Default for EmptyRange<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Cmpop {
|
||||
impl CmpOp {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Cmpop::Eq => "==",
|
||||
Cmpop::NotEq => "!=",
|
||||
Cmpop::Lt => "<",
|
||||
Cmpop::LtE => "<=",
|
||||
Cmpop::Gt => ">",
|
||||
Cmpop::GtE => ">=",
|
||||
Cmpop::Is => "is",
|
||||
Cmpop::IsNot => "is not",
|
||||
Cmpop::In => "in",
|
||||
Cmpop::NotIn => "not in",
|
||||
CmpOp::Eq => "==",
|
||||
CmpOp::NotEq => "!=",
|
||||
CmpOp::Lt => "<",
|
||||
CmpOp::LtE => "<=",
|
||||
CmpOp::Gt => ">",
|
||||
CmpOp::GtE => ">=",
|
||||
CmpOp::Is => "is",
|
||||
CmpOp::IsNot => "is not",
|
||||
CmpOp::In => "in",
|
||||
CmpOp::NotIn => "not in",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,4 +61,4 @@ static_assertions::assert_eq_size!(crate::Stmt, [u8; 136]);
|
|||
#[cfg(target_arch = "x86_64")]
|
||||
static_assertions::assert_eq_size!(crate::Pattern, [u8; 96]);
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
static_assertions::assert_eq_size!(crate::Excepthandler, [u8; 64]);
|
||||
static_assertions::assert_eq_size!(crate::ExceptHandler, [u8; 64]);
|
||||
|
|
|
@ -6,6 +6,14 @@
|
|||
//!
|
||||
//! [PythonArguments] is replaced by [Arguments]. The new [Arguments] type representation uses a new type
|
||||
//! [ArgWithDefault] to represent arguments with default values. See each type documentation for more details.
|
||||
//!
|
||||
//! A few top-level sum types are renamed to human friendly names.
|
||||
//! [CmpOp] refers `cmpop`
|
||||
//! [UnaryOp] refers `unaryop`
|
||||
//! [BoolOp] refers `boolop`
|
||||
//! [WithItem] refers `withitem`
|
||||
//! [ExceptHandler] refers `excepthandler`
|
||||
//!
|
||||
|
||||
mod builtin;
|
||||
mod generic;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
Arg, ArgWithDefault, Arguments, Boolop, Comprehension, Constant, ConversionFlag, Expr,
|
||||
Arg, ArgWithDefault, Arguments, BoolOp, Comprehension, Constant, ConversionFlag, Expr,
|
||||
Identifier, Operator, PythonArguments,
|
||||
};
|
||||
use std::fmt;
|
||||
|
@ -79,7 +79,7 @@ impl<'a> Unparser<'a> {
|
|||
values,
|
||||
range: _range,
|
||||
}) => {
|
||||
let (op, prec) = op_prec!(bin, op, Boolop, And("and", AND), Or("or", OR));
|
||||
let (op, prec) = op_prec!(bin, op, BoolOp, And("and", AND), Or("or", OR));
|
||||
group_if!(prec, {
|
||||
let mut first = true;
|
||||
for val in values {
|
||||
|
@ -138,7 +138,7 @@ impl<'a> Unparser<'a> {
|
|||
let (op, prec) = op_prec!(
|
||||
un,
|
||||
op,
|
||||
crate::Unaryop,
|
||||
crate::UnaryOp,
|
||||
Invert("~", FACTOR),
|
||||
Not("not ", NOT),
|
||||
UAdd("+", FACTOR),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue