KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > jemacs > lang > defcustom


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