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§
- Fold
Owned - 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.