Skip to content

Commit

Permalink
Treats # as a delimited in R6RS mode when reading numbers (fixes cisc…
Browse files Browse the repository at this point in the history
  • Loading branch information
mnieper committed Jan 24, 2025
1 parent beca0d1 commit 868daed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
21 changes: 13 additions & 8 deletions mats/6.ms
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)])
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions mats/root-experr-compile-0-f-f-f
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -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".
Expand Down Expand Up @@ -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".
Expand Down
16 changes: 11 additions & 5 deletions s/read.ss
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 868daed

Please sign in to comment.