1 | // pest. The Elegant Parser |
2 | // Copyright (c) 2018 DragoČ™ Tiselice |
3 | // |
4 | // Licensed under the Apache License, Version 2.0 |
5 | // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT |
6 | // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
7 | // option. All files in the project carrying such notice may not be copied, |
8 | // modified, or distributed except according to those terms. |
9 | |
10 | use alloc::borrow::Cow; |
11 | |
12 | // This structure serves to improve performance over Token objects in two ways: |
13 | // |
14 | // * it is smaller than a Token, leading to both less memory use when stored in the queue but also |
15 | // increased speed when pushing to the queue |
16 | // * it finds its pair in O(1) time instead of O(N), since pair positions are known at parse time |
17 | // and can easily be stored instead of recomputed |
18 | #[derive (Debug)] |
19 | pub enum QueueableToken<'i, R> { |
20 | Start { |
21 | end_token_index: usize, |
22 | input_pos: usize, |
23 | }, |
24 | End { |
25 | start_token_index: usize, |
26 | rule: R, |
27 | tag: Option<Cow<'i, str>>, |
28 | input_pos: usize, |
29 | }, |
30 | } |
31 | |