allow inherits in json file

This commit is contained in:
tux 2024-11-02 19:58:15 +01:00
parent e9b904c32c
commit 88f0dc9f8f
2 changed files with 23 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#(if (defined? 'LAYOUT) #f (load (string-append (dirname (current-filename)) file-name-separator-string "json_parser.scm")))
#(use-modules (json parser))
\include "resolve_inherits.ly"
\include "basic_format_and_style_settings.ly"
\include "eps_file_from_song_dir.ly"
\include "title_with_category_images.ly"

22
resolve_inherits.ly Normal file
View File

@ -0,0 +1,22 @@
#(define (resolve-inherit-entry-in-list alist entry)
(let* ((key (car entry))
(attributes (cdr entry))
(inherits (assoc-ref attributes "inherits")))
(if inherits
(let* ((alist-without-entry (alist-delete key alist))
(inherit-entry (assoc inherits alist-without-entry))
(inherits-attributes (if inherit-entry (alist-copy (cdr (resolve-inherit-entry-in-list alist-without-entry inherit-entry)))))
(override-attributes (alist-delete "inherits" attributes)))
(if inherit-entry
(begin
(for-each (lambda (attribute) (assoc-set! inherits-attributes (car attribute) (cdr attribute))) override-attributes)
(cons key inherits-attributes)
)
(ly:error "~a can not inherit from ~a" key inherits))
)
entry
)))
#(define (resolve-inherits alist)
(map (lambda (entry) (resolve-inherit-entry-in-list alist entry)) alist)
)