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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*!
In this submodule the patterns in `crate::parser::regex_patterns` are lazily compiled into finite automata
using the standard Rust `regex` crate.

Copyright © 2020 Santtu Söderholm
*/
use crate::parser::regex_patterns;
use regex::Regex;

lazy_static::lazy_static! {

    /// A DFA for recognising block quote attributions.
    pub static ref ATTRIBUTION_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::ATTRIBUTION_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize ATTRIBUTION automaton. Computer says no...")
    };

    /// A DFA for recognising blank lines.
    pub static ref BLANK_LINE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::BLANK_LINE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize BLANK_LINE automaton. Computer says no...")
    };

    /// A DFA for recognising blank lines.
    pub static ref BULLET_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::BULLET_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize BULLET automaton. Computer says no...")
    };

    /// A DFA for recognising enumerators.
    pub static ref ENUMERATOR_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::ENUMERATOR_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize ENUMERATOR automaton. Computer says no...")
    };

    /// A DFA for recognising field markers.
    pub static ref FIELD_MARKER_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::FIELD_MARKER_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize FIELD_MARKER automaton. Computer says no...")
    };

    /// A DFA for recognising indented literal blocks.
    pub static ref INDENTED_LITERAL_BLOCK_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::INDENTED_LITERAL_BLOCK_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize INDENTED_LITERAL_BLOCK automaton. Computer says no...")
    };

    /// A DFA for recognising quoted literal blocks.
    pub static ref QUOTED_LITERAL_BLOCK_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::QUOTED_LITERAL_BLOCK_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize QUOTED_LITERAL_BLOCK automaton. Computer says no...")
    };

    /// A DFA for recognising the tops and bottoms of grid tables.
    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) {
        automaton
    } else {
        panic!("Could not initialize GRID_TABLE_TOP_AND_BOT_AUTOMATON automaton. Computer says no...")
    };

    /// A DFA for recognising the tops of simple tables.
    pub static ref SIMPLE_TABLE_TOP_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_TABLE_TOP_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize SIMPLE_TABLE_TOP_AUTOMATON automaton. Computer says no...")
    };

    /// A DFA for recognising the bottoms of simple tables.
    pub static ref SIMPLE_TABLE_BOTTOM_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_TABLE_BOTTOM_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize SIMPLE_TABLE_BOTTOM_AUTOMATON automaton. Computer says no...")
    };

    /// A DFA for recognizing footnotes.
    pub static ref FOOTNOTE_AUTOMATON: regex::Regex = match regex::Regex::new(regex_patterns::FOOTNOTE_PATTERN) {
        Ok(automaton) => automaton,
        Err(e) => panic!("Could not initialize FOOTNOTE_AUTOMATON: {}. Computer says no...", e)
    };

    /// A DFA for recognising manually numbered footnotes.
    pub static ref MANUAL_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::MANUAL_FOOTNOTE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize MANUAL_FOOTNOTE automaton. Computer says no...")
    };

    /// A DFA for recognising automatically numbered footnotes.
    pub static ref AUTO_NUM_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::AUTO_NUM_FOOTNOTE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize AUTO_NUM_FOOTNOTE automaton. Computer says no...")
    };

    /// A DFA for recognising simple refname footnotes.
    pub static ref SIMPLE_NAME_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_NAME_FOOTNOTE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize SIMPLE_NAME_FOOTNOTE automaton. Computer says no...")
    };

    /// A DFA for recognising automatically assigned footnote symbols.
    pub static ref AUTO_SYM_FOOTNOTE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::AUTO_SYM_FOOTNOTE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize AUTO_SYM_FOOTNOTE automaton. Computer says no...")
    };

    /// A DFA for recognising citations.
    pub static ref CITATION_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::CITATION_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize CITATION automaton. Computer says no...")
    };

    /// A DFA for recognising hyperlink targets.
    pub static ref HYPERLINK_TARGET_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::HYPERLINK_TARGET_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize HYPERLINK_TARGET automaton. Computer says no...")
    };

    /// A DFA for recognising substitution definitions.
    pub static ref SUBSTITUTION_DEF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SUBSTITUTION_DEF_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize SUBSTITUTION_DEF automaton. Computer says no...")
    };

    /// A DFA for recognising directives.
    pub static ref DIRECTIVE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::DIRECTIVE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize DIRECTIVE automaton. Computer says no...")
    };

    /// A DFA for recognising comments.
    pub static ref COMMENT_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::COMMENT_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize COMMENT automaton. Computer says no...")
    };

    /// A DFA for recognising transition and section title lines.
    pub static ref LINE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::LINE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize LINE automaton. Computer says no...")
    };

    /// A DFA for recognising blocks of text after all other options have been exhausted.
    pub static ref TEXT_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::TEXT_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize TEXT automaton. Computer says no...")
    };

    /// A DFA for recognising inline stong emphasis.
    pub static ref STRONG_EMPH_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::STRONG_EMPH_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize STRONG_EMPH automaton. Computer says no...")
    };

    /// A DFA for recognising inline emphasis.
    pub static ref EMPH_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::EMPH_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize EMPH automaton. Computer says no...")
    };

    /// A DFA for recognising inline literals.
    pub static ref LITERAL_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::LITERAL_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize LITERAL automaton. Computer says no...")
    };

    /// A DFA for recognising inline reference targets.
    pub static ref INLINE_TARGET_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::INLINE_TARGET_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize INLINE_TARGET automaton. Computer says no...")
    };

    /// A DFA for recognising inline interpreted text.
    pub static ref INTERPRETED_TEXT_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::INTERPRETED_TEXT_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize INTERPRETED_TEXT automaton. Computer says no...")
    };

    /// A DFA for recognising inline phrase references.
    pub static ref PHRASE_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::PHRASE_REF_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize PHRASE_REF automaton. Computer says no...")
    };

    /// A DFA for recognising inline simple references.
    pub static ref SIMPLE_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SIMPLE_REF_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize SIMPLE_REF automaton. Computer says no...")
    };

    /// A DFA for recognising inline footnote references.
    pub static ref FOOTNOTE_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::FOOTNOTE_REF_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize FOOTNOTE_REF automaton. Computer says no...")
    };

    /// A DFA for recognising inline citation references.
    pub static ref CITATION_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::CITATION_REF_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize CITATION_REF automaton. Computer says no...")
    };

    /// A DFA for recognising inline substotution references (macro expansions).
    pub static ref SUBSTITUTION_REF_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::SUBSTITUTION_REF_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize SUBSTITUTION_REF automaton. Computer says no...")
    };

    /// A DFA for recognising inline URIs.
    pub static ref URI_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::URI_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize URI automaton. Computer says no...")
    };

    // A+ specific automata

    /// A DFA for recognising A+ Point of interest column breaks.
    pub static ref APLUS_COL_BREAK_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_COL_BREAK_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize APLUS_COL_BREAK automaton. Computer says no...")
    };

    /// A DFA for recognising A+ questionnaire directives.
    pub static ref APLUS_QUESTIONNAIRE_DIRECTIVE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_QUESTIONNAIRE_DIRECTIVE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize APLUS_QUESTIONNAIRE_DIRECTIVE automaton. Computer says no...")
    };

    /// A DFA for recognising A+ pick-any choices.
    pub static ref APLUS_PICK_ONE_CHOICE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_PICK_ONE_CHOICE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize APLUS_PICK_ONE_CHOICE automaton. Computer says no...")
    };

    /// A DFA for recognising A+ pick-any choices.
    pub static ref APLUS_PICK_ANY_CHOICE_AUTOMATON: regex::Regex = if let Ok(automaton) = Regex::new(regex_patterns::APLUS_PICK_ANY_CHOICE_PATTERN) {
        automaton
    } else {
        panic!("Could not initialize APLUS_PICK_ANY_CHOICE automaton. Computer says no...")
    };

}