Thanks to visit codestin.com
Credit goes to lib.rs

#parser #ast #doc-comment #documentation #prose #spans-tags

phpdoc-parser

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

7 unstable releases (3 breaking)

new 0.14.0 May 21, 2026
0.13.0 May 17, 2026
0.12.2 May 16, 2026
0.11.1 May 11, 2026

#539 in Programming languages

Codestin Search App Codestin Search App Codestin Search App

124 downloads per month
Used in 5 crates (2 directly)

BSD-3-Clause

22KB
387 lines

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()
        }
    }
}

Dependencies

~0.2–0.8MB
~18K SLoC