phpdoc-parser 0.11.1

Structural PHPDoc parser. Parses doc-comment blocks into a tag/prose AST with accurate spans; tag bodies exposed as raw text.
Documentation

Structural PHPDoc comment parser.

Parses /** ... */ documentation blocks into a structured AST with accurate spans and support for inline tags. Designed for type checkers, linters, IDEs, and documentation generators.

The crate is agnostic — it does not interpret tag semantics or parse type expressions. Tag bodies are exposed as raw [PhpDocText], letting tools apply their own type parsers and validation rules.

Quick start

use phpdoc_parser::parse;

let text = "/** @param int $x The value */";
let doc = parse(text);
assert_eq!(doc.tags.len(), 1);
assert_eq!(doc.tags[0].name, "param");

Common patterns

Read a tag body

use phpdoc_parser::{parse, find_tags, body_text};

let doc = parse("/** @param int $x The mapping */");
for param in find_tags(&doc, "param") {
    let body = body_text(&param.body).unwrap_or_default();
    // body is "int $x The mapping" — parse the type yourself
}

Find inline references

use phpdoc_parser::{parse, inline_tags};

let doc = parse("/** See {@link User::load()} for details. */");
if let Some(desc) = &doc.description {
    for tag in inline_tags(desc) {
        if tag.name == "link" {
            // Process the reference to User::load()
        }
    }
}