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
Folds an argument, recursing into its children.
fold_owned_attribute
Folds an attribute, recursing into its children.
fold_owned_block
Folds a block, recursing into its children.
fold_owned_catch_clause
Folds a catch clause, recursing into its children.
fold_owned_class_member
Folds a class member, recursing into its children.
fold_owned_closure_use_var
Folds a closure use var, recursing into its children.
fold_owned_enum_member
Folds an enum member, recursing into its children.
fold_owned_expr
Folds an expression, recursing into its children.
fold_owned_match_arm
Folds a match arm, recursing into its children.
fold_owned_name
Folds a name, recursing into its children.
fold_owned_param
Folds a param, recursing into its children.
fold_owned_program
Folds a program, recursing into its children.
fold_owned_property_hook
Folds a property hook, recursing into its children.
fold_owned_stmt
Folds a statement, recursing into its children.
fold_owned_type_hint
Folds a type hint, recursing into its children.