Skip to main content

lex_babel/ir/
nodes.rs

1//! Core data structures for the Intermediate Representation (IR).
2
3/// A universal, semantic representation of a document node.
4#[derive(Debug, Clone, PartialEq)]
5pub enum DocNode {
6    Document(Document),
7    Heading(Heading),
8    Paragraph(Paragraph),
9    List(List),
10    ListItem(ListItem),
11    Definition(Definition),
12    Verbatim(Verbatim),
13    Annotation(Annotation),
14    Inline(InlineContent),
15    Table(Table),
16    Image(Image),
17    Video(Video),
18    Audio(Audio),
19}
20
21/// Represents the root of a document.
22#[derive(Debug, Clone, PartialEq)]
23pub struct Document {
24    pub children: Vec<DocNode>,
25}
26
27/// Represents a heading with a specific level.
28#[derive(Debug, Clone, PartialEq)]
29pub struct Heading {
30    pub level: usize,
31    pub content: Vec<InlineContent>,
32    pub children: Vec<DocNode>,
33}
34
35/// Represents a paragraph of text.
36#[derive(Debug, Clone, PartialEq)]
37pub struct Paragraph {
38    pub content: Vec<InlineContent>,
39}
40
41/// Represents a list of items.
42#[derive(Debug, Clone, PartialEq)]
43pub struct List {
44    pub items: Vec<ListItem>,
45    pub ordered: bool,
46}
47
48/// Represents an item in a list.
49#[derive(Debug, Clone, PartialEq)]
50pub struct ListItem {
51    pub content: Vec<InlineContent>,
52    pub children: Vec<DocNode>,
53}
54
55/// Represents a definition of a term.
56#[derive(Debug, Clone, PartialEq)]
57pub struct Definition {
58    pub term: Vec<InlineContent>,
59    pub description: Vec<DocNode>,
60}
61
62/// Represents a block of verbatim text.
63#[derive(Debug, Clone, PartialEq)]
64pub struct Verbatim {
65    pub language: Option<String>,
66    pub content: String,
67}
68
69/// Represents an annotation.
70#[derive(Debug, Clone, PartialEq)]
71pub struct Annotation {
72    pub label: String,
73    pub parameters: Vec<(String, String)>,
74    pub content: Vec<DocNode>,
75}
76
77/// Represents a table.
78#[derive(Debug, Clone, PartialEq)]
79pub struct Table {
80    pub rows: Vec<TableRow>,
81    pub header: Vec<TableRow>,
82    pub caption: Option<Vec<InlineContent>>,
83}
84
85/// Represents a table row.
86#[derive(Debug, Clone, PartialEq)]
87pub struct TableRow {
88    pub cells: Vec<TableCell>,
89}
90
91/// Represents a table cell.
92#[derive(Debug, Clone, PartialEq)]
93pub struct TableCell {
94    pub content: Vec<DocNode>,
95    pub header: bool,
96    pub align: TableCellAlignment,
97}
98
99/// Alignment of a table cell.
100#[derive(Debug, Clone, Copy, PartialEq)]
101pub enum TableCellAlignment {
102    Left,
103    Center,
104    Right,
105    None,
106}
107
108/// Represents inline content, such as text, bold, italics, etc.
109#[derive(Debug, Clone, PartialEq)]
110pub enum InlineContent {
111    Text(String),
112    Bold(Vec<InlineContent>),
113    Italic(Vec<InlineContent>),
114    Code(String),
115    Math(String),
116    Reference(String),
117    Marker(String),
118    Image(Image),
119}
120
121/// Represents an image.
122#[derive(Debug, Clone, PartialEq)]
123pub struct Image {
124    pub src: String,
125    pub alt: String,
126    pub title: Option<String>,
127}
128
129/// Represents a video.
130#[derive(Debug, Clone, PartialEq)]
131pub struct Video {
132    pub src: String,
133    pub title: Option<String>,
134    pub poster: Option<String>,
135}
136
137/// Represents an audio file.
138#[derive(Debug, Clone, PartialEq)]
139pub struct Audio {
140    pub src: String,
141    pub title: Option<String>,
142}