• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // This structure serves to improve performance over Token objects in two ways:
11 //
12 //   * it is smaller than a Token, leading to both less memory use when stored in the queue but also
13 //     increased speed when pushing to the queue
14 //   * it finds its pair in O(1) time instead of O(N), since pair positions are known at parse time
15 //     and can easily be stored instead of recomputed
16 #[derive(Debug)]
17 pub enum QueueableToken<'i, R> {
18     Start {
19         /// Queue (as a vec) contains both `Start` token and `End` for the same rule.
20         /// This field is an index of corresponding `End` token in vec.
21         end_token_index: usize,
22         /// Position from which rule was tried to parse (or successfully parsed).
23         input_pos: usize,
24     },
25     End {
26         /// Queue (as a vec) contains both `Start` token and `End` for the same rule.
27         /// This filed is an index of corresponding `Start` token in vec.
28         start_token_index: usize,
29         rule: R,
30         tag: Option<&'i str>,
31         /// Position at which successfully parsed rule finished (ended).
32         input_pos: usize,
33     },
34 }
35