PatternScope.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package kawa.lang;
  2. import gnu.expr.*;
  3. import java.util.Vector;
  4. /** Bindings from a <code>syntax-case</code>/<code>syntax-rules</code> pattern. */
  5. public class PatternScope extends LetExp {
  6. PatternScope previousSyntax;
  7. /** Currently visible macro pattern names.
  8. * For the i'th pattern variable, pattern_names.elementAt(i)
  9. * is the name of the variable, */
  10. public Vector pattern_names;
  11. /** Nesting of currently visible macro pattern names.
  12. * For the <code>i</code>'th pattern variable,
  13. * <code>(int) patternNesting.charAt(i)/2</code> is the nesting (in terms of
  14. * number of ellipsis that indicate the variable is repeated).
  15. * The low-order bit indicates that if matched value is the <code>car</code>
  16. * of the value saved in the <code>vars</code> array. */
  17. public StringBuffer patternNesting;
  18. // FIXME - move to Translator?
  19. public Declaration matchArray;
  20. public PatternScope() { }
  21. public static PatternScope push(Translator tr) {
  22. PatternScope newScope = new PatternScope();
  23. // The actual declarations of newScope will be added later,
  24. // in SyntaxPattern#translate.
  25. PatternScope oldScope = tr.patternScope;
  26. newScope.previousSyntax = oldScope;
  27. tr.patternScope = newScope;
  28. if (oldScope == null) {
  29. newScope.pattern_names = new Vector();
  30. newScope.patternNesting = new StringBuffer();
  31. } else {
  32. newScope.pattern_names = (Vector) oldScope.pattern_names.clone();
  33. newScope.patternNesting
  34. = new StringBuffer(oldScope.patternNesting.toString());
  35. }
  36. newScope.setOuter(tr.currentScope());
  37. return newScope;
  38. }
  39. public static void pop(Translator tr) {
  40. tr.patternScope = tr.patternScope.previousSyntax;
  41. }
  42. /*
  43. public void compile(Compilation comp, Target target) {
  44. throw new RuntimeException ("internal error - PatternScope.compile called");
  45. }
  46. */
  47. }