3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!IMPL")
14 (sb!xc:deftype attribute-table ()
15 '(simple-array (unsigned-byte 8) (#.sb!xc:char-code-limit)))
17 ;;; constants for readtable character attributes. These are all as in
19 (def!constant +char-attr-whitespace+ 0)
20 (def!constant +char-attr-terminating-macro+ 1)
21 (def!constant +char-attr-escape+ 2)
22 (def!constant +char-attr-constituent+ 3)
23 (def!constant +char-attr-constituent-dot+ 4)
24 (def!constant +char-attr-constituent-expt+ 5)
25 (def!constant +char-attr-constituent-slash+ 6)
26 (def!constant +char-attr-constituent-digit+ 7)
27 (def!constant +char-attr-constituent-sign+ 8)
28 ;;; the following two are not static but depend on *READ-BASE*.
29 ;;; DECIMAL-DIGIT is for characters being digits in base 10 but not in
30 ;;; base *READ-BASE* (which is therefore perforce smaller than 10);
31 ;;; DIGIT-OR-EXPT is for characters being both exponent markers and
32 ;;; digits in base *READ-BASE* (which is therefore perforce larger
33 ;;; than 10). -- CSR, 2004-03-16
34 (def!constant +char-attr-constituent-decimal-digit+ 9)
35 (def!constant +char-attr-constituent-digit-or-expt+ 10)
37 (def!constant +char-attr-multiple-escape+ 11)
38 (def!constant +char-attr-package-delimiter+ 12)
39 (def!constant +char-attr-delimiter+ 13) ; (a fake for READ-UNQUALIFIED-TOKEN)
41 (sb!xc:defstruct (readtable (:conc-name nil)
42 (:predicate readtablep)
43 ;; ANSI requires a CL:COPY-READTABLE to do
44 ;; a deep copy, so the DEFSTRUCT-generated
45 ;; default is not suitable.
48 "A READTABLE is a data structure that maps characters into syntax
49 types for the Common Lisp expression reader."
50 ;; The CHARACTER-ATTRIBUTE-TABLE is a vector of CHAR-CODE-LIMIT
51 ;; integers for describing the character type. Conceptually, there
52 ;; are 4 distinct "primary" character attributes:
53 ;; +CHAR-ATTR-WHITESPACE+, +CHAR-ATTR-TERMINATING-MACRO+,
54 ;; +CHAR-ATTR-ESCAPE+, and +CHAR-ATTR-CONSTITUENT+. Non-terminating
55 ;; macros (such as the symbol reader) have the attribute
56 ;; +CHAR-ATTR-CONSTITUENT+.
58 ;; In order to make READ-TOKEN fast, all this information is stored
59 ;; in the character attribute table by having different varieties of
61 (character-attribute-table
62 (make-array sb!xc:char-code-limit
63 :element-type '(unsigned-byte 8)
64 :initial-element +char-attr-constituent+)
65 :type attribute-table)
66 ;; The CHARACTER-MACRO-TABLE is a vector of CHAR-CODE-LIMIT
67 ;; functions. One of these functions called with appropriate
68 ;; arguments whenever any non-WHITESPACE character is encountered
69 ;; inside READ-PRESERVING-WHITESPACE. These functions are used to
70 ;; implement user-defined read-macros, system read-macros, and the
71 ;; number-symbol reader.
72 (character-macro-table
73 (make-array sb!xc:char-code-limit :initial-element #'undefined-macro-char)
74 :type (simple-vector #.sb!xc:char-code-limit))
75 ;; an alist from dispatch characters to vectors of CHAR-CODE-LIMIT
76 ;; functions, for use in defining dispatching macros (like #-macro)
77 (dispatch-tables () :type list)
78 (readtable-case :upcase :type (member :upcase :downcase :preserve :invert)))