~ chicken-core (master) 3c59641cf226a7ba8674b8a33654143b8f6ee847
commit 3c59641cf226a7ba8674b8a33654143b8f6ee847
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Thu Dec 4 22:55:22 2025 +0100
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Thu Dec 4 22:55:22 2025 +0100
add optional arg for filename to read-with-source-info
diff --git a/expand.scm b/expand.scm
index df58bf03..32a415dd 100644
--- a/expand.scm
+++ b/expand.scm
@@ -768,12 +768,13 @@
(define-constant line-number-database-size 997) ; Copied from core.scm
-(define (read-with-source-info #!optional (in ##sys#standard-input))
+(define (read-with-source-info #!optional (in ##sys#standard-input) fname)
;; Initialize line number db on first use
(unless ##sys#line-number-database
(set! ##sys#line-number-database (make-vector line-number-database-size '())))
(##sys#check-input-port in #t 'read-with-source-info)
- (##sys#read in read-with-source-info-hook) )
+ (fluid-let ((##sys#current-source-filename (or fname ##sys#current-source-filename)))
+ (##sys#read in read-with-source-info-hook) ) )
(define (get-line-number sexp)
diff --git a/manual/Module (chicken syntax) b/manual/Module (chicken syntax)
index 03ed6b5b..36f306a8 100644
--- a/manual/Module (chicken syntax)
+++ b/manual/Module (chicken syntax)
@@ -366,7 +366,7 @@ renamed.
==== read-with-source-info
-<procedure>(read-with-source-info [port])</procedure>
+<procedure>(read-with-source-info [port filename])</procedure>
Exactly like {{read}} from the {{scheme}} module, except it
registers the expression it read into the line number database, so
@@ -375,7 +375,10 @@ that if {{(read-with-source-info)}} returns {{OBJ}},
The port argument may be omitted, in which case it defaults to the
value returned by {{current-input-port}}. It is an error to read from
-a closed port.
+a closed port. If {{filename}} is given, it designates the name
+of the file associated. In case this argument is not given, the
+currently opened source file is used. If no current source file
+is opened, then the name defaults to "<stdin>".
==== get-line-number
Trap