Skip to main content

lex_core/lex/ast/elements/inlines/
references.rs

1//! Inline AST nodes shared across formatting, literal, and reference elements.
2//!
3//! These nodes are intentionally lightweight so the inline parser can be used
4//! from unit tests before it is integrated into the higher level AST builders.
5
6/// Sequence of inline nodes produced from a [`TextContent`](crate::lex::ast::TextContent).
7/// Reference inline node with raw content and classified type.
8#[derive(Debug, Clone, PartialEq)]
9pub struct ReferenceInline {
10    pub raw: String,
11    pub reference_type: ReferenceType,
12}
13
14impl ReferenceInline {
15    pub fn new(raw: String) -> Self {
16        Self {
17            raw,
18            reference_type: ReferenceType::NotSure,
19        }
20    }
21}
22
23/// Reference type classification derived from its content.
24#[derive(Debug, Clone, PartialEq)]
25pub enum ReferenceType {
26    /// `[TK]` or `[TK-identifier]`
27    ToCome { identifier: Option<String> },
28    /// `[@citation]` with structured citation data.
29    Citation(CitationData),
30    /// `[^note]`
31    FootnoteLabeled { label: String },
32    /// `[12]`
33    FootnoteNumber { number: u32 },
34    /// `[#42]`
35    Session { target: String },
36    /// `[https://example.com]`
37    Url { target: String },
38    /// `[./file.txt]`
39    File { target: String },
40    /// `[Introduction]` or other document references.
41    General { target: String },
42    /// Unable to classify.
43    NotSure,
44}
45
46/// Structured citation payload capturing parsed information.
47#[derive(Debug, Clone, PartialEq)]
48pub struct CitationData {
49    pub keys: Vec<String>,
50    pub locator: Option<CitationLocator>,
51}
52
53/// Citation locator derived from the `p.` / `pp.` segment.
54#[derive(Debug, Clone, PartialEq)]
55pub struct CitationLocator {
56    pub format: PageFormat,
57    pub ranges: Vec<PageRange>,
58    /// Raw locator string as authored (e.g. `p.45-46`).
59    pub raw: String,
60}
61
62#[derive(Debug, Clone, PartialEq)]
63pub enum PageFormat {
64    P,
65    Pp,
66}
67
68#[derive(Debug, Clone, PartialEq)]
69pub struct PageRange {
70    pub start: u32,
71    pub end: Option<u32>,
72}