php-ast 0.1.0

PHP Abstract Syntax Tree (AST) node definitions
Documentation
  • Coverage
  • 17.61%
    93 out of 528 items documented0 out of 109 items with examples
  • Size
  • Source code size: 51.95 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 25.48 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 28s Average build duration of successful builds.
  • all releases: 30s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • jorgsowa/rust-php-parser
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jorgsowa

Rust PHP Parser

A fast, fault-tolerant PHP parser written in Rust. Produces a full AST with source spans, recovers from syntax errors, and covers the vast majority of PHP 8.x syntax.

Inspired by and tested against the nikic/PHP-Parser test suite.

Note: The parser targets PHP 8.5 by default — all supported syntax from PHP 5.x through 8.5 is accepted.

Architecture

Cargo workspace with three crates:

Crate Purpose
php-lexer Hand-written tokenizer with handling for strings, heredoc/nowdoc, and inline HTML
php-ast AST type definitions, serializable via Serde
php-parser Pratt-based recursive descent parser with panic-mode error recovery

Usage

use php_parser::parse;

let result = parse("<?php echo 'Hello, world!';");

println!("{:#?}", result.program);

for err in &result.errors {
    println!("error at {:?}: {}", err.span(), err);
}

Testing

cargo test --test integration               # hand-written integration tests
cargo test --test nikic_integration_tests   # nikic/PHP-Parser fixture tests

Fixture files live in crates/php-parser/tests/fixtures/.

Roadmap

See ROADMAP.md.

License

BSD 3-Clause