fn transform(&self, item: RcExprPat) -> RcExpr {
        fn transform(
            repls: &PatternMatch<RcExpr>,
            item: RcExprPat,
            cache: &mut HashMap<u64, RcExpr>,
        ) -> RcExpr {
            if let Some(result) = cache.get(&hash(item.as_ref())) {
                return result.clone();
            }

            let og_span = item.span;
            let transformed: RcExpr = match item.as_ref() {
                ExprPat::VarPat(_) | ExprPat::ConstPat(_) | ExprPat::AnyPat(_) => {
                    match repls.map.get(&hash(item.as_ref())) {
                        Some(transformed) => transformed.clone(),

                        // A pattern can only be transformed into an expression if it has an
                        // expression replacement. Patterns are be validated before transformation,
                        // so this branch should never be hit.
                        None => unreachable!(),
                    }
                }

                ExprPat::Const(f) => rc_expr!(Expr::Const(*f), og_span),
                ExprPat::BinaryExpr(binary_expr) => rc_expr!(
                    Expr::BinaryExpr(BinaryExpr {
                        op: binary_expr.op,
                        lhs: transform(repls, binary_expr.lhs.clone(), cache),
                        rhs: transform(repls, binary_expr.rhs.clone(), cache),
                    }),
                    og_span
                ),
                ExprPat::UnaryExpr(unary_expr) => rc_expr!(
                    Expr::UnaryExpr(UnaryExpr {
                        op: unary_expr.op,
                        rhs: transform(repls, unary_expr.rhs.clone(), cache),
                    }),
                    og_span
                ),
                ExprPat::Parend(expr) => {
                    let inner = transform(repls, expr.clone(), cache);
                    rc_expr!(Expr::Parend(inner), og_span)
                }
                ExprPat::Bracketed(expr) => {
                    let inner = transform(repls, expr.clone(), cache);
                    rc_expr!(Expr::Bracketed(inner), og_span)
                }
            };

            let result = cache
                .entry(hash(item.as_ref()))
                .or_insert_with(|| transformed);
            result.clone()
        }

        // Expr pointer -> transformed expression. Assumes that transient expressions of the same
        // value are reference counters pointing to the same underlying expression. This is done
        // via common subexpression elimination during parsing.
        let mut cache = HashMap::new();
        transform(self, item, &mut cache)
    }
/// Transforms a pattern expression into an expression by replacing patterns with target
/// expressions known by the [`PatternMatch`].
///
/// This transformation can be used to apply a rule on an expression by transforming the RHS
/// using patterns matched between the LHS of the rule and the target expression.
///
/// [`PatternMatch`]: PatternMatch
Transforms a pattern expression into an expression by replacing patterns with target
expressions known by the [`PatternMatch`].

This transformation can be used to apply a rule on an expression by transforming the RHS
using patterns matched between the LHS of the rule and the target expression.


Transforms a pattern expression into an expression by replacing patterns with target expressions known by the [ ` PatternMatch ` ] . This transformation can be used to apply a rule on an expression by transforming the RHS using patterns matched between the LHS of the rule and the target expression .
fn transform(&self, item: RcExprPat) -> RcExpr {
        fn transform(
            repls: &PatternMatch<RcExpr>,
            item: RcExprPat,
            cache: &mut HashMap<u64, RcExpr>,
        ) -> RcExpr {
            if let Some(result) = cache.get(&hash(item.as_ref())) {
                return result.clone();
            }
            let og_span = item.span;
            let transformed: RcExpr = match item.as_ref() {
                ExprPat::VarPat(_) | ExprPat::ConstPat(_) | ExprPat::AnyPat(_) => {
                    match repls.map.get(&hash(item.as_ref())) {
                        Some(transformed) => transformed.clone(),
                        // A pattern can only be transformed into an expression if it has an
                        // expression replacement. Patterns are be validated before transformation,
                        // so this branch should never be hit.
                        None => unreachable!(),
                    }
                }
                ExprPat::Const(f) => rc_expr!(Expr::Const(*f), og_span),
                ExprPat::BinaryExpr(binary_expr) => rc_expr!(
                    Expr::BinaryExpr(BinaryExpr {
                        op: binary_expr.op,
                        lhs: transform(repls, binary_expr.lhs.clone(), cache),
                        rhs: transform(repls, binary_expr.rhs.clone(), cache),
                    }),
                    og_span
                ),
                ExprPat::UnaryExpr(unary_expr) => rc_expr!(
                    Expr::UnaryExpr(UnaryExpr {
                        op: unary_expr.op,
                        rhs: transform(repls, unary_expr.rhs.clone(), cache),
                    }),
                    og_span
                ),
                ExprPat::Parend(expr) => {
                    let inner = transform(repls, expr.clone(), cache);
                    rc_expr!(Expr::Parend(inner), og_span)
                }
                ExprPat::Bracketed(expr) => {
                    let inner = transform(repls, expr.clone(), cache);
                    rc_expr!(Expr::Bracketed(inner), og_span)
                }
            };
            let result = cache
                .entry(hash(item.as_ref()))
                .or_insert_with(|| transformed);
            result.clone()
        }
        // Expr pointer -> transformed expression. Assumes that transient expressions of the same
        // value are reference counters pointing to the same underlying expression. This is done
        // via common subexpression elimination during parsing.
        let mut cache = HashMap::new();
        transform(self, item, &mut cache)
    }
fn transform ( & self , item : RcExprPat ) -> RcExpr { fn transform ( repls : & PatternMatch < RcExpr > , item : RcExprPat , cache : & mut HashMap < u64 , RcExpr > , ) -> RcExpr { if let Some ( result ) = cache . get ( & hash ( item . as_ref ( ) ) ) { return result . clone ( ) ; } let og_span = item . span ; let transformed : RcExpr = match item . as_ref ( ) { ExprPat :: VarPat ( _ ) | ExprPat :: ConstPat ( _ ) | ExprPat :: AnyPat ( _ ) => { match repls . map . get ( & hash ( item . as_ref ( ) ) ) { Some ( transformed ) => transformed . clone ( ) , // A pattern can only be transformed into an expression if it has an // expression replacement. Patterns are be validated before transformation, // so this branch should never be hit. None => unreachable ! ( ) , } } ExprPat :: Const ( f ) => rc_expr ! ( Expr Const ( f ) og_span ) , ExprPat :: BinaryExpr ( binary_expr ) => rc_expr ! ( Expr BinaryExpr ( BinaryExpr { op binary_expr op lhs transform ( repls binary_expr lhs clone ( ) cache ) rhs transform ( repls binary_expr rhs clone ( ) cache ) } ) og_span ) , ExprPat :: UnaryExpr ( unary_expr ) => rc_expr ! ( Expr UnaryExpr ( UnaryExpr { op unary_expr op rhs transform ( repls unary_expr rhs clone ( ) cache ) } ) og_span ) , ExprPat :: Parend ( expr ) => { let inner = transform ( repls , expr . clone ( ) , cache ) ; rc_expr ! ( Expr Parend ( inner ) og_span ) } ExprPat :: Bracketed ( expr ) => { let inner = transform ( repls , expr . clone ( ) , cache ) ; rc_expr ! ( Expr Bracketed ( inner ) og_span ) } } ; let result = cache . entry ( hash ( item . as_ref ( ) ) ) . or_insert_with ( | | transformed ) ; result . clone ( ) } // Expr pointer -> transformed expression. Assumes that transient expressions of the same // value are reference counters pointing to the same underlying expression. This is done // via common subexpression elimination during parsing. let mut cache = HashMap :: new ( ) ; transform ( self , item , & mut cache ) }
Transforms a pattern expression into an expression by replacing patterns with target
expressions known by the [`PatternMatch`].
Transforms a pattern expression into an expression by replacing patterns with target expressions known by the [ ` PatternMatch ` ] .
&self
item
RcExprPat
&self
item
RcExprPat