From 1f8c91a926c9552beebf1d1cb2b7a84ba2d8d38f Mon Sep 17 00:00:00 2001
From: alice maz <alice@alicemaz.com>
Date: Wed, 5 Aug 2020 00:07:23 -0500
Subject: [PATCH] Always treat bare colon as a symbol
Fixes ##sys#read behavior in -keyword-style prefix to match suffix
Also fixes it to consume at most one colon in -keyword-style prefix
---
library.scm | 22 +++++++++++++---------
tests/library-tests.scm | 15 +++++++++++----
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/library.scm b/library.scm
index c5015b7a..ab3b6397 100644
a
|
b
|
EOF |
4031 | 4031 | (cond ((or (eof-object? c) |
4032 | 4032 | (char-whitespace? c) |
4033 | 4033 | (memq c terminating-characters)) |
4034 | | ;; The not null? checks here ensure we read a |
4035 | | ;; plain ":" as a symbol, not as a keyword. |
4036 | | ;; However, when the keyword is quoted like ||:, |
4037 | | ;; it _should_ be read as a keyword. |
4038 | | (if (and skw (eq? ksp #:suffix) |
4039 | | (or qtd (not (null? (cdr lst))))) |
4040 | | (k (##sys#reverse-list->string (cdr lst)) #t) |
4041 | | (k (##sys#reverse-list->string lst) |
4042 | | (and pkw (or qtd (not (null? lst))))))) |
| 4034 | ;; The various cases here cover: |
| 4035 | ;; - Nonempty keywords formed with colon in the ksp position |
| 4036 | ;; - Empty keywords formed explicitly with vbar quotes |
| 4037 | ;; - Bare colon, which should always be a symbol |
| 4038 | (cond ((and skw (eq? ksp #:suffix) (or qtd (not (null? (cdr lst))))) |
| 4039 | (k (##sys#reverse-list->string (cdr lst)) #t)) |
| 4040 | ((and pkw (eq? ksp #:prefix) (or qtd (not (null? lst)))) |
| 4041 | (k (##sys#reverse-list->string lst) #t)) |
| 4042 | ((and pkw (eq? ksp #:prefix) (not qtd) (null? lst)) |
| 4043 | (k ":" #f)) |
| 4044 | (else |
| 4045 | (k (##sys#reverse-list->string lst) #f)))) |
4043 | 4046 | ((memq c reserved-characters) |
4044 | 4047 | (reserved-character c)) |
4045 | 4048 | (else |
… |
… |
EOF |
4056 | 4059 | (loop (cons #\newline lst) pkw #f qtd)) |
4057 | 4060 | ((#\:) |
4058 | 4061 | (cond ((and (null? lst) |
| 4062 | (not pkw) |
4059 | 4063 | (not qtd) |
4060 | 4064 | (eq? ksp #:prefix)) |
4061 | 4065 | (loop '() #t #f qtd)) |
diff --git a/tests/library-tests.scm b/tests/library-tests.scm
index dda075f7..d331871e 100644
a
|
b
|
|
496 | 496 | (assert (not (keyword? (with-input-from-string ":abc:" read)))) |
497 | 497 | (assert (not (keyword? (with-input-from-string "abc:" read))))) |
498 | 498 | |
499 | | (let ((colon-sym (with-input-from-string ":" read))) |
500 | | (assert (symbol? colon-sym)) |
501 | | (assert (not (keyword? colon-sym))) |
502 | | (assert (string=? ":" (symbol->string colon-sym)))) |
| 499 | (parameterize ((keyword-style #:suffix)) |
| 500 | (let ((colon-sym (with-input-from-string ":" read))) |
| 501 | (assert (symbol? colon-sym)) |
| 502 | (assert (not (keyword? colon-sym))) |
| 503 | (assert (string=? ":" (symbol->string colon-sym))))) |
| 504 | |
| 505 | (parameterize ((keyword-style #:prefix)) |
| 506 | (let ((colon-sym (with-input-from-string ":" read))) |
| 507 | (assert (symbol? colon-sym)) |
| 508 | (assert (not (keyword? colon-sym))) |
| 509 | (assert (string=? ":" (symbol->string colon-sym))))) |
503 | 510 | |
504 | 511 | ;; The next two cases are a bit dubious, but we follow SRFI-88 (see |
505 | 512 | ;; also #1625). |