syntax-rules-data.scm 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Mike Sperber
  3. ; These define the format for compiled SYNTAX-RULES patterns and templates,
  4. ; which are the shared data between the compilation and expansion phases.
  5. ;----------------
  6. (define (make-pattern-variable v rank)
  7. (vector 'var v rank))
  8. (define (pattern-variable? x)
  9. (and (vector? x)
  10. (eq? (vector-ref x 0) 'var)))
  11. (define (pattern-variable-name pattern-var) (vector-ref pattern-var 1))
  12. (define (pattern-variable-rank pattern-var) (vector-ref pattern-var 2))
  13. ;----------------
  14. (define (make-ellipsis-form form vars)
  15. (vector 'ellipsis form vars))
  16. (define (ellipsis-form? x)
  17. (and (vector? x)
  18. (eq? (vector-ref x 0) 'ellipsis)))
  19. (define (ellipsis-form-body ellipsis) (vector-ref ellipsis 1))
  20. (define (ellipsis-form-vars ellipsis) (vector-ref ellipsis 2))
  21. ;----------------
  22. ; Because we use vectors for pattern variables and ellipses we need to
  23. ; escape any actual vectors that occur. This isn't as bad as it might
  24. ; seem because vectors in patterns and templates need to be converted
  25. ; to lists in any case.
  26. (define (make-vector-marker contents)
  27. (vector 'vector contents))
  28. (define (vector-marker? x)
  29. (and (vector? x)
  30. (eq? (vector-ref x 0) 'vector)))
  31. (define (vector-marker-contents vector-marker) (vector-ref vector-marker 1))