syntax_rules.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package kawa.standard;
  2. import kawa.lang.*;
  3. import gnu.lists.*;
  4. import gnu.mapping.Symbol;
  5. import gnu.expr.*;
  6. /** Implement the standard Scheme "syntax-rules" form. */
  7. public class syntax_rules extends Syntax
  8. {
  9. public static final syntax_rules syntax_rules = new syntax_rules();
  10. static { syntax_rules.setName("syntax-rules"); }
  11. public Expression rewriteForm(Pair form, Translator tr) {
  12. Pair pair1 = (Pair) form.getCdr();
  13. Object car1 = pair1.getCar();
  14. Object cdr1 = pair1.getCdr();
  15. Object ellipsis = SyntaxRule.dots3Symbol;
  16. if (Translator.stripSyntax(car1) instanceof Symbol
  17. && cdr1 instanceof Pair) {
  18. Pair pair2 = (Pair) cdr1;
  19. Object car2 = pair2.getCar();
  20. Object cdr2 = pair2.getCdr();
  21. if (car2 instanceof LList) {
  22. ellipsis = car1;
  23. car1 = car2;
  24. cdr1 = cdr2;
  25. }
  26. // otherwise error caught by getLiteralsList
  27. }
  28. Object[] literal_identifiers
  29. = SyntaxPattern.getLiteralsList(car1, null, tr);
  30. SyntaxRules rules = new SyntaxRules(ellipsis, literal_identifiers,
  31. cdr1, tr);
  32. return new QuoteExp(rules);
  33. }
  34. }