Skip to main content

Module fold

Module fold 

Source
Expand description

Owned AST transformation via the FoldOwned trait.

FoldOwned is the transformation counterpart of super::visitor::OwnedVisitor. Where OwnedVisitor reads nodes in place, FoldOwned rebuilds them — reading from an input node (borrowed) and returning a new owned value. Override only the node types you want to change; all others are rebuilt identically by the default implementations (equivalent to Clone).

§Example

use php_ast::owned::fold::{FoldOwned, fold_owned_expr};
use php_ast::owned::{Expr, ExprKind};

struct NegateInts;

impl FoldOwned for NegateInts {
    fn fold_expr(&mut self, expr: &Expr) -> Expr {
        if let ExprKind::Int(n) = &expr.kind {
            return Expr { kind: ExprKind::Int(-n), span: expr.span };
        }
        fold_owned_expr(self, expr)
    }
}

Traits§

FoldOwned
Trait for transforming owned PHP AST nodes.

Functions§

fold_owned_arg
fold_owned_attribute
fold_owned_block
fold_owned_catch_clause
fold_owned_class_member
fold_owned_closure_use_var
fold_owned_enum_member
fold_owned_expr
fold_owned_match_arm
fold_owned_name
fold_owned_param
fold_owned_program
fold_owned_property_hook
fold_owned_stmt
fold_owned_type_hint