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