Last active
October 3, 2015 08:17
-
-
Save shanecelis/2424214 to your computer and use it in GitHub Desktop.
Recognize #line <line-number> <filename> statements in your Guile code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; line-pragma.scm | |
;; | |
;; This code extends the reader to recognize #l and is meant to | |
;; be used the same way as the #line pragma in C. This way you can | |
;; sprinkle your code with lines like this: | |
;; | |
;; (define (f x) | |
;; #line 314 "increment-literately.w" | |
;; (+ x 1)) | |
;; | |
;; I wrote it to do literate programming with Guile using nuweb. | |
;; | |
;; Many thanks to dsmith-work, civodul, and others in | |
;; #[email protected] for their help. | |
;; | |
;; Shane Celis | |
(eval-when (compile load eval) | |
(read-hash-extend #\l | |
(lambda (char port) | |
(let* ((ine (read port)) | |
(lineno (read port)) | |
(filename (read port))) | |
(if (not (eq? ine 'ine)) | |
(error (format #f "Expected '#line <line-number> <filename>'; got '#~a~a ~a \"~a\"'." char ine lineno filename))) | |
(set-port-filename! port filename) | |
(set-port-line! port lineno) | |
(set-port-column! port 0) | |
"")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment