rustla/parser/
automata.rs

1/*!
2In this submodule the patterns in `crate::parser::regex_patterns` are lazily compiled into finite automata
3using the standard Rust `regex` crate.
4
5Copyright © 2020 Santtu Söderholm
6*/
7use crate::parser::regex_patterns;
8use regex::Regex;
9
10lazy_static::lazy_static! {
11
12    /// A DFA for recognising block quote attributions.
13    pub static ref ATTRIBUTION_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::ATTRIBUTION_PATTERN) {
14        automaton
15    } else {
16        panic!("Could not initialize ATTRIBUTION automaton. Computer says no...")
17    };
18
19    /// A DFA for recognising blank lines.
20    pub static ref BLANK_LINE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::BLANK_LINE_PATTERN) {
21        automaton
22    } else {
23        panic!("Could not initialize BLANK_LINE automaton. Computer says no...")
24    };
25
26    /// A DFA for recognising blank lines.
27    pub static ref BULLET_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::BULLET_PATTERN) {
28        automaton
29    } else {
30        panic!("Could not initialize BULLET automaton. Computer says no...")
31    };
32
33    /// A DFA for recognising enumerators.
34    pub static ref ENUMERATOR_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::ENUMERATOR_PATTERN) {
35        automaton
36    } else {
37        panic!("Could not initialize ENUMERATOR automaton. Computer says no...")
38    };
39
40    /// A DFA for recognising field markers.
41    pub static ref FIELD_MARKER_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::FIELD_MARKER_PATTERN) {
42        automaton
43    } else {
44        panic!("Could not initialize FIELD_MARKER automaton. Computer says no...")
45    };
46
47    /// A DFA for recognising indented literal blocks.
48    pub static ref INDENTED_LITERAL_BLOCK_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::INDENTED_LITERAL_BLOCK_PATTERN) {
49        automaton
50    } else {
51        panic!("Could not initialize INDENTED_LITERAL_BLOCK automaton. Computer says no...")
52    };
53
54    /// A DFA for recognising quoted literal blocks.
55    pub static ref QUOTED_LITERAL_BLOCK_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::QUOTED_LITERAL_BLOCK_PATTERN) {
56        automaton
57    } else {
58        panic!("Could not initialize QUOTED_LITERAL_BLOCK automaton. Computer says no...")
59    };
60
61    /// A DFA for recognising the tops and bottoms of grid tables.
62    pub static ref GRID_TABLE_TOP_AND_BOT_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::GRID_TABLE_TOP_AND_BOT_PATTERN) {
63        automaton
64    } else {
65        panic!("Could not initialize GRID_TABLE_TOP_AND_BOT_AUTOMATON automaton. Computer says no...")
66    };
67
68    /// A DFA for recognising the tops of simple tables.
69    pub static ref SIMPLE_TABLE_TOP_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_TABLE_TOP_PATTERN) {
70        automaton
71    } else {
72        panic!("Could not initialize SIMPLE_TABLE_TOP_AUTOMATON automaton. Computer says no...")
73    };
74
75    /// A DFA for recognising the bottoms of simple tables.
76    pub static ref SIMPLE_TABLE_BOTTOM_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_TABLE_BOTTOM_PATTERN) {
77        automaton
78    } else {
79        panic!("Could not initialize SIMPLE_TABLE_BOTTOM_AUTOMATON automaton. Computer says no...")
80    };
81
82    /// A DFA for recognizing footnotes.
83    pub static ref FOOTNOTE_AUTOMATON: regex::Regex = match regex::Regex::new(regex_patterns::FOOTNOTE_PATTERN) {
84        Ok(automaton) => automaton,
85        Err(e) => panic!("Could not initialize FOOTNOTE_AUTOMATON: {}. Computer says no...", e)
86    };
87
88    /// A DFA for recognising manually numbered footnotes.
89    pub static ref MANUAL_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::MANUAL_FOOTNOTE_PATTERN) {
90        automaton
91    } else {
92        panic!("Could not initialize MANUAL_FOOTNOTE automaton. Computer says no...")
93    };
94
95    /// A DFA for recognising automatically numbered footnotes.
96    pub static ref AUTO_NUM_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::AUTO_NUM_FOOTNOTE_PATTERN) {
97        automaton
98    } else {
99        panic!("Could not initialize AUTO_NUM_FOOTNOTE automaton. Computer says no...")
100    };
101
102    /// A DFA for recognising simple refname footnotes.
103    pub static ref SIMPLE_NAME_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_NAME_FOOTNOTE_PATTERN) {
104        automaton
105    } else {
106        panic!("Could not initialize SIMPLE_NAME_FOOTNOTE automaton. Computer says no...")
107    };
108
109    /// A DFA for recognising automatically assigned footnote symbols.
110    pub static ref AUTO_SYM_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::AUTO_SYM_FOOTNOTE_PATTERN) {
111        automaton
112    } else {
113        panic!("Could not initialize AUTO_SYM_FOOTNOTE automaton. Computer says no...")
114    };
115
116    /// A DFA for recognising citations.
117    pub static ref CITATION_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::CITATION_PATTERN) {
118        automaton
119    } else {
120        panic!("Could not initialize CITATION automaton. Computer says no...")
121    };
122
123    /// A DFA for recognising hyperlink targets.
124    pub static ref HYPERLINK_TARGET_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::HYPERLINK_TARGET_PATTERN) {
125        automaton
126    } else {
127        panic!("Could not initialize HYPERLINK_TARGET automaton. Computer says no...")
128    };
129
130    /// A DFA for recognising substitution definitions.
131    pub static ref SUBSTITUTION_DEF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SUBSTITUTION_DEF_PATTERN) {
132        automaton
133    } else {
134        panic!("Could not initialize SUBSTITUTION_DEF automaton. Computer says no...")
135    };
136
137    /// A DFA for recognising directives.
138    pub static ref DIRECTIVE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::DIRECTIVE_PATTERN) {
139        automaton
140    } else {
141        panic!("Could not initialize DIRECTIVE automaton. Computer says no...")
142    };
143
144    /// A DFA for recognising comments.
145    pub static ref COMMENT_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::COMMENT_PATTERN) {
146        automaton
147    } else {
148        panic!("Could not initialize COMMENT automaton. Computer says no...")
149    };
150
151    /// A DFA for recognising transition and section title lines.
152    pub static ref LINE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::LINE_PATTERN) {
153        automaton
154    } else {
155        panic!("Could not initialize LINE automaton. Computer says no...")
156    };
157
158    /// A DFA for recognising blocks of text after all other options have been exhausted.
159    pub static ref TEXT_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::TEXT_PATTERN) {
160        automaton
161    } else {
162        panic!("Could not initialize TEXT automaton. Computer says no...")
163    };
164
165    /// A DFA for recognising inline stong emphasis.
166    pub static ref STRONG_EMPH_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::STRONG_EMPH_PATTERN) {
167        automaton
168    } else {
169        panic!("Could not initialize STRONG_EMPH automaton. Computer says no...")
170    };
171
172    /// A DFA for recognising inline emphasis.
173    pub static ref EMPH_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::EMPH_PATTERN) {
174        automaton
175    } else {
176        panic!("Could not initialize EMPH automaton. Computer says no...")
177    };
178
179    /// A DFA for recognising inline literals.
180    pub static ref LITERAL_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::LITERAL_PATTERN) {
181        automaton
182    } else {
183        panic!("Could not initialize LITERAL automaton. Computer says no...")
184    };
185
186    /// A DFA for recognising inline reference targets.
187    pub static ref INLINE_TARGET_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::INLINE_TARGET_PATTERN) {
188        automaton
189    } else {
190        panic!("Could not initialize INLINE_TARGET automaton. Computer says no...")
191    };
192
193    /// A DFA for recognising inline interpreted text.
194    pub static ref INTERPRETED_TEXT_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::INTERPRETED_TEXT_PATTERN) {
195        automaton
196    } else {
197        panic!("Could not initialize INTERPRETED_TEXT automaton. Computer says no...")
198    };
199
200    /// A DFA for recognising inline phrase references.
201    pub static ref PHRASE_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::PHRASE_REF_PATTERN) {
202        automaton
203    } else {
204        panic!("Could not initialize PHRASE_REF automaton. Computer says no...")
205    };
206
207    /// A DFA for recognising inline simple references.
208    pub static ref SIMPLE_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_REF_PATTERN) {
209        automaton
210    } else {
211        panic!("Could not initialize SIMPLE_REF automaton. Computer says no...")
212    };
213
214    /// A DFA for recognising inline footnote references.
215    pub static ref FOOTNOTE_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::FOOTNOTE_REF_PATTERN) {
216        automaton
217    } else {
218        panic!("Could not initialize FOOTNOTE_REF automaton. Computer says no...")
219    };
220
221    /// A DFA for recognising inline citation references.
222    pub static ref CITATION_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::CITATION_REF_PATTERN) {
223        automaton
224    } else {
225        panic!("Could not initialize CITATION_REF automaton. Computer says no...")
226    };
227
228    /// A DFA for recognising inline substotution references (macro expansions).
229    pub static ref SUBSTITUTION_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SUBSTITUTION_REF_PATTERN) {
230        automaton
231    } else {
232        panic!("Could not initialize SUBSTITUTION_REF automaton. Computer says no...")
233    };
234
235    /// A DFA for recognising inline URIs.
236    pub static ref URI_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::URI_PATTERN) {
237        automaton
238    } else {
239        panic!("Could not initialize URI automaton. Computer says no...")
240    };
241
242    // A+ specific automata
243
244    /// A DFA for recognising A+ Point of interest column breaks.
245    pub static ref APLUS_COL_BREAK_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_COL_BREAK_PATTERN) {
246        automaton
247    } else {
248        panic!("Could not initialize APLUS_COL_BREAK automaton. Computer says no...")
249    };
250
251    /// A DFA for recognising A+ questionnaire directives.
252    pub static ref APLUS_QUESTIONNAIRE_DIRECTIVE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_QUESTIONNAIRE_DIRECTIVE_PATTERN) {
253        automaton
254    } else {
255        panic!("Could not initialize APLUS_QUESTIONNAIRE_DIRECTIVE automaton. Computer says no...")
256    };
257
258    /// A DFA for recognising A+ pick-any choices.
259    pub static ref APLUS_PICK_ONE_CHOICE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_PICK_ONE_CHOICE_PATTERN) {
260        automaton
261    } else {
262        panic!("Could not initialize APLUS_PICK_ONE_CHOICE automaton. Computer says no...")
263    };
264
265    /// A DFA for recognising A+ pick-any choices.
266    pub static ref APLUS_PICK_ANY_CHOICE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_PICK_ANY_CHOICE_PATTERN) {
267        automaton
268    } else {
269        panic!("Could not initialize APLUS_PICK_ANY_CHOICE automaton. Computer says no...")
270    };
271
272}