01: package gnu.jemacs.lang;
02:
03: import kawa.lang.*;
04: import gnu.lists.*;
05: import gnu.expr.*;
06: import gnu.mapping.Symbol;
07:
08: public class defcustom extends Syntax {
09: public boolean scanForDefinitions(Pair st, java.util.Vector forms,
10: ScopeExp defs, Translator tr) {
11: if (!(st.cdr instanceof Pair))
12: return super .scanForDefinitions(st, forms, defs, tr);
13: Pair p = (Pair) st.cdr;
14: Object name = p.car;
15: if (name instanceof String || name instanceof Symbol) {
16: Declaration decl = defs.lookup(name);
17: if (decl == null) {
18: decl = new Declaration(name);
19: defs.addDeclaration(decl);
20: } else
21: tr.error('w', "duplicate declaration for `" + name
22: + "'");
23: p = Translator.makePair(p, decl, p.cdr);
24: st = Translator.makePair(st, this , p);
25: if (defs instanceof ModuleExp) {
26: decl.setCanRead(true);
27: decl.setCanWrite(true);
28: }
29: }
30: forms.addElement(st);
31: return true;
32: }
33:
34: public Expression rewriteForm(Pair form, Translator tr) {
35: Object obj = form.cdr;
36: String name = null;
37: Expression value = null;
38: Declaration decl = null;
39:
40: if (obj instanceof Pair) {
41: Pair p1 = (Pair) obj;
42: if (p1.car instanceof Declaration) {
43: decl = (Declaration) p1.car;
44: name = decl.getName();
45: if (p1.cdr instanceof Pair) {
46: Pair p2 = (Pair) p1.cdr;
47: value = tr.rewrite(p2.car);
48: if (p2.cdr != LList.Empty) {
49: // Handle the defcustom options. FIXME.
50: }
51: } else if (p1.cdr != LList.Empty)
52: name = null;
53: }
54: }
55: if (name == null)
56: return tr.syntaxError("invalid syntax for " + getName());
57: SetExp sexp = new SetExp(name, value);
58: sexp.setDefining(true);
59: if (decl != null) {
60: sexp.setBinding(decl);
61: if (decl.context instanceof ModuleExp && decl.getCanWrite())
62: value = null;
63: decl.noteValue(value);
64: }
65: return sexp;
66: }
67:
68: }
|