From 050f4157a7ece01dad8b8962e72cc89ee62182df Mon Sep 17 00:00:00 2001 From: Evan Hanson Date: Wed, 14 Mar 2018 17:53:00 +1300 Subject: [PATCH] Print #!-style symbols verbatim, without pipes These symbols are readable, so should be printed as-is by `##sys#print' just like #:keywords or the #!eof token. This has the side effect of making some lambda-infos look nicer in interpreted code, since the DSSSL indicators ("#!optional" et al.) will print verbatim rather than being enclosed by pipes, e.g. "(foo #!key x)" rather than "(foo |#!key| x)". Symbols that start with #% are no longer readable unquoted. Signed-off-by: Peter Bex --- NEWS | 3 +++ library.scm | 8 +++----- tests/syntax-tests.scm | 21 +++++++++++++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 9d254a5a..939769bd 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,9 @@ - Removed the deprecated C_locative_ref and C_mutate2 C functions. - The trace buffer no longer holds on to thread objects, allowing them to be garbage collected sooner (#1356, thanks to Kristian Lein-Mathisen) + - Symbols starting with #% are no longer treated specially and need + to be quoted with pipes. This makes the "%" sign available for + use in custom/user-defined sharp-sign read syntax. - Compiler - Fixed an off by one allocation problem in generated C code for (list ...). diff --git a/library.scm b/library.scm index e2be1e22..02f6b996 100644 --- a/library.scm +++ b/library.scm @@ -4294,8 +4294,6 @@ EOF (not (char=? c #\|))) (##sys#read-error port "empty keyword") (build-keyword str))))))) - ((#\%) - (build-symbol (##sys#string-append "#" (r-token))) ) ((#\+) (##sys#read-char-0 port) (let ((tst (readrec))) @@ -4560,9 +4558,9 @@ EOF (eq? c #\-) ) (not (##sys#string->number str)) ) ((eq? c #\:) (not (eq? ksp #:prefix))) - ((and (eq? c #\#) - (not (eq? #\% (##core#inline "C_subchar" str 1)))) - #f) + ((and (eq? c #\#) ;; #!rest, #!key etc + (not (eq? (##core#inline "C_subchar" str 1) #\!))) + #f) ((specialchar? c) #f) (else #t) ) ) (let ((c (##core#inline "C_subchar" str i))) diff --git a/tests/syntax-tests.scm b/tests/syntax-tests.scm index b119ee84..6bdfec45 100644 --- a/tests/syntax-tests.scm +++ b/tests/syntax-tests.scm @@ -1,7 +1,7 @@ ;;;; syntax-tests.scm - various macro tests (import-for-syntax chicken.pretty-print) -(import chicken.gc chicken.pretty-print) +(import chicken.gc chicken.pretty-print chicken.port) (define-syntax t (syntax-rules () @@ -264,10 +264,23 @@ ;; and not documented, but shouldn't be messed with by the expander (t "foo#bar" (symbol->string 'foo#bar)) -(t "#%void" (symbol->string '#%void)) - (t "foo#bar" (symbol->string (strip-syntax 'foo#bar))) -(t "#%void" (symbol->string (strip-syntax '#%void))) + +(t "#!rest" (symbol->string '#!rest)) +(t "#!rest" (symbol->string '|#!rest|)) +(t "#!rest" (symbol->string (strip-syntax '#!rest))) + +;; Read-write invariance of "special" symbols + +(t '#!rest (with-input-from-string "#!rest" read)) +(t '#!rest (with-input-from-string "|#!rest|" read)) +(t "#!rest" (with-output-to-string (lambda () (write '#!rest)))) +(t "foo#bar" (with-output-to-string (lambda () (write 'foo#bar)))) + +;; These used to be treated specially, but now they just trigger an +;; "invalid sharp-sign read syntax" error. +(t "|#%foo|" (with-output-to-string (lambda () (write '|#%foo|)))) +(f (with-input-from-string "#%foo" read)) ;;; alternative ellipsis test (SRFI-46) -- 2.11.0