From 868daed6cef34fc47d3abd68fbeb7a5399964432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= Date: Fri, 24 Jan 2025 20:54:03 +0100 Subject: [PATCH] Treats # as a delimited in R6RS mode when reading numbers (fixes #687) --- mats/6.ms | 21 +++++++++++++-------- mats/root-experr-compile-0-f-f-f | 6 +++--- s/read.ss | 16 +++++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/mats/6.ms b/mats/6.ms index ea25fd6c1..431364457 100644 --- a/mats/6.ms +++ b/mats/6.ms @@ -1,12 +1,12 @@ ;;; 6.ms ;;; Copyright 1984-2017 Cisco Systems, Inc. -;;; +;;; ;;; Licensed under the Apache License, Version 2.0 (the "License"); ;;; you may not use this file except in compliance with the License. ;;; You may obtain a copy of the License at -;;; +;;; ;;; http://www.apache.org/licenses/LICENSE-2.0 -;;; +;;; ;;; Unless required by applicable law or agreed to in writing, software ;;; distributed under the License is distributed on an "AS IS" BASIS, ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -78,7 +78,7 @@ ; and write-char---and builds testfile.ss for the next test (equal? (call-with-values (lambda () - (with-output-to-file "testfile.ss" + (with-output-to-file "testfile.ss" (lambda () (for-each (lambda (c) (write-char c)) (string->list "a b c d e")) @@ -103,7 +103,7 @@ ; and write-char---and builds testfile.ss for the next test (equal? (call-with-values (lambda () - (call-with-output-file "testfile.ss" + (call-with-output-file "testfile.ss" (lambda (p) (for-each (lambda (c) (write-char c p)) (string->list "a b c d e")) @@ -1016,7 +1016,7 @@ (error? (fasl-write 'any (let-values ([(o get) (open-bytevector-output-port)]) o) 10)) (error? (fasl-read (open-bytevector-input-port #vu8()) 'load #f)) (error? (fasl-read (open-bytevector-input-port #vu8()) 'load 10)) - + (let-values ([(o get) (open-bytevector-output-port)]) (fasl-write '(apple (banana cream pie) (vector coconut banana cream)) o (lambda (v) (or (eq? v 'banana) @@ -1719,6 +1719,11 @@ (equal? (format "~s" "\bab\nc\f\rd\t\v\a") "\"\\bab\\nc\\f\\rd\\t\\v\\a\"") ) +(mat r6rs + (equal? '(3 #f) (let ([ip (open-input-string "#!r6rs 3#f")]) + (let* ([x (read ip)] [y (read ip)]) + (list x y))))) + (mat read-token (let ([ip (open-input-string "(cons 33 #;hello \"rot\")")]) (and (let-values ([vals (read-token ip)]) @@ -2816,12 +2821,12 @@ (load "fatfib.ss" compile)) (procedure? fatfib)) (equal? ((inspect/object fatfib) 'type) 'procedure) - (equal? + (equal? (call-with-values (lambda () (((inspect/object fatfib) 'code) 'source-path)) list) (list (format "../examples~afatfib.ss" (directory-separator)) 16 4)) - (equal? + (equal? (parameterize ([source-directories '("." "../examples")]) (call-with-values (lambda () (((inspect/object fatfib) 'code) 'source-path)) diff --git a/mats/root-experr-compile-0-f-f-f b/mats/root-experr-compile-0-f-f-f index e8c2d2edc..1d2765f75 100644 --- a/mats/root-experr-compile-0-f-f-f +++ b/mats/root-experr-compile-0-f-f-f @@ -4881,7 +4881,7 @@ cp0.mo:Expected error in mat expand/optimize-output: "expand/optimize-output: #< 6.mo:Expected error in mat read-test: "read: |...| symbol escape syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat read-test: "read: @abc symbol syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat read-test: "read: 123a symbol syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". -6.mo:Expected error in mat read-test: "read: 123# number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". +6.mo:Expected error in mat read-test: "read: invalid sharp-sign prefix # 6.mo:Expected error in mat read-test: "read: 1/2e2 number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat read-test: "read: #x.3 number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat read-test: "read: alternative boolean syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". @@ -5710,7 +5710,7 @@ cp0.mo:Expected error in mat expand/optimize-output: "expand/optimize-output: #< 6.mo:Expected error in mat load-test: "read: |...| symbol escape syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat load-test: "read: @abc symbol syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat load-test: "read: 123a symbol syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". -6.mo:Expected error in mat load-test: "read: 123# number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". +6.mo:Expected error in mat load-test: "read: invalid sharp-sign prefix # 6.mo:Expected error in mat load-test: "read: 1/2e2 number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat load-test: "read: #x.3 number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat load-test: "read: alternative boolean syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". @@ -6539,7 +6539,7 @@ cp0.mo:Expected error in mat expand/optimize-output: "expand/optimize-output: #< 6.mo:Expected error in mat compile-test: "read: |...| symbol escape syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat compile-test: "read: @abc symbol syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat compile-test: "read: 123a symbol syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". -6.mo:Expected error in mat compile-test: "read: 123# number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". +6.mo:Expected error in mat compile-test: "read: invalid sharp-sign prefix # 6.mo:Expected error in mat compile-test: "read: 1/2e2 number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat compile-test: "read: #x.3 number syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". 6.mo:Expected error in mat compile-test: "read: alternative boolean syntax is not allowed in #!r6rs mode at line 3, char 8 of testfile.ss". diff --git a/s/read.ss b/s/read.ss index 543cbe88f..1074248f8 100644 --- a/s/read.ss +++ b/s/read.ss @@ -1,12 +1,12 @@ ;;; read.ss ;;; Copyright 1984-2017 Cisco Systems, Inc. -;;; +;;; ;;; Licensed under the Apache License, Version 2.0 (the "License"); ;;; you may not use this file except in compliance with the License. ;;; You may obtain a copy of the License at -;;; +;;; ;;; http://www.apache.org/licenses/LICENSE-2.0 -;;; +;;; ;;; Unless required by applicable law or agreed to in writing, software ;;; distributed under the License is distributed on an "AS IS" BASIS, ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -932,13 +932,19 @@ (state-case c [eof (with-unread-char c (state-return atomic (xcall rd-make-number-or-symbol i)))] - [((#\0 - #\9) (#\a - #\z) #\- #\+ #\. #\/ #\@ #\# #\|) + [((#\0 - #\9) (#\a - #\z) #\- #\+ #\. #\/ #\@ #\|) (with-stretch-buffer i c (*state rd-token-number-or-symbol (fx+ i 1)))] [((#\A - #\Z)) (with-stretch-buffer i c (*state rd-token-number-or-symbol (fx+ i 1)))] - [(#\space #\( #\) #\[ #\] #\" #\; #\#) + [(#\#) + (if ($port-flags-set? (rcb-ip rcb) (constant port-flag-r6rs)) + (with-unread-char c + (state-return atomic (xcall rd-make-number-or-symbol i))) + (with-stretch-buffer i c + (*state rd-token-number-or-symbol (fx+ i 1))))] + [(#\space #\( #\) #\[ #\] #\" #\;) (with-unread-char c (state-return atomic (xcall rd-make-number-or-symbol i)))] [char-whitespace?