Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Last active October 3, 2015 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanecelis/2424214 to your computer and use it in GitHub Desktop.
Save shanecelis/2424214 to your computer and use it in GitHub Desktop.
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