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(¶m.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§
- Inline
Tag - An inline
{@tagname body}tag embedded in text. - PhpDoc
- PhpDoc
Tag - A block-level
@tag— generic, no semantic interpretation. - PhpDoc
Text - A prose run (summary, description, or tag body) that may contain inline tags.
- Span
Enums§
- Text
Segment - 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.