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) (#.base-char-code-limit
)))
17 ;;; constants for readtable character attributes. These are all as in
20 ;;; FIXME: wait a minute. Firstly, I doubt they're in the manual.
21 ;;; Secondly, the numerical order of these constants is coupled with
22 ;;; code in CHAR-CLASS{,2,3} in the reader implementation, so beware
23 ;;; when changing them.
24 (def!constant
+char-attr-whitespace
+ 0)
25 (def!constant
+char-attr-terminating-macro
+ 1)
26 (def!constant
+char-attr-single-escape
+ 2)
27 (def!constant
+char-attr-multiple-escape
+ 3)
28 (def!constant
+char-attr-constituent
+ 4)
29 (def!constant
+char-attr-constituent-dot
+ 5)
30 (def!constant
+char-attr-constituent-expt
+ 6)
31 (def!constant
+char-attr-constituent-slash
+ 7)
32 (def!constant
+char-attr-constituent-digit
+ 8)
33 (def!constant
+char-attr-constituent-sign
+ 9)
34 ;;; the following two are not static but depend on *READ-BASE*.
35 ;;; DECIMAL-DIGIT is for characters being digits in base 10 but not in
36 ;;; base *READ-BASE* (which is therefore perforce smaller than 10);
37 ;;; DIGIT-OR-EXPT is for characters being both exponent markers and
38 ;;; digits in base *READ-BASE* (which is therefore perforce larger
39 ;;; than 10). -- CSR, 2004-03-16
40 (def!constant
+char-attr-constituent-decimal-digit
+ 10)
41 (def!constant
+char-attr-constituent-digit-or-expt
+ 11)
43 (def!constant
+char-attr-package-delimiter
+ 12)
44 (def!constant
+char-attr-invalid
+ 13)
45 ;; Meta: there is no such function as READ-UNQUALIFIED-TOKEN. No biggie.
46 (def!constant
+char-attr-delimiter
+ 14) ; (a fake for READ-UNQUALIFIED-TOKEN)
48 (sb!xc
:defstruct
(readtable (:conc-name nil
)
49 (:constructor make-readtable
())
50 (:predicate readtablep
)
51 ;; ANSI requires a CL:COPY-READTABLE to do
52 ;; a deep copy, so the DEFSTRUCT-generated
53 ;; default is not suitable.
56 "A READTABLE is a data structure that maps characters into syntax
57 types for the Common Lisp expression reader."
58 ;; The CHARACTER-ATTRIBUTE-TABLE is a vector of BASE-CHAR-CODE-LIMIT
59 ;; integers for describing the character type. Conceptually, there
60 ;; are 4 distinct "primary" character attributes:
61 ;; +CHAR-ATTR-WHITESPACE+, +CHAR-ATTR-TERMINATING-MACRO+,
62 ;; +CHAR-ATTR-ESCAPE+, and +CHAR-ATTR-CONSTITUENT+. Non-terminating
63 ;; macros (such as the symbol reader) have the attribute
64 ;; +CHAR-ATTR-CONSTITUENT+.
66 ;; In order to make READ-TOKEN fast, all this information is stored
67 ;; in the character attribute table by having different varieties of
69 (character-attribute-array
70 (make-array base-char-code-limit
71 :element-type
'(unsigned-byte 8)
72 :initial-element
+char-attr-constituent
+)
75 (character-attribute-hash-table (make-hash-table)
78 ;; The CHARACTER-MACRO-TABLE is a vector of BASE-CHAR-CODE-LIMIT
79 ;; functions. One of these functions called with appropriate
80 ;; arguments whenever any non-WHITESPACE character is encountered
81 ;; inside READ-PRESERVING-WHITESPACE. These functions are used to
82 ;; implement user-defined read-macros, system read-macros, and the
83 ;; number-symbol reader.
84 (character-macro-array
85 (make-array base-char-code-limit
:initial-element nil
)
86 :type
(simple-vector #.base-char-code-limit
)
88 (character-macro-hash-table (make-hash-table) :type hash-table
90 (%readtable-case
:upcase
:type
(member :upcase
:downcase
:preserve
:invert
))
91 (%readtable-normalization
#!+sb-unicode t
#!-sb-unicode nil
:type boolean
))
93 (declaim (freeze-type readtable
))