-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRuntimeUtils.re
More file actions
38 lines (36 loc) · 1.27 KB
/
RuntimeUtils.re
File metadata and controls
38 lines (36 loc) · 1.27 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
module RP = PackTypes.Path;
let rec greedy = (~mergeErrors, ~emptyErrors, loop, min, max, subr, i, path, greedyCount, isNegated) =>
/* implements e* e+ e? */
switch max {
| Some(0) => (i, [], emptyErrors)
| _ =>
if (min > 0) {
/* we must match at least min or fail */
let (i', found, err) = loop(i, [subr], [RP.Iter(greedyCount), ...path], 0, isNegated);
if (i' >= i) {
let (i'', children, merr) =
greedy(~mergeErrors, ~emptyErrors, loop, min - 1, max, subr, i', path, greedyCount + 1, isNegated);
(i'', List.concat([found, children]), mergeErrors(err, merr))
} else {
(Lexing.dummy_pos, [], err)
}
} else {
/* try matching, doesn't matter if we fail */
let (i', children, err) = loop(i, [subr], [RP.Iter(greedyCount), ...path], 0, isNegated);
if (i' > i) {
let max =
switch max {
| None => None
| Some(n) => Some(n - 1)
};
let (i'', more, merr) = greedy(~mergeErrors, ~emptyErrors, loop, 0, max, subr, i', path, greedyCount + 1, isNegated);
(i'', List.concat([children, more]), mergeErrors(err, merr))
} else {
(
i,
[],
err /* don't fail, return longest match */
)
}
}
};