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
//! An example of how to use a Structex with this crate's minimal templating support to create
//! a simple 'p' print action.
use Regex;
use ;
// This is a much more complicated, compound expression. It is searching for Rust "impl" blocks
// within a file, filtering out those that look like a trait implementation ("impl X for Y") before
// running a parallel group that breaks the impl block into non-overlapping sections:
// - First the name of the type that owns the impl block is printed
// - Then, a second extract is run to locate all method signatures (up to the opening '{')
// - For each signature, a second nested parallel group is run:
// - If the signature includes "->" we assume it has a return type and we attempt to narrow the
// matching substring to locate both the method name and return type
// - If the signature doesn't include "->", we only narrow and look for the function name.
// - Then, for each signature we run one final parallel group that checks to see if "self" is
// mutable and uses all of that information to print out a summary for the method.
// - The template strings used for each branch are slight modifications of one another
// depending on which branch has been taken.
const SE: &str = r#"
x/^impl(?:<.*?>)?.*? (\w+)(?:.|\n)*?^\}/
v/^impl(?:<.*?>)?.*? for/ {
p/\nimpl {1}/;
x/fn(?:.|\n)*?\{/ {
g/->/ n/fn (\w+)(?:.|\n)*?-> (.*?)\w*\{/ {
g/(&?('. ))?mut self/ p/ mut {1} -> {2}/;
v/(&?('. ))?mut self/ p/ {1} -> {2}/;
};
v/->/ n/fn (\w+)(?:.|\n)*\{/ {
g/(&?('. ))?mut self/ p/ mut {1} -> ()/;
v/(&?('. ))?mut self/ p/ {1} -> ()/;
};
};
}
"#;