aboutsummaryrefslogtreecommitdiffstats
path: root/src/document_tree/elements.rs
blob: f1a9b4375e6c3db1bfa7f29946f1507fd217706a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
use url::Url;

use super::extra_attributes::{self,ExtraAttributes};
use super::element_categories::*;


//-----------------\\
//Element hierarchy\\
//-----------------\\

pub trait Element {
	fn     ids    (&    self) -> &    Vec<String>;
	fn     ids_mut(&mut self) -> &mut Vec<String>;
	fn   names    (&    self) -> &    Vec<String>;
	fn   names_mut(&mut self) -> &mut Vec<String>;
	fn  source    (&    self) -> &    Option<Url>;
	fn  source_mut(&mut self) -> &mut Option<Url>;
	fn classes    (&    self) -> &    Vec<String>;
	fn classes_mut(&mut self) -> &mut Vec<String>;
}

#[derive(Default,Debug)]
pub struct CommonAttributes {
	ids:     Vec<String>,
	names:   Vec<String>,
	source:  Option<Url>,
	classes: Vec<String>,
	//left out dupnames
}

//----\\
//impl\\
//----\\

macro_rules! impl_element(($name:ident) => {
	impl Element for $name {
		fn     ids    (&    self) -> &    Vec<String> { &    self.common.ids     }
		fn     ids_mut(&mut self) -> &mut Vec<String> { &mut self.common.ids     }
		fn   names    (&    self) -> &    Vec<String> { &    self.common.names   }
		fn   names_mut(&mut self) -> &mut Vec<String> { &mut self.common.names   }
		fn  source    (&    self) -> &    Option<Url> { &    self.common.source  }
		fn  source_mut(&mut self) -> &mut Option<Url> { &mut self.common.source  }
		fn classes    (&    self) -> &    Vec<String> { &    self.common.classes }
		fn classes_mut(&mut self) -> &mut Vec<String> { &mut self.common.classes }
	}
});

macro_rules! impl_children(($name:ident, $childtype:ident) => {
	impl HasChildren<$childtype> for $name {
		fn children    (&    self) -> &    Vec<$childtype> { &    self.children }
		fn children_mut(&mut self) -> &mut Vec<$childtype> { &mut self.children }
	}
});

macro_rules! impl_extra(($name:ident) => {
	impl ExtraAttributes<extra_attributes::$name> for $name {
		fn extra    (&    self) -> &    extra_attributes::$name { &    self.extra }
		fn extra_mut(&mut self) -> &mut extra_attributes::$name { &mut self.extra }
	}
});

macro_rules! impl_elem(
	($name:ident) => {
		#[derive(Default,Debug)]
		pub struct $name { common: CommonAttributes }
		impl_element!($name);
	};
	($name:ident; +) => {
		#[derive(Default,Debug)]
		pub struct $name { common: CommonAttributes, extra: extra_attributes::$name }
		impl_element!($name); impl_extra!($name);
	};
	($name:ident; *) => { //same as above with no default
		#[derive(Debug)]
		pub struct $name { common: CommonAttributes, extra: extra_attributes::$name }
		impl_element!($name); impl_extra!($name);
	};
	($name:ident, $childtype:ident) => {
		#[derive(Default,Debug)]
		pub struct $name { common: CommonAttributes, children: Vec<$childtype> }
		impl_element!($name); impl_children!($name, $childtype);
	};
	($name:ident, $childtype:ident; +) => {
		#[derive(Default,Debug)]
		pub struct $name { common: CommonAttributes, extra: extra_attributes::$name, children: Vec<$childtype> }
		impl_element!($name); impl_extra!($name); impl_children!($name, $childtype);
	};
);

macro_rules! impl_elems(( $( ($($args:tt)*) )* ) => {
	$( impl_elem!($($args)*); )*
});


#[derive(Default,Debug)]
pub struct Document { children: Vec<StructuralSubElement> }
impl_children!(Document, StructuralSubElement);

impl_elems!(
	//structual elements
	(Section, SubSection)
	(Topic,   SubTopic)
	(Sidebar, SubSidebar)
	
	//structural subelements
	(Title,      TextOrInlineElement)
	(Subtitle,   TextOrInlineElement)
	(Decoration, DecorationElement)
	(Docinfo,    BibliographicElement)
	(Transition)
	
	//bibliographic elements
	(Author,       TextOrInlineElement)
	(Authors,      AuthorInfo)
	(Organization, TextOrInlineElement)
	(Address,      TextOrInlineElement; +)
	(Contact,      TextOrInlineElement)
	(Version,      TextOrInlineElement)
	(Revision,     TextOrInlineElement)
	(Status,       TextOrInlineElement)
	(Date,         TextOrInlineElement)
	(Copyright,    TextOrInlineElement)
	(Field,        SubField)
	
	//decoration elements
	(Header, BodyElement)
	(Footer, BodyElement)
	
	//simple body elements
	(Paragraph,              TextOrInlineElement)
	(LiteralBlock,           TextOrInlineElement; +)
	(DoctestBlock,           TextOrInlineElement; +)
	(MathBlock)
	(Rubric,                 TextOrInlineElement)
	(SubstitutionDefinition, TextOrInlineElement; +)
	(Comment,                TextOrInlineElement; +)
	(Pending)
	(Target; +)
	(Raw;    +)
	(Image;  *)
	
	//compound body elements
	(Compound,  BodyElement)
	(Container, BodyElement)
	
	(BulletList,     ListItem; +)
	(EnumeratedList, ListItem; +)
	(DefinitionList, DefinitionListItem)
	(FieldList,      Field)
	(OptionList,     OptionListItem)
	
	(LineBlock,     SubLineBlock)
	(BlockQuote,    SubBlockQuote)
	(Admonition,    SubTopic)
	(Attention,     BodyElement)
	(Hint,          BodyElement)
	(Note,          BodyElement)
	(Caution,       BodyElement)
	(Danger,        BodyElement)
	(Error,         BodyElement)
	(Important,     BodyElement)
	(Tip,           BodyElement)
	(Warning,       BodyElement)
	(Footnote,      SubFootnote; +)
	(Citation,      SubFootnote; +)
	(SystemMessage, BodyElement; +)
	(Figure,        SubFigure;   +)
	(Table; +) //TODO
	
	//body sub elements
	(ListItem, BodyElement)
	
	(DefinitionListItem, SubDLItem)
	(Term,               TextOrInlineElement)
	(Classifier,         TextOrInlineElement)
	(Definition,         BodyElement)
	
	(FieldName, TextOrInlineElement)
	(FieldBody, BodyElement)
	
	(OptionListItem, SubOptionListItem)
	(OptionGroup,    Option_)
	(Description,    BodyElement)
	(Option_,        SubOption)
	(OptionString,   TextOrInlineElement)
	(OptionArgument, TextOrInlineElement; +)
	
	(Line,        TextOrInlineElement)
	(Attribution, TextOrInlineElement)
	(Label,       TextOrInlineElement)
	
	(Caption, TextOrInlineElement)
	(Legend,  BodyElement)
	
	//inline elements
	(Emphasis,              TextOrInlineElement)
	(Literal,               TextOrInlineElement)
	(Reference,             TextOrInlineElement; +)
	(Strong,                TextOrInlineElement)
	(FootnoteReference,     TextOrInlineElement; +)
	(CitationReference,     TextOrInlineElement; +)
	(SubstitutionReference, TextOrInlineElement; +)
	(TitleReference,        TextOrInlineElement)
	(Abbreviation,          TextOrInlineElement)
	(Acronym,               TextOrInlineElement)
	(Superscript,           TextOrInlineElement)
	(Subscript,             TextOrInlineElement)
	(Inline,                TextOrInlineElement)
	(Problematic,           TextOrInlineElement; +)
	(Generated,             TextOrInlineElement)
	(Math)
	
	//also have non-inline versions. Inline image is no figure child, inline target has content
	(TargetInline, TextOrInlineElement; +)
	(RawInline;   +)
	(ImageInline; *)
	
	//text element
	(TextElement)
);