1
0
forked from alex-eg/sex

space toplevel forms the way the source does

Every toplevel form was followed by a blank line whether or not one
was written, so the prelude's run of typedefs arrived at twice the
height. A function had no location of its own to measure from either,
having lost it where its header and body are stitched together.
This commit is contained in:
2026-10-05 02:08:15 +03:00
parent 7f3f22e853
commit 95f39e4b44
8 changed files with 72 additions and 25 deletions

View File

@@ -93,9 +93,12 @@
;;; read-with-source-info / get-line-number, which only works when forms
;;; are produced by the built-in `read'.
;;;
;;; A location is (file . line). The file matters because imported
;;; A location is (file line end-line): where the form starts and the
;;; line its closing delimiter is on. The file matters because imported
;;; modules paste their public forms into the current unit: those forms
;;; originate in another file and must be reported as such
;;; originate in another file and must be reported as such. The end line
;;; tells the C writer whether two toplevel forms were written with a
;;; blank line between them
(define +form-sources+ (make-hash-table eq?))
;;; The file `parse-all' is currently reading. Bound by the reader
@@ -114,8 +117,8 @@
(define (form-type form)
(hash-table-ref/default +form-types+ form #f))
(define (set-form-source! form file line)
(hash-table-set! +form-sources+ form (cons file line)))
(define (set-form-source! form file line #!optional (end-line line))
(hash-table-set! +form-sources+ form (list file line end-line)))
(define (form-source form)
(hash-table-ref/default +form-sources+ form #f))
@@ -126,7 +129,11 @@
(define (form-line form)
(let ((src (form-source form)))
(and src (cdr src))))
(and src (cadr src))))
(define (form-end-line form)
(let ((src (form-source form)))
(and src (caddr src))))
(define (copy-form-source! from to)
"Give TO the location of FROM, if FROM has one. Returns TO, so it can
@@ -144,7 +151,7 @@ wrap a form-building expression."
"\"file:line: \" for FORM, or \"\" when it has none"
(let ((src (form-source form)))
(if src
(string-append (car src) ":" (number->string (cdr src)) ": ")
(string-append (car src) ":" (number->string (cadr src)) ": ")
"")))
(define (sex-error form message . args)