mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-20 10:40:19 +02:00
Fix bug for read-syntax on ( . args)
* module/ice-9/boot-9.scm: Capture syntax?. * module/ice-9/read.scm (read-syntax): Avoid re-annotating objects. * test-suite/tests/reader.test ("read-syntax"): Add test.
This commit is contained in:
parent
3bce507407
commit
3383a2cb10
3 changed files with 25 additions and 7 deletions
|
@ -4656,8 +4656,11 @@ R7RS."
|
|||
;;;
|
||||
|
||||
(call-with-values (lambda ()
|
||||
(include-from-path "ice-9/read.scm")
|
||||
(values read read-syntax))
|
||||
;; Capture syntax? binding, later removed from root
|
||||
;; module.
|
||||
(let ((syntax? syntax?))
|
||||
(include-from-path "ice-9/read.scm")
|
||||
(values read read-syntax)))
|
||||
(lambda (read* read-syntax*)
|
||||
(set! read read*)
|
||||
(set! read-syntax read-syntax*)))
|
||||
|
|
|
@ -877,7 +877,17 @@
|
|||
(define* (read-syntax #:optional (port (current-input-port)))
|
||||
(define filename (port-filename port))
|
||||
(define (annotate line column datum)
|
||||
(datum->syntax #f ; No lexical context.
|
||||
datum
|
||||
#:source (vector filename line (1- column))))
|
||||
;; Usually when reading compound expressions consisting of multiple
|
||||
;; syntax objects, like lists, the "leaves" of the expression are
|
||||
;; annotated but the "root" isn't. Like in (A . B), A and B will be
|
||||
;; annotated but the pair won't. Therefore the usually correct
|
||||
;; thing to do is to just annotate the result. However in the case
|
||||
;; of reading ( . C), the result is the already annotated C, which
|
||||
;; we don't want to re-annotate. Therefore we avoid re-annotating
|
||||
;; already annotated objects.
|
||||
(if (syntax? datum)
|
||||
datum
|
||||
(datum->syntax #f ; No lexical context.
|
||||
datum
|
||||
#:source (vector filename line (1- column)))))
|
||||
(%read port annotate syntax->datum))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue