Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Recognize #line <line-number> <filename> statements in your Guile code.
;; 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
;; #guile@irc.freenode.net 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