php-ast 0.26.0

PHP Abstract Syntax Tree (AST) node definitions
Documentation
//! AST type definitions and visitor infrastructure for the PHP parser.
//!
//! This crate provides:
//! - The complete set of AST node types ([`ast`] module) — statements, expressions, declarations,
//!   type hints, operators, and all other syntactic constructs for PHP 7.4–8.5, plus PHP 8.6
//!   partial function application (`?`/`...` call-argument placeholders).
//! - A [`Span`] type for tracking byte-offset ranges back to the source text.
//! - A [`visitor`] module with the [`visitor::Visitor`] and [`visitor::ScopeVisitor`] traits for
//!   depth-first AST traversal, plus free `walk_*` functions that drive the default recursion.
//! - A [`fold`] module with the [`fold::Fold`] trait for arena-to-arena AST transformation.
//! - An [`owned`] module with lifetime-free mirrors of every AST type, plus owned visitor and fold
//!   traits.
//! - A [`resolve::NameResolver`] that resolves names to fully qualified names using the current
//!   namespace and `use` imports.
//! - With the `serde` feature, a `fingerprint` module for structural AST fingerprints.
//!
//! # Quick start
//!
//! Parse a PHP file with `php-rs-parser` and then walk the AST with a custom visitor:
//!
//! ```
//! use php_ast::visitor::{Visitor, walk_expr};
//! use php_ast::ast::{Expr, ExprKind};
//! use std::ops::ControlFlow;
//!
//! struct FunctionCallCounter(usize);
//!
//! impl<'arena, 'src> Visitor<'arena, 'src> for FunctionCallCounter {
//!     type Break = ();
//!     fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()> {
//!         if matches!(expr.kind, ExprKind::FunctionCall(_)) {
//!             self.0 += 1;
//!         }
//!         walk_expr(self, expr)
//!     }
//! }
//! ```
//!
//! # Semantic AST
//!
//! Equivalent spellings (`array()`/`[]`, `exit`/`die`, `(integer)`/`(int)`) share one node;
//! formatting is dropped. Use [`Span`] to recover the original text.
//!
//! # Serialization
//!
//! With the `serde` feature (off by default), AST types implement `serde::Serialize`
//! for debugging, snapshots and tooling, and the `fingerprint` module is available.
//! The serialized shape is **not** covered by semver and may change in any release,
//! for example when a node is renamed. `Deserialize` is not implemented.

#![warn(missing_docs)]

/// Arena-allocated AST node types.
pub mod ast;
#[cfg(feature = "serde")]
pub mod fingerprint;
pub mod fold;
pub mod owned;
pub mod resolve;
/// Byte-offset source spans.
pub mod span;
/// Target PHP version selection.
pub mod version;
/// Read-only AST traversal.
pub mod visitor;

pub use ast::*;
pub use span::Span;
pub use version::PhpVersion;

/// The arena allocator behind [`ArenaVec`] and [`fold::Fold`], re-exported so
/// callers use the same version.
pub use bumpalo;