rustla/parser/state_machine/
transitions.rs

1/*!
2This Module contains lists of transition tuples related to different states and common patterns as &str constants.
3
4Copyright © 2020 Santtu Söderholm
5*/
6
7use super::*;
8use crate::parser::regex_patterns;
9
10/// =================================
11/// StateMachine associated constants
12/// =================================
13impl State {
14
15    /// An array of transitions related to `State::Body`.
16    pub const BODY_TRANSITIONS: &'static [UncompiledTransition] = &[
17        (
18            Pattern::EmptyLine,
19            regex_patterns::BLANK_LINE_PATTERN,
20            common::empty_line,
21        ),
22        (Pattern::Bullet, regex_patterns::BULLET_PATTERN, body::bullet),
23        (
24            Pattern::Enumerator,
25            regex_patterns::ENUMERATOR_PATTERN,
26            body::enumerator,
27        ),
28        (
29            Pattern::FieldMarker,
30            regex_patterns::FIELD_MARKER_PATTERN,
31            body::field_marker,
32        ),
33        (
34            Pattern::Footnote,
35            regex_patterns::FOOTNOTE_PATTERN,
36            body::footnote,
37        ),
38        (
39            Pattern::Citation,
40            regex_patterns::CITATION_PATTERN,
41            body::citation
42        ),
43        (
44            Pattern::HyperlinkTarget,
45            regex_patterns::HYPERLINK_TARGET_PATTERN,
46            body::hyperlink_target,
47        ),
48        (
49            Pattern::Directive,
50            regex_patterns::DIRECTIVE_PATTERN,
51            body::directive
52        ),
53        (
54            Pattern::Comment,
55            regex_patterns::COMMENT_PATTERN,
56            body::comment
57        ),
58        (
59            Pattern::Line,
60            regex_patterns::LINE_PATTERN,
61            body::line),
62        (
63            Pattern::Text,
64            regex_patterns::TEXT_PATTERN,
65            body::text
66        ),
67    ];
68
69    /// An array of transitions related to `State::Body`.
70    pub const BLOCK_QUOTE_TRANSITIONS: &'static [UncompiledTransition] = &[
71        (
72            Pattern::EmptyLine,
73            regex_patterns::BLANK_LINE_PATTERN,
74            common::empty_line,
75        ),
76        (
77            Pattern::Attribution,
78            regex_patterns::ATTRIBUTION_PATTERN,
79            block_quote::attribution,
80        ),
81        (
82            Pattern::Bullet,
83            regex_patterns::BULLET_PATTERN,
84            body::bullet
85        ),
86        (
87            Pattern::Enumerator,
88            regex_patterns::ENUMERATOR_PATTERN,
89            body::enumerator,
90        ),
91        (
92            Pattern::FieldMarker,
93            regex_patterns::FIELD_MARKER_PATTERN,
94            body::field_marker,
95        ),
96        (
97            Pattern::Footnote,
98            regex_patterns::FOOTNOTE_PATTERN,
99            body::footnote,
100        ),
101        (
102            Pattern::Citation,
103            regex_patterns::CITATION_PATTERN,
104            body::citation
105        ),
106        (
107            Pattern::HyperlinkTarget,
108            regex_patterns::HYPERLINK_TARGET_PATTERN,
109            body::hyperlink_target,
110        ),
111        (
112            Pattern::Directive,
113            regex_patterns::DIRECTIVE_PATTERN,
114            body::directive
115        ),
116        (
117            Pattern::Comment,
118            regex_patterns::COMMENT_PATTERN,
119            body::comment
120        ),
121        (
122            Pattern::Line,
123            regex_patterns::LINE_PATTERN,
124            body::line
125        ),
126        (
127            Pattern::Text,
128            regex_patterns::TEXT_PATTERN,
129            body::text
130        ),
131    ];
132
133    /// An array of transitions related to `State::BulletList`.
134    pub const BULLET_LIST_TRANSITIONS: [UncompiledTransition; 2] = [
135        (
136            Pattern::EmptyLine,
137            regex_patterns::BLANK_LINE_PATTERN,
138            common::empty_line,
139        ),
140        (
141            Pattern::Bullet,
142            regex_patterns::BULLET_PATTERN,
143            bullet_list::bullet
144        ),
145    ];
146
147    /// An array of transitions related to `State::DefinitionList`.
148    pub const DEFINITION_LIST_TRANSITIONS: &'static [UncompiledTransition] = &[
149        (
150            Pattern::EmptyLine,
151            regex_patterns::BLANK_LINE_PATTERN,
152            common::empty_line,
153        ),
154        (
155            Pattern::Bullet,
156            regex_patterns::BULLET_PATTERN,
157            unknown_transitions::back_up,
158        ),
159        (
160            Pattern::Enumerator,
161            regex_patterns::ENUMERATOR_PATTERN,
162            unknown_transitions::back_up,
163        ),
164        (
165            Pattern::FieldMarker,
166            regex_patterns::FIELD_MARKER_PATTERN,
167            unknown_transitions::back_up,
168        ),
169        (
170            Pattern::Footnote,
171            regex_patterns::FOOTNOTE_PATTERN,
172            unknown_transitions::back_up,
173        ),
174        (
175            Pattern::Citation,
176            regex_patterns::CITATION_PATTERN,
177            unknown_transitions::back_up,
178        ),
179        (
180            Pattern::HyperlinkTarget,
181            regex_patterns::HYPERLINK_TARGET_PATTERN,
182            unknown_transitions::back_up,
183        ),
184        (
185            Pattern::Directive,
186            regex_patterns::DIRECTIVE_PATTERN,
187            unknown_transitions::back_up,
188        ),
189        (
190            Pattern::Comment,
191            regex_patterns::COMMENT_PATTERN,
192            unknown_transitions::back_up,
193        ),
194        (
195            Pattern::Line,
196            regex_patterns::LINE_PATTERN,
197            unknown_transitions::back_up,
198        ),
199        (
200            Pattern::Text,
201            regex_patterns::TEXT_PATTERN,
202            definition_list::text
203        ),
204    ];
205
206    /// An array of transitions related to `State::EnumeratedList`.
207    pub const ENUMERATED_LIST_TRANSITIONS: &'static [UncompiledTransition] = &[
208        (
209            Pattern::EmptyLine,
210            regex_patterns::BLANK_LINE_PATTERN,
211            common::empty_line,
212        ),
213        (
214            Pattern::Enumerator,
215            regex_patterns::ENUMERATOR_PATTERN,
216            enumerated_list::enumerator,
217        ),
218    ];
219
220    /// An array of transitions related to `State::FieldList`.
221    pub const FIELD_LIST_TRANSITIONS: &'static [UncompiledTransition] = &[
222        (
223            Pattern::EmptyLine,
224            regex_patterns::BLANK_LINE_PATTERN,
225            common::empty_line,
226        ),
227        (
228            Pattern::FieldMarker,
229            regex_patterns::FIELD_MARKER_PATTERN,
230            field_list::field_marker,
231        ),
232    ];
233
234    const HYPERLINK_TARGET_TRANSITIONS: [UncompiledTransition; 0] = [];
235
236    /// An array of transitions related to `State::OptionList`.
237    pub const OPTION_LIST_TRANSITIONS: [UncompiledTransition; 0] = [];
238
239    /// An array of transitions related to `State::LineBlock`.
240    pub const LINE_BLOCK_TRANSITIONS: [UncompiledTransition; 0] = [];
241
242    /// An array of transitions related to `State::Line`.
243    pub const LITERAL_BLOCK_TRANSITIONS: [UncompiledTransition; 3] = [
244        (
245            Pattern::EmptyLine,
246            regex_patterns::BLANK_LINE_PATTERN,
247            common::empty_line,
248        ),
249        (
250            Pattern::QuotedLiteralBlock,
251            regex_patterns::QUOTED_LITERAL_BLOCK_PATTERN,
252            literal_block::literal_block,
253        ),
254        (
255            Pattern::IndentedLiteralBlock,
256            regex_patterns::INDENTED_LITERAL_BLOCK_PATTERN,
257            literal_block::literal_block,
258        ),
259    ];
260
261    /// An array of transitions related to `State::ExtensionOptions`.
262    pub const EXTENSION_OPTION_TRANSITIONS: [UncompiledTransition; 0] = [];
263
264    /// An array of transitions related to `State::ExplicitMarkup`.
265    pub const EXPLICIT_MARKUP_TRANSITIONS: [UncompiledTransition; 0] = [];
266
267    /// An array of transitions related to `State::Text`.
268    pub const TEXT_TRANSITIONS: [UncompiledTransition; 0] = [];
269
270    /// An array of transitions related to `State::Definition`.
271    pub const DEFINITION_LIST_ITEM_TRANSITIONS: [UncompiledTransition; 0] = [];
272
273    /// An array of transitions related to `State::Line`.
274    pub const LINE_TRANSITIONS: [UncompiledTransition; 0] = [];
275
276    /// An array of transitions related to `State::SubstitutionDef`.
277    pub const SUBSTITUTION_DEF_TRANSITIONS: [UncompiledTransition; 0] = [];
278
279    pub const LIST_TABLE_TRANSITIONS: &'static [UncompiledTransition] = &[
280        (
281            Pattern::EmptyLine,
282            regex_patterns::BLANK_LINE_PATTERN,
283            common::empty_line,
284        ),
285        (
286            Pattern::Bullet,
287            regex_patterns::BULLET_PATTERN,
288            body::bullet
289        ),
290    ];
291
292    /// An array of transitions allowed in multi-column A+ directives such as points of interest.
293    /// These are indentical to those, except the state also recognizes
294    pub const APLUS_MULTICOL_TRANSITIONS: &'static [UncompiledTransition] = &[
295        (
296            Pattern::EmptyLine,
297            regex_patterns::BLANK_LINE_PATTERN,
298            common::empty_line,
299        ),
300        (
301            Pattern::AplusColBreak,
302            regex_patterns::APLUS_COL_BREAK_PATTERN,
303            aplus::aplus_col_break,
304        ),
305        (
306            Pattern::Bullet,
307            regex_patterns::BULLET_PATTERN,
308            body::bullet
309        ),
310        (
311            Pattern::Enumerator,
312            regex_patterns::ENUMERATOR_PATTERN,
313            body::enumerator,
314        ),
315        (
316            Pattern::FieldMarker,
317            regex_patterns::FIELD_MARKER_PATTERN,
318            body::field_marker,
319        ),
320        (
321            Pattern::Footnote,
322            regex_patterns::FOOTNOTE_PATTERN,
323            body::footnote,
324        ),
325        (
326            Pattern::Citation,
327            regex_patterns::CITATION_PATTERN,
328            body::citation
329        ),
330        (
331            Pattern::HyperlinkTarget,
332            regex_patterns::HYPERLINK_TARGET_PATTERN,
333            body::hyperlink_target,
334        ),
335        (
336            Pattern::Directive,
337            regex_patterns::DIRECTIVE_PATTERN,
338            body::directive
339        ),
340        (
341            Pattern::Comment,
342            regex_patterns::COMMENT_PATTERN,
343            body::comment
344        ),
345        (
346            Pattern::Line,
347            regex_patterns::LINE_PATTERN,
348            body::line
349        ),
350        (
351            Pattern::Text,
352            regex_patterns::TEXT_PATTERN,
353            body::text
354        ),
355    ];
356
357    pub const APLUS_QUESTIONNAIRE_TRANSITIONS: &'static [UncompiledTransition] = &[
358        (
359            Pattern::EmptyLine,
360            regex_patterns::BLANK_LINE_PATTERN,
361            common::empty_line,
362        ),
363        (
364            Pattern::AplusQuestionnaireDirective,
365            regex_patterns::APLUS_QUESTIONNAIRE_DIRECTIVE_PATTERN,
366            aplus_questionnaire::parse_aplus_questionnaire_directive,
367        ),
368        (
369            Pattern::Text,
370            regex_patterns::TEXT_PATTERN,
371            aplus_questionnaire::parse_aplus_questionnaire_text,
372        ),
373    ];
374
375    /// An array of inline transitions.
376    pub const INLINE_TRANSITIONS: [InlineTransition; 13] = [
377        (
378            Pattern::WhiteSpace,
379            regex_patterns::INLINE_WHITESPACE_PATTERN,
380            inline::whitespace),
381        (
382            Pattern::StrongEmphasis,
383            regex_patterns::STRONG_EMPH_PATTERN,
384            inline::paired_delimiter,
385        ),
386        (
387            Pattern::Emphasis,
388            regex_patterns::EMPH_PATTERN,
389            inline::paired_delimiter,
390        ),
391        (
392            Pattern::Literal,
393            regex_patterns::LITERAL_PATTERN,
394            inline::paired_delimiter,
395        ),
396        (
397            Pattern::InlineTarget,
398            regex_patterns::INLINE_TARGET_PATTERN,
399            inline::inline_target,
400        ),
401        (
402            Pattern::PhraseRef,
403            regex_patterns::PHRASE_REF_PATTERN,
404            inline::phrase_ref,
405        ),
406        (
407            Pattern::Interpreted,
408            regex_patterns::INTERPRETED_TEXT_PATTERN,
409            inline::interpreted_text,
410        ),
411        (
412            Pattern::FootNoteRef,
413            regex_patterns::FOOTNOTE_REF_PATTERN,
414            inline::footnote_ref,
415        ),
416        (
417            Pattern::CitationRef,
418            regex_patterns::CITATION_REF_PATTERN,
419            inline::citation_ref,
420        ),
421        (
422            Pattern::SimpleRef,
423            regex_patterns::SIMPLE_REF_PATTERN,
424            inline::simple_ref,
425        ),
426        (
427            Pattern::SubstitutionRef,
428            regex_patterns::SUBSTITUTION_REF_PATTERN,
429            inline::substitution_ref,
430        ),
431
432        // source: https://www.rfc-editor.org/rfc/rfc2396.txt, appendix B
433        //
434        // The capturing groups correspond to the following constructs:
435        //   $1 = http:
436        //   $2 = http
437        //   $3 = //www.ics.uci.edu
438        //   $4 = www.ics.uci.edu
439        //   $5 = /pub/ietf/uri/
440        //   $6 = <undefined>
441        //   $7 = <undefined>
442        //   $8 = #Related
443        //   $9 = Related
444        //
445        // where <undefined> indicates that the component is not present, as is
446        // the case for the query component in the above example.  Therefore, we
447        // can determine the value of the four components and fragment as
448        //
449        //   scheme    = $2
450        //   authority = $4
451        //   path      = $5
452        //   query     = $7
453        //   fragment  = $9
454        //(PatternName::StandaloneHyperlink, r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", Inline::reference),
455        (
456            Pattern::StandaloneHyperlink,
457            regex_patterns::URI_PATTERN,
458            inline::uri
459        ),
460        (
461            Pattern::Text,
462            regex_patterns::INLINE_TEXT_PATTERN,
463            inline::text
464        ),
465    ];
466}