home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / runtime / syntab.scm < prev    next >
Text File  |  1999-01-02  |  3KB  |  79 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: syntab.scm,v 14.5 1999/01/02 06:19:10 cph Exp $
  4.  
  5. Copyright (c) 1988-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. |#
  21.  
  22. ;;;; Syntax Table
  23. ;;; package: (runtime syntax-table)
  24.  
  25. (declare (usual-integrations))
  26.  
  27. (define-structure (syntax-table (constructor %make-syntax-table)
  28.                 (conc-name syntax-table/))
  29.   alist
  30.   (parent false read-only true))
  31.  
  32. (define (make-syntax-table #!optional parent)
  33.   (%make-syntax-table '()
  34.               (if (default-object? parent)
  35.               false
  36.               (guarantee-syntax-table parent 'MAKE-SYNTAX-TABLE))))
  37.  
  38. (define (guarantee-syntax-table table procedure)
  39.   (if (not (syntax-table? table))
  40.       (error:wrong-type-argument table "syntax table" procedure))
  41.   table)
  42.  
  43. (define (syntax-table/ref table name)
  44.   (guarantee-syntax-table table 'SYNTAX-TABLE/REF)
  45.   (let loop ((table table))
  46.     (and table
  47.      (let ((entry (assq name (syntax-table/alist table))))
  48.        (if entry
  49.            (cdr entry)
  50.            (loop (syntax-table/parent table)))))))
  51.  
  52. (define syntax-table-ref
  53.   syntax-table/ref)
  54.  
  55. (define (syntax-table/define table name transform)
  56.   (guarantee-syntax-table table 'SYNTAX-TABLE/DEFINE)
  57.   (let ((entry (assq name (syntax-table/alist table))))
  58.     (if entry
  59.     (set-cdr! entry transform)
  60.     (set-syntax-table/alist! table
  61.                  (cons (cons name transform)
  62.                        (syntax-table/alist table))))))
  63.  
  64. (define syntax-table-define
  65.   syntax-table/define)
  66.  
  67. (define (syntax-table/defined-names table)
  68.   (map car (syntax-table/alist table)))
  69.  
  70. (define (syntax-table/copy table)
  71.   (guarantee-syntax-table table 'SYNTAX-TABLE/COPY)
  72.   (let loop ((table table))
  73.     (and table
  74.      (%make-syntax-table (alist-copy (syntax-table/alist table))
  75.                  (loop (syntax-table/parent table))))))
  76.  
  77. (define (syntax-table/extend table alist)
  78.   (guarantee-syntax-table table 'SYNTAX-TABLE/EXTEND)
  79.   (%make-syntax-table (alist-copy alist) table))