Ticket #1711: prefix-colon.patch

File prefix-colon.patch, 3.1 KB (added by alicemaz, 4 years ago)
  • library.scm

    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 
    40314031                (cond ((or (eof-object? c)
    40324032                           (char-whitespace? c)
    40334033                           (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))))
    40434046                      ((memq c reserved-characters)
    40444047                       (reserved-character c))
    40454048                      (else
    EOF 
    40564059                            (loop (cons #\newline lst) pkw #f qtd))
    40574060                           ((#\:)
    40584061                            (cond ((and (null? lst)
     4062                                        (not pkw)
    40594063                                        (not qtd)
    40604064                                        (eq? ksp #:prefix))
    40614065                                   (loop '() #t #f qtd))
  • tests/library-tests.scm

    diff --git a/tests/library-tests.scm b/tests/library-tests.scm
    index dda075f7..d331871e 100644
    a b  
    496496  (assert (not (keyword? (with-input-from-string ":abc:" read))))
    497497  (assert (not (keyword? (with-input-from-string "abc:" read)))))
    498498
    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)))))
    503510
    504511;; The next two cases are a bit dubious, but we follow SRFI-88 (see
    505512;; also #1625).