raz / src / test / Recover.raz

38 lines · 1.0 KiB · raw · history · last change 596c810a

1(* Tests going on after an error, as the parser does with try: a driver
2 reads a file's symbols and reports each name `bad` as an error,
3 several calls deep; the error comes back up through them, and the
4 driver reads on from the next symbol. *)
5module Recover;
6import Out, Files, Diag, Scan;
7
8var failed, names: INT;
9
10proc deep(n: INT): ERROR;
11begin
12 if n > 0 then
13 try deep(n - 1);
14 return nil;
15 end;
16 return Scan.mark("a bad name");
17end;
18
19proc main*;
20var err: ERROR;
21begin
22 if LEN(Scan.open(Files.arg(1))) # 0 then Diag.fatal("no file"); end;
23 while Scan.tok # Scan.sEof do
24 Scan.next;
25 if Scan.tok = Scan.sIdent then
26 INC(names);
27 if Scan.nameOf(Scan.id) = "bad" then
28 err := deep(5);
29 if err # nil then INC(failed); end;
30 end;
31 end;
32 end;
33 Out.int(names); Out.str(" names, "); Out.int(failed); Out.str(" failed, ");
34 Out.int(Diag.errors); Out.str(" errors\n");
35 Diag.finish;
36end;
37
38end Recover.