01: package kawa.standard;
02:
03: import kawa.lang.*;
04: import gnu.lists.*;
05: import gnu.expr.*;
06:
07: /**
08: * Utility method for try-catch.
09: */
10:
11: public class try_catch {
12: public static Expression rewrite(Object try_part, Object clauses) {
13: Translator tr = (Translator) Compilation.getCurrent();
14: Expression try_part_exp = tr.rewrite(try_part);
15: CatchClause prev = null;
16: CatchClause chain = null;
17: FVector vec = (FVector) clauses;
18: int n = vec.size();
19: for (int i = 0; i < n; i++) {
20: Expression cl = Scheme.lambda.rewrite(vec.get(i), tr);
21: if (cl instanceof ErrorExp)
22: return cl;
23: if (!(cl instanceof LambdaExp))
24: return tr.syntaxError("internal error with try-catch");
25: CatchClause ccl = new CatchClause((LambdaExp) cl);
26: if (prev == null)
27: chain = ccl;
28: else
29: prev.setNext(ccl);
30: prev = ccl;
31: }
32: if (try_part_exp instanceof ErrorExp)
33: return try_part_exp;
34: TryExp texp = new TryExp(try_part_exp, null);
35: texp.setCatchClauses(chain);
36: return texp;
37: }
38: }
|