Repository navigation
Expand file tree
/
Copy pathdfa.rs
More file actions
212 lines (190 loc) · 6.22 KB
/
Copy pathdfa.rs
File metadata and controls
212 lines (190 loc) · 6.22 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
use regex_automata::{dfa::Automaton, Input, PatternSet};
use crate::{
args,
util::{self, Table},
};
pub fn run_hybrid(p: &mut lexopt::Parser) -> anyhow::Result<()> {
const USAGE: &'static str = "\
Executes a search for full matches using the lazy DFA regex engine.
USAGE:
regex-cli find match hybrid [-p <pattern> ...] <haystack-path>
regex-cli find match hybrid [-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 hybrid = args::hybrid::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 hybrid,
&mut find,
],
)?;
anyhow::ensure!(
!find.count,
"'which' command does not support reporting counts",
);
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 (nfafwd, time) = util::timeitr(|| thompson.from_hirs(&hirs))?;
table.add("compile forward nfa time", time);
let (re, time) = util::timeitr(|| hybrid.from_nfa(&nfafwd))?;
table.add("build forward hybrid time", time);
let (mut cache, time) = util::timeit(|| re.create_cache());
table.add("cache creation time", time);
let search = |input: &Input<'_>, patset: &mut PatternSet| {
re.try_which_overlapping_matches(&mut cache, input, patset)
};
super::run_search(
&mut table,
&common,
&find,
&input,
&haystack,
re.pattern_len(),
search,
)?;
Ok(())
}
pub fn run_dense(p: &mut lexopt::Parser) -> anyhow::Result<()> {
const USAGE: &'static str = "\
Executes a search for full matches using the dense DFA regex engine.
USAGE:
regex-cli find match dense [-p <pattern> ...] <haystack-path>
regex-cli find match dense [-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 dense = args::dfa::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 dense,
&mut find,
],
)?;
anyhow::ensure!(
!find.count,
"'which' command does not support reporting counts",
);
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 (nfafwd, time) = util::timeitr(|| thompson.from_hirs(&hirs))?;
table.add("compile forward nfa time", time);
let (re, time) = util::timeitr(|| dense.from_nfa(&nfafwd))?;
table.add("build forward dense DFA time", time);
let search = |input: &Input<'_>, patset: &mut PatternSet| {
re.try_which_overlapping_matches(input, patset)
};
super::run_search(
&mut table,
&common,
&find,
&input,
&haystack,
re.pattern_len(),
search,
)?;
Ok(())
}
pub fn run_sparse(p: &mut lexopt::Parser) -> anyhow::Result<()> {
const USAGE: &'static str = "\
Executes a search for full matches using the sparse DFA regex engine.
USAGE:
regex-cli find match sparse [-p <pattern> ...] <haystack-path>
regex-cli find match sparse [-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 sparse = args::dfa::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 sparse,
&mut find,
],
)?;
anyhow::ensure!(
!find.count,
"'which' command does not support reporting counts",
);
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 (nfafwd, time) = util::timeitr(|| thompson.from_hirs(&hirs))?;
table.add("compile forward nfa time", time);
let (re, time) = util::timeitr(|| sparse.from_nfa_sparse(&nfafwd))?;
table.add("build forward sparse DFA time", time);
let search = |input: &Input<'_>, patset: &mut PatternSet| {
re.try_which_overlapping_matches(input, patset)
};
super::run_search(
&mut table,
&common,
&find,
&input,
&haystack,
re.pattern_len(),
search,
)?;
Ok(())
}