From bac4b5c9de3c304b114834b50bab7204070dd6d1 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Fri, 16 Oct 2026 17:30:47 +0300 Subject: [PATCH] refuse a char literal that is not one byte MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A char is C's, and #\λ came out a multi-character constant whose value is the C compiler's to choose. --- reader.scm | 5 +++++ tests/reader.scm | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/reader.scm b/reader.scm index 960bea3..3e22f10 100644 --- a/reader.scm +++ b/reader.scm @@ -448,10 +448,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 "") diff --git a/tests/reader.scm b/tests/reader.scm index 86412a6..dde7bbe 100644 --- a/tests/reader.scm +++ b/tests/reader.scm @@ -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")