Skip to main content

php_ast/
lib.rs

1//! AST type definitions and visitor infrastructure for the PHP parser.
2//!
3//! This crate provides:
4//! - The complete set of AST node types ([`ast`] module) — statements, expressions, declarations,
5//!   type hints, operators, and all other syntactic constructs for PHP 7.4–8.5, plus PHP 8.6
6//!   partial function application (`?`/`...` call-argument placeholders).
7//! - A [`Span`] type for tracking byte-offset ranges back to the source text.
8//! - A [`visitor`] module with the [`visitor::Visitor`] and [`visitor::ScopeVisitor`] traits for
9//!   depth-first AST traversal, plus free `walk_*` functions that drive the default recursion.
10//!
11//! # Quick start
12//!
13//! Parse a PHP file with `php-rs-parser` and then walk the AST with a custom visitor:
14//!
15//! ```
16//! use php_ast::visitor::{Visitor, walk_expr};
17//! use php_ast::ast::{Expr, ExprKind};
18//! use std::ops::ControlFlow;
19//!
20//! struct FunctionCallCounter(usize);
21//!
22//! impl<'arena, 'src> Visitor<'arena, 'src> for FunctionCallCounter {
23//!     fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()> {
24//!         if matches!(expr.kind, ExprKind::FunctionCall(_)) {
25//!             self.0 += 1;
26//!         }
27//!         walk_expr(self, expr)
28//!     }
29//! }
30//! ```
31
32pub mod ast;
33pub mod fold;
34pub mod owned;
35pub mod span;
36pub mod visitor;
37
38pub use ast::*;
39pub use span::Span;