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 pub name: String,
12 pub body: Option<String>,
13 pub span: Span,
14}
15
16/// A segment of prose text — either plain text or an inline tag.
17#[derive(Debug, Clone, Serialize)]
18pub enum TextSegment {
19 Text(String),
20 InlineTag(InlineTag),
21}
22
23/// A prose run (summary, description, or tag body) that may contain inline tags.
24#[derive(Debug, Clone, Serialize)]
25pub struct PhpDocText {
26 pub segments: Vec<TextSegment>,
27 pub span: Span,
28}
29
30/// A block-level `@tag` — generic, no semantic interpretation.
31#[derive(Debug, Clone, Serialize)]
32pub struct PhpDocTag {
33 /// Raw tag name, e.g. `"param"`, `"psalm-type"`, `"return"`.
34 pub name: String,
35 pub body: Option<PhpDocText>,
36 pub span: Span,
37}
38
39// =============================================================================
40// Top-level document
41// =============================================================================
42
43#[derive(Debug, Clone, Serialize)]
44pub struct PhpDoc {
45 pub summary: Option<PhpDocText>,
46 pub description: Option<PhpDocText>,
47 pub tags: Vec<PhpDocTag>,
48 /// Always `Span::new(0, text.len() as u32)`.
49 pub span: Span,
50}