]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/parser-ly-from-scheme.scm
Build: Better error handling from build scripts.
[lilypond.git] / scm / parser-ly-from-scheme.scm
index a2bc74c27a0337366b7fad070fc6cafa67efb231..19e6559448e23c95d5648b79c8127ddd87ba9d89 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; This file is part of LilyPond, the GNU music typesetter.
 ;;;;
-;;;; Copyright (C) 2004--2011  Nicolas Sceaux  <nicolas.sceaux@free.fr>
+;;;; Copyright (C) 2004--2012  Nicolas Sceaux  <nicolas.sceaux@free.fr>
 ;;;;           Jan Nieuwenhuizen <janneke@gnu.org>
 ;;;;
 ;;;; LilyPond is free software: you can redistribute it and/or modify
@@ -33,6 +33,7 @@ from @var{port} and return the corresponding Scheme music expression.
                                             (write-char x out)
                                             x)) #f)
                                 "r")))
+                          (set-port-filename! copycat filename)
                           (do ((c (read-char port) (read-char port)))
                               ((and (char=? c #\#)
                                     (char=? (peek-char port) #\}))
@@ -42,7 +43,13 @@ from @var{port} and return the corresponding Scheme music expression.
                             ;; a #scheme or $scheme expression
                             (if (or (char=? c #\#) (char=? c #\$))
                                 (let* ((p (ftell out))
-                                       (expr (read copycat)))
+                                       (expr
+                                        (begin
+                                          (set-port-line! copycat
+                                                          (port-line port))
+                                          (set-port-column! copycat
+                                                            (port-column port))
+                                          (read copycat))))
                                   ;; kill unused lookahead, it has been
                                   ;; written out already
                                   (drain-input copycat)
@@ -56,13 +63,13 @@ from @var{port} and return the corresponding Scheme music expression.
                                       (set! closures
                                             (cons `(cons ,p (lambda () ,expr))
                                                   closures)))))))))))
-    `(let* ((clone
-            (ly:parser-clone parser (list ,@closures)))
-           (result (ly:parse-string-expression clone ,lily-string
-                                               ,filename
-                                               ,line)))
-       (if (ly:parser-has-error? clone)
-          (ly:parser-error parser (_ "error in #{ ... #}")))
-       result)))
+    (define (embedded-lilypond parser lily-string filename line closures)
+      (let* ((clone (ly:parser-clone parser closures))
+            (result (ly:parse-string-expression clone lily-string
+                                                filename line)))
+       (if (ly:parser-has-error? clone)
+           (ly:parser-error parser (_ "error in #{ ... #}")))
+       result))
+    (list embedded-lilypond 'parser lily-string filename line (cons 'list (reverse! closures)))))
 
 (read-hash-extend #\{ read-lily-expression)