phpdoc_parser/ast.rs
1use crate::Span;
2use serde::Serialize;
3
4// =============================================================================
5// Document-structure AST
6// =============================================================================
7
8/// An inline `{@tagname body}` tag embedded in text.
9#[derive(Debug, Clone, Serialize)]
10pub struct InlineTag {
11 /// Tag name without braces or `@`.
12 pub name: String,
13 /// Text after the name, if any.
14 pub body: Option<String>,
15 /// Source range of the whole tag.
16 pub span: Span,
17}
18
19/// A segment of prose text — either plain text or an inline tag.
20#[derive(Debug, Clone, Serialize)]
21pub enum TextSegment {
22 /// Literal prose.
23 Text(String),
24 /// Embedded `{@tag}`.
25 InlineTag(InlineTag),
26}
27
28/// A prose run (summary, description, or tag body) that may contain inline tags.
29#[derive(Debug, Clone, Serialize)]
30pub struct PhpDocText {
31 /// Segments in source order.
32 pub segments: Vec<TextSegment>,
33 /// Source range of the text.
34 pub span: Span,
35}
36
37/// A block-level `@tag` — generic, no semantic interpretation.
38#[derive(Debug, Clone, Serialize)]
39pub struct PhpDocTag {
40 /// Raw tag name, e.g. `"param"`, `"psalm-type"`, `"return"`.
41 pub name: String,
42 /// Tag body, if any.
43 pub body: Option<PhpDocText>,
44 /// Source range of the tag.
45 pub span: Span,
46}
47
48// =============================================================================
49// Top-level document
50// =============================================================================
51
52/// A parsed docblock.
53#[derive(Debug, Clone, Serialize)]
54pub struct PhpDoc {
55 /// Leading summary text.
56 pub summary: Option<PhpDocText>,
57 /// Description following the summary.
58 pub description: Option<PhpDocText>,
59 /// Block-level tags in source order.
60 pub tags: Vec<PhpDocTag>,
61 /// Always `Span::new(0, text.len() as u32)`.
62 pub span: Span,
63}