use yml data structures with python parser

This commit is contained in:
tux 2024-11-24 15:23:32 +01:00
parent 8dfbc5ef25
commit f0ffd3f630
4 changed files with 17 additions and 5 deletions

View File

@ -1,8 +1,10 @@
#(define noStandaloneOutput (if (defined? 'noStandaloneOutput) noStandaloneOutput #f))
#(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"
#(if (defined? 'LAYOUT) #f
(let ((scmdir (string-append (dirname (current-filename)) file-name-separator-string "scm" file-name-separator-string)))
(load (string-append scmdir "json_parser.scm"))
(load (string-append scmdir "resolve_inherits.scm"))
(load (string-append scmdir "yaml_parser.scm"))))
\include "basic_format_and_style_settings.ly"
\include "eps_file_from_song_dir.ly"
\include "title_with_category_images.ly"

View File

@ -1,4 +1,4 @@
#(define (resolve-inherit-entry-in-list alist entry)
(define (resolve-inherit-entry-in-list alist entry)
(let* ((key (car entry))
(attributes (cdr entry))
(inherits (assoc-ref attributes "inherits")))
@ -17,6 +17,6 @@
entry
)))
#(define (resolve-inherits alist)
(define (resolve-inherits alist)
(map (lambda (entry) (resolve-inherit-entry-in-list alist entry)) alist)
)

10
scm/yaml_parser.scm Normal file
View File

@ -0,0 +1,10 @@
(use-modules (ice-9 popen) (ice-9 textual-ports) (json parser))
(define (yml-file->scm filename)
(let* ((python_cmd (string-append "import sys, yaml, json; print(json.dumps(yaml.safe_load(open('" filename "'))))"))
(pipe (open-pipe* OPEN_READ "python" "-c" python_cmd))
(json (get-string-all pipe)))
(close-pipe pipe)
(json-string->scm json)))
(define (parse-yml-file filename) (resolve-inherits (yml-file->scm filename)))