Skip to main content

Crate phpdoc_parser

Crate phpdoc_parser 

Source
Expand description

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

Structs§

InlineTag
An inline {@tagname body} tag embedded in text.
PhpDoc
PhpDocTag
A block-level @tag — generic, no semantic interpretation.
PhpDocText
A prose run (summary, description, or tag body) that may contain inline tags.
Span

Enums§

TextSegment
A segment of prose text — either plain text or an inline tag.

Functions§

body_text
Get the text content of a tag body, if present.
find_tag
Find the first tag with the given name.
find_tags
Find all tags with the given name.
inline_tags
Extract all inline tags from a text segment.
parse
Parse a raw doc-comment string into a PhpDoc.
text_content
Reconstruct the text content of a PhpDocText, including inline tags.