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//! - A [`resolve::NameResolver`] that resolves names to fully qualified names using the current
11//! namespace and `use` imports.
12//!
13//! # Quick start
14//!
15//! Parse a PHP file with `php-rs-parser` and then walk the AST with a custom visitor:
16//!
17//! ```
18//! use php_ast::visitor::{Visitor, walk_expr};
19//! use php_ast::ast::{Expr, ExprKind};
20//! use std::ops::ControlFlow;
21//!
22//! struct FunctionCallCounter(usize);
23//!
24//! impl<'arena, 'src> Visitor<'arena, 'src> for FunctionCallCounter {
25//! fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()> {
26//! if matches!(expr.kind, ExprKind::FunctionCall(_)) {
27//! self.0 += 1;
28//! }
29//! walk_expr(self, expr)
30//! }
31//! }
32//! ```
33
34#![warn(missing_docs)]
35
36/// Arena-allocated AST node types.
37pub mod ast;
38pub mod fold;
39pub mod owned;
40pub mod resolve;
41/// Byte-offset source spans.
42pub mod span;
43/// Read-only AST traversal.
44pub mod visitor;
45
46pub use ast::*;
47pub use span::Span;