From 88f0dc9f8fee1cd3f7152cd7e56798bb97699ee0 Mon Sep 17 00:00:00 2001 From: tux Date: Sat, 2 Nov 2024 19:58:15 +0100 Subject: [PATCH] allow inherits in json file --- all_base_includes.ly | 1 + resolve_inherits.ly | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 resolve_inherits.ly diff --git a/all_base_includes.ly b/all_base_includes.ly index 77c9f7b..f5fcb3d 100644 --- a/all_base_includes.ly +++ b/all_base_includes.ly @@ -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" diff --git a/resolve_inherits.ly b/resolve_inherits.ly new file mode 100644 index 0000000..abd2823 --- /dev/null +++ b/resolve_inherits.ly @@ -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) +) \ No newline at end of file