1
0
forked from alex-eg/sex

refuse a char literal that is not one byte

A char is C's, and #\λ came out a multi-character constant whose value
is the C compiler's to choose.
This commit is contained in:
2026-10-16 17:30:47 +03:00
parent 41945606f6
commit 192ed2ba64
2 changed files with 13 additions and 0 deletions

View File

@@ -445,10 +445,15 @@
("delete" . #\delete) ("escape" . #\escape) ("alarm" . #\alarm)
("backspace" . #\backspace)))
;;; A char is C's, one byte: #\λ was a multi-character constant, whose
;;; value is the C compiler's to choose
(define (read-char-lit port)
(let ((first (get-ch port)))
(when (eof-object? first)
(error "Unexpected end of input in character literal"))
(when (> (char->integer first) 127)
(error "a char is one byte, and this is not: write its code point, or a string"
first))
(if (char-alphabetic? first)
(let ((rest (read-atom-string port)))
(if (string=? rest "")

View File

@@ -115,6 +115,14 @@
(test "a surrogate is no character"
"no character has this code point" (read-error "\"\\uD800\""))
;; A char is C's, one byte, and #\λ came out a multi-character
;; constant whose value is the compiler's to choose
(test "a char is one byte"
"a char is one byte, and this is not: write its code point, or a string"
(read-error "#\\λ"))
(test "Latin-1 is no exception" #t (string? (read-error "#\\é")))
(reader-test '(#\a #\~ #\space) "#\\a #\\~ #\\space")
;; `;' comments are preserved as (comment "...") forms
(reader-test '((comment " hi")) "; hi")
(reader-test '((comment ";; Prototypes")) ";;; Prototypes")