| 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. *) |
| 5 | module Recover; |
| 6 | import Out, Files, Diag, Scan; |
| 7 | |
| 8 | var failed, names: INT; |
| 9 | |
| 10 | proc deep(n: INT): ERROR; |
| 11 | begin |
| 12 | if n > 0 then |
| 13 | try deep(n - 1); |
| 14 | return nil; |
| 15 | end; |
| 16 | return Scan.mark("a bad name"); |
| 17 | end; |
| 18 | |
| 19 | proc main*; |
| 20 | var err: ERROR; |
| 21 | begin |
| 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; |
| 36 | end; |
| 37 | |
| 38 | end Recover. |