gen-exercises.awk 957 Bytes
Newer Older
1
BEGIN {
2
3
    in_solution = 0; # for the advanced solution syntax
    in_auto_solution = 0; # for the simple solution syntax that recognizes `Qed.`
4
5
}
{ # on every line of the input
6
7
8
9
    if (match($0, /^( *)\(\* *SOLUTION *\*\) *Proof.$/, groups)) {
        print groups[1] "Proof."
        in_auto_solution = 1
    } else if (in_auto_solution == 1 && match($0, /^( *)Qed.$/, groups)) {
10
11
        print groups[1] "  (* exercise *)"
        print groups[1] "Admitted."
12
13
14
        in_auto_solution = 0
    } else if (match($0, /^( *)\(\* *BEGIN SOLUTION *\*\)$/, groups)) {
        in_solution = 1
15
16
17
18
    } else if (match($0, /^( *)\(\* *END SOLUTION BEGIN TEMPLATE *$/, groups)) {
        in_solution = 0
    } else if (match($0, /^( *)END TEMPLATE *\*\)$/, groups)) {
        # Nothing to do, just do not print this line.
19
    } else if (in_solution == 0 && in_auto_solution == 0) {
20
21
22
23
        gsub("From solutions Require", "From exercises Require")
        print
    }
}