]> git.donarmstrong.com Git - lilypond.git/commitdiff
Provide check-context-path function
authorDavid Kastrup <dak@gnu.org>
Sun, 12 Jul 2015 18:44:39 +0000 (20:44 +0200)
committerDavid Kastrup <dak@gnu.org>
Sat, 18 Jul 2015 04:42:13 +0000 (06:42 +0200)
scm/music-functions.scm

index b75709bf0c733c56ba283d3a016694cf5cddde3a..97bb8c4f67f89aa0ce79482595f8d0f86d978f44 100644 (file)
@@ -481,6 +481,30 @@ respectively."
              location)
             #f)))))
 
+(define-safe-public (check-context-path path #:optional location)
+  "Check a context property path specification @var{path}, a symbol
+list (or a single symbol), for validity and possibly complete it.
+Returns the completed specification, or @code{#f} when rising an
+error (using optionally @code{location})."
+  (let* ((path (if (symbol? path) (list path) path)))
+    ;; A Guile 1.x bug specific to optargs precludes moving the
+    ;; defines out of the let
+    (define (property? s)
+      (object-property s 'translation-type?))
+    (define (unspecial? s)
+      (not (property? s)))
+    (define (check c p) (c p))
+    (or (case (length path)
+          ((1) (and (property? (car path)) (cons 'Bottom path)))
+          ((2) (and (unspecial? (car path)) (property? (cadr path)) path))
+          (else #f))
+        (begin
+          (ly:parser-error
+           (format #f (_ "bad context property ~a")
+                   path)
+           location)
+          #f))))
+
 (define-public (make-grob-property-set grob gprop val)
   "Make a @code{Music} expression that sets @var{gprop} to @var{val} in
 @var{grob}.  Does a pop first, i.e., this is not an override."