forked from dylan-sutton-chavez/edge-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.rs
More file actions
57 lines (51 loc) · 1.48 KB
/
ast.rs
File metadata and controls
57 lines (51 loc) · 1.48 KB
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
/* Regex AST and flags, matched directly by the backtracking engine. */
use alloc::{boxed::Box, string::String, vec::Vec};
/* Inline flag state threaded into the matcher. */
#[derive(Clone, Copy, Default)]
pub struct Flags {
pub ignorecase: bool, // (?i)
pub dotall: bool, // (?s), dot also matches newline
pub multiline: bool, // (?m), anchors match at line boundaries
}
/* One entry inside a bracket set. Predefined classes stay symbolic. */
#[derive(Clone)]
pub enum ClassItem {
Ch(char),
Range(char, char),
Digit,
NotDigit,
Word,
NotWord,
Space,
NotSpace,
}
#[derive(Clone)]
pub enum Node {
Empty,
Char(char),
AnyChar, // the dot
Class { items: Vec<ClassItem>, negated: bool },
Start, // caret anchor
End, // dollar anchor
WordBoundary, // backslash b
NotWordBoundary, // backslash B
Group { index: usize, name: Option<String>, node: Box<Node> },
NonCap(Box<Node>),
Concat(Vec<Node>),
Alt(Vec<Node>),
Repeat { node: Box<Node>, min: usize, max: Option<usize>, greedy: bool },
Backref(usize),
Look { node: Box<Node>, behind: bool, negative: bool },
}
/* Compiled pattern, the tree plus capture metadata and flags. */
pub struct Program {
pub root: Node,
pub group_count: usize,
pub names: Vec<(String, usize)>, // maps a group name to its index
pub flags: Flags,
}
#[derive(Debug)]
pub struct ParseError {
pub msg: &'static str,
pub pos: usize, // codepoint offset into the pattern
}