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
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct Grammar {
pub lookup: HashMap<String, usize>,
pub definitions: Vec<Definition>,
}
#[derive(Clone, Debug)]
pub struct Definition {
pub name: String,
pub sequence: Expression,
}
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
pub enum Expression {
Dot,
Whitespace,
EndOfInput,
XidIdentifier,
Definition(usize),
MemoDefinition(usize),
StringLiteral(String),
Regex(String),
MustMatch(Box<Expression>),
MustNotMatch(Box<Expression>),
Optional(Box<Expression>),
Any(Box<Expression>),
More(Box<Expression>),
List(Vec<Expression>),
Alternatives(Vec<Expression>),
}