KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > kawa > lang > PatternScope


1 package kawa.lang;
2 import gnu.expr.*;
3 import java.util.Vector JavaDoc;
4
5 /** Bindings from a <code>syntax-case</code>/<code>syntax-rules</code> pattern. */
6
7 public class PatternScope extends LetExp
8 {
9   PatternScope previousSyntax;
10
11   /** Currently visible macro pattern names.
12    * For the i'th pattern variable, pattern_names.elementAt(i)
13    * is the name of the variable, */

14   public Vector JavaDoc pattern_names;
15
16   /** Nesting of currently visible macro pattern names.
17    * For the <code>i</code>'th pattern variable,
18    * <code>(int) patternNesting.charAt(i)/2</code> is the nesting (in terms of
19    * number of ellipsis that indicate the variable is repeated).
20    * The low-order bit indicates that if matched value is the <code>car</code>
21    * of the value saved in the <code>vars</code> array. */

22   public StringBuffer JavaDoc patternNesting;
23
24   // FIXME - move to Translator?
25
public Declaration matchArray;
26
27   public PatternScope ()
28   {
29     super(null);
30   }
31
32   public static PatternScope push (Translator tr)
33   {
34     PatternScope newScope = new PatternScope();
35     PatternScope oldScope = tr.patternScope;
36     newScope.previousSyntax = oldScope;
37     tr.patternScope = newScope;
38     if (oldScope == null)
39       {
40     newScope.pattern_names = new Vector JavaDoc();
41     newScope.patternNesting = new StringBuffer JavaDoc();
42       }
43     else
44       {
45     newScope.pattern_names = (Vector JavaDoc) oldScope.pattern_names.clone();
46     newScope.patternNesting
47       = new StringBuffer JavaDoc(oldScope.patternNesting.toString());
48       }
49     newScope.outer = tr.currentScope();
50     return newScope;
51   }
52
53   public static void pop (Translator tr)
54   {
55     tr.patternScope = tr.patternScope.previousSyntax;
56   }
57
58   /*
59   public void compile (Compilation comp, Target target)
60   {
61     throw new RuntimeException ("internal error - PatternScope.compile called");
62   }
63   */

64
65 }
66
Popular Tags