Skip to main content

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)]
21#[non_exhaustive]
22pub enum TextSegment {
23    /// Literal prose.
24    Text(String),
25    /// Embedded `{@tag}`.
26    InlineTag(InlineTag),
27}
28
29/// A prose run (summary, description, or tag body) that may contain inline tags.
30#[derive(Debug, Clone, Serialize)]
31pub struct PhpDocText {
32    /// Segments in source order.
33    pub segments: Vec<TextSegment>,
34    /// Source range of the text.
35    pub span: Span,
36}
37
38/// A block-level `@tag` — generic, no semantic interpretation.
39#[derive(Debug, Clone, Serialize)]
40pub struct PhpDocTag {
41    /// Raw tag name, e.g. `"param"`, `"psalm-type"`, `"return"`.
42    pub name: String,
43    /// Tag body, if any.
44    pub body: Option<PhpDocText>,
45    /// Source range of the tag.
46    pub span: Span,
47}
48
49// =============================================================================
50// Top-level document
51// =============================================================================
52
53/// A parsed docblock.
54#[derive(Debug, Clone, Serialize)]
55pub struct PhpDoc {
56    /// Leading summary text.
57    pub summary: Option<PhpDocText>,
58    /// Description following the summary.
59    pub description: Option<PhpDocText>,
60    /// Block-level tags in source order.
61    pub tags: Vec<PhpDocTag>,
62    /// Always `Span::new(0, text.len() as u32)`.
63    pub span: Span,
64}