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 8.0–8.5.
6//! - A [`Span`] type for tracking byte-offset ranges back to the source text.
7//! - A [`visitor`] module with the [`visitor::Visitor`] and [`visitor::ScopeVisitor`] traits for
8//!   depth-first AST traversal, plus free `walk_*` functions that drive the default recursion.
9//!
10//! # Quick start
11//!
12//! Parse a PHP file with `php-rs-parser` and then walk the AST with a custom visitor:
13//!
14//! ```
15//! use php_ast::visitor::{Visitor, walk_expr};
16//! use php_ast::ast::{Expr, ExprKind};
17//! use std::ops::ControlFlow;
18//!
19//! struct FunctionCallCounter(usize);
20//!
21//! impl<'arena, 'src> Visitor<'arena, 'src> for FunctionCallCounter {
22//!     fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()> {
23//!         if matches!(expr.kind, ExprKind::FunctionCall(_)) {
24//!             self.0 += 1;
25//!         }
26//!         walk_expr(self, expr)
27//!     }
28//! }
29//! ```
30
31pub mod ast;
32pub mod span;
33pub mod visitor;
34
35pub use ast::*;
36pub use span::Span;