X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Freadtable.lisp;h=0df3891f81867bb65d7e8ba2093fabcb6c36781b;hb=HEAD;hp=0ac86adb00de241636e4de0e9b054a5f37d8db96;hpb=ce02ab2ecd9c6ae2e570abd8c93ebf3be55bbdad;p=sbcl.git diff --git a/src/code/readtable.lisp b/src/code/readtable.lisp index 0ac86ad..0df3891 100644 --- a/src/code/readtable.lisp +++ b/src/code/readtable.lisp @@ -12,39 +12,75 @@ (in-package "SB!IMPL") (sb!xc:deftype attribute-table () - '(simple-array (unsigned-byte 8) (#.char-code-limit))) + '(simple-array (unsigned-byte 8) (#.base-char-code-limit))) + +;;; constants for readtable character attributes. These are all as in +;;; the manual. +;;; +;;; FIXME: wait a minute. Firstly, I doubt they're in the manual. +;;; Secondly, the numerical order of these constants is coupled with +;;; code in CHAR-CLASS{,2,3} in the reader implementation, so beware +;;; when changing them. +(def!constant +char-attr-whitespace+ 0) +(def!constant +char-attr-terminating-macro+ 1) +(def!constant +char-attr-single-escape+ 2) +(def!constant +char-attr-multiple-escape+ 3) +(def!constant +char-attr-constituent+ 4) +(def!constant +char-attr-constituent-dot+ 5) +(def!constant +char-attr-constituent-expt+ 6) +(def!constant +char-attr-constituent-slash+ 7) +(def!constant +char-attr-constituent-digit+ 8) +(def!constant +char-attr-constituent-sign+ 9) +;;; the following two are not static but depend on *READ-BASE*. +;;; DECIMAL-DIGIT is for characters being digits in base 10 but not in +;;; base *READ-BASE* (which is therefore perforce smaller than 10); +;;; DIGIT-OR-EXPT is for characters being both exponent markers and +;;; digits in base *READ-BASE* (which is therefore perforce larger +;;; than 10). -- CSR, 2004-03-16 +(def!constant +char-attr-constituent-decimal-digit+ 10) +(def!constant +char-attr-constituent-digit-or-expt+ 11) + +(def!constant +char-attr-package-delimiter+ 12) +(def!constant +char-attr-invalid+ 13) +(def!constant +char-attr-delimiter+ 14) ; (a fake for READ-UNQUALIFIED-TOKEN) (sb!xc:defstruct (readtable (:conc-name nil) - (:predicate readtablep)) + (:predicate readtablep) + ;; ANSI requires a CL:COPY-READTABLE to do + ;; a deep copy, so the DEFSTRUCT-generated + ;; default is not suitable. + (:copier nil)) #!+sb-doc - "Readtable is a data structure that maps characters into syntax - types for the Common Lisp expression reader." - ;; The CHARACTER-ATTRIBUTE-TABLE is a vector of CHAR-CODE-LIMIT + "A READTABLE is a data structure that maps characters into syntax +types for the Common Lisp expression reader." + ;; The CHARACTER-ATTRIBUTE-TABLE is a vector of BASE-CHAR-CODE-LIMIT ;; integers for describing the character type. Conceptually, there - ;; are 4 distinct "primary" character attributes: WHITESPACE, - ;; TERMINATING-MACRO, ESCAPE, and CONSTITUENT. Non-terminating + ;; are 4 distinct "primary" character attributes: + ;; +CHAR-ATTR-WHITESPACE+, +CHAR-ATTR-TERMINATING-MACRO+, + ;; +CHAR-ATTR-ESCAPE+, and +CHAR-ATTR-CONSTITUENT+. Non-terminating ;; macros (such as the symbol reader) have the attribute - ;; CONSTITUENT. + ;; +CHAR-ATTR-CONSTITUENT+. ;; - ;; In order to make the READ-TOKEN fast, all this information is - ;; stored in the character attribute table by having different - ;; varieties of constituents. - (character-attribute-table - (make-array char-code-limit - :element-type '(unsigned-byte 8) - :initial-element constituent) + ;; In order to make READ-TOKEN fast, all this information is stored + ;; in the character attribute table by having different varieties of + ;; constituents. + (character-attribute-array + (make-array base-char-code-limit + :element-type '(unsigned-byte 8) + :initial-element +char-attr-constituent+) :type attribute-table) - ;; The CHARACTER-MACRO-TABLE is a vector of CHAR-CODE-LIMIT + (character-attribute-hash-table (make-hash-table) :type hash-table) + ;; The CHARACTER-MACRO-TABLE is a vector of BASE-CHAR-CODE-LIMIT ;; functions. One of these functions called with appropriate ;; arguments whenever any non-WHITESPACE character is encountered ;; inside READ-PRESERVING-WHITESPACE. These functions are used to ;; implement user-defined read-macros, system read-macros, and the ;; number-symbol reader. - (character-macro-table - (make-array char-code-limit :initial-element #'undefined-macro-char) - :type (simple-vector #.char-code-limit)) - ;; DISPATCH-TABLES entry, which is an alist from dispatch characters - ;; to vectors of CHAR-CODE-LIMIT functions, for use in defining - ;; dispatching macros (like #-macro). + (character-macro-array + (make-array base-char-code-limit :initial-element #'undefined-macro-char) + :type (simple-vector #.base-char-code-limit)) + (character-macro-hash-table (make-hash-table) :type hash-table) + ;; an alist from dispatch characters to hash-tables akin to + ;; CHARACTER-MACRO-HASH-TABLE. (dispatch-tables () :type list) - (readtable-case :upcase :type (member :upcase :downcase :preserve :invert))) + (%readtable-case :upcase :type (member :upcase :downcase :preserve :invert)))