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
pub mod builder;
pub mod destination;
pub mod rewrite;
use symbol::Symbol;
use self::Separator::*;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Sequence<H> {
pub lhs: Symbol,
pub rhs: Symbol,
pub start: u32,
pub end: Option<u32>,
pub separator: Separator,
pub history: H,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Separator {
Trailing(Symbol),
Proper(Symbol),
Liberal(Symbol),
Null,
}
impl<H> Sequence<H> {
pub fn inclusive(mut self, start: u32, end: Option<u32>) -> Self {
self.start = start;
self.end = end;
self
}
pub fn separator(mut self, sep: Separator) -> Self {
self.separator = sep;
self
}
}
impl Separator {
pub fn prefix_separator(self) -> Self {
match self {
Proper(sep) | Liberal(sep) => Trailing(sep),
other => other,
}
}
}
impl Into<Option<Symbol>> for Separator {
fn into(self) -> Option<Symbol> {
match self {
Trailing(sep) => Some(sep),
_ => None,
}
}
}