Repository navigation
Expand file tree
/
Copy pathnfa.rs
More file actions
156 lines (141 loc) · 4.63 KB
/
Copy pathnfa.rs
File metadata and controls
156 lines (141 loc) · 4.63 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use regex_automata::Input;
use crate::{
args,
util::{self, Table},
};
pub fn run_backtrack(p: &mut lexopt::Parser) -> anyhow::Result<()> {
const USAGE: &'static str = "\
Executes a search for full matches using the BoundedBacktracker regex engine.
USAGE:
regex-cli find match backtrack [-p <pattern> ...] <haystack-path>
regex-cli find match backtrack [-p <pattern> ...] -y <haystack>
TIP:
use -h for short docs and --help for long docs
OPTIONS:
%options%
";
let mut common = args::common::Config::default();
let mut input = args::input::Config::default();
let mut patterns = args::patterns::Config::only_flags();
let mut haystack = args::haystack::Config::default();
let mut syntax = args::syntax::Config::default();
let mut thompson = args::thompson::Config::default();
let mut backtrack = args::backtrack::Config::default();
let mut find = super::super::Config::default();
args::configure(
p,
USAGE,
&mut [
&mut common,
&mut input,
&mut patterns,
&mut haystack,
&mut syntax,
&mut thompson,
&mut backtrack,
&mut find,
],
)?;
let pats = patterns.get(&syntax)?;
let mut table = Table::empty();
let (asts, time) = util::timeitr(|| syntax.asts(&pats))?;
table.add("parse time", time);
let (hirs, time) = util::timeitr(|| syntax.hirs(&pats, &asts))?;
table.add("translate time", time);
let (nfa, time) = util::timeitr(|| thompson.from_hirs(&hirs))?;
table.add("compile nfa time", time);
let (re, time) = util::timeitr(|| backtrack.from_nfa(&nfa))?;
table.add("build backtracker time", time);
let (mut cache, time) = util::timeit(|| re.create_cache());
table.add("cache creation time", time);
let (mut caps, time) = util::timeit(|| re.create_captures());
table.add("captures creation time", time);
let search = |input: &Input<'_>| {
re.try_search(&mut cache, input, &mut caps)?;
Ok(caps.get_match())
};
if find.count {
super::run_counts(
&mut table,
&common,
&find,
&input,
&haystack,
re.pattern_len(),
search,
)?;
} else {
super::run_search(
&mut table, &common, &find, &input, &haystack, search,
)?;
}
Ok(())
}
pub fn run_pikevm(p: &mut lexopt::Parser) -> anyhow::Result<()> {
const USAGE: &'static str = "\
Executes a search for full matches using the PikeVM regex engine.
USAGE:
regex-cli find match pikevm [-p <pattern> ...] <haystack-path>
regex-cli find match pikevm [-p <pattern> ...] -y <haystack>
TIP:
use -h for short docs and --help for long docs
OPTIONS:
%options%
";
let mut common = args::common::Config::default();
let mut input = args::input::Config::default();
let mut patterns = args::patterns::Config::only_flags();
let mut haystack = args::haystack::Config::default();
let mut syntax = args::syntax::Config::default();
let mut thompson = args::thompson::Config::default();
let mut pikevm = args::pikevm::Config::default();
let mut find = super::super::Config::default();
args::configure(
p,
USAGE,
&mut [
&mut common,
&mut input,
&mut patterns,
&mut haystack,
&mut syntax,
&mut thompson,
&mut pikevm,
&mut find,
],
)?;
let pats = patterns.get(&syntax)?;
let mut table = Table::empty();
let (asts, time) = util::timeitr(|| syntax.asts(&pats))?;
table.add("parse time", time);
let (hirs, time) = util::timeitr(|| syntax.hirs(&pats, &asts))?;
table.add("translate time", time);
let (nfa, time) = util::timeitr(|| thompson.from_hirs(&hirs))?;
table.add("compile nfa time", time);
let (re, time) = util::timeitr(|| pikevm.from_nfa(&nfa))?;
table.add("build pikevm time", time);
let (mut cache, time) = util::timeit(|| re.create_cache());
table.add("cache creation time", time);
let (mut caps, time) = util::timeit(|| re.create_captures());
table.add("captures creation time", time);
let search = |input: &Input<'_>| {
re.search(&mut cache, input, &mut caps);
Ok(caps.get_match())
};
if find.count {
super::run_counts(
&mut table,
&common,
&find,
&input,
&haystack,
re.pattern_len(),
search,
)?;
} else {
super::run_search(
&mut table, &common, &find, &input, &haystack, search,
)?;
}
Ok(())
}