From f0ffd3f6305f61ab47cdae342e749c44d1f9b78f Mon Sep 17 00:00:00 2001 From: tux Date: Sun, 24 Nov 2024 15:23:32 +0100 Subject: [PATCH] use yml data structures with python parser --- all_base_includes.ly | 8 +++++--- json_parser.scm => scm/json_parser.scm | 0 resolve_inherits.ly => scm/resolve_inherits.scm | 4 ++-- scm/yaml_parser.scm | 10 ++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) rename json_parser.scm => scm/json_parser.scm (100%) rename resolve_inherits.ly => scm/resolve_inherits.scm (90%) create mode 100644 scm/yaml_parser.scm diff --git a/all_base_includes.ly b/all_base_includes.ly index f5fcb3d..408a272 100644 --- a/all_base_includes.ly +++ b/all_base_includes.ly @@ -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" diff --git a/json_parser.scm b/scm/json_parser.scm similarity index 100% rename from json_parser.scm rename to scm/json_parser.scm diff --git a/resolve_inherits.ly b/scm/resolve_inherits.scm similarity index 90% rename from resolve_inherits.ly rename to scm/resolve_inherits.scm index abd2823..ee84968 100644 --- a/resolve_inherits.ly +++ b/scm/resolve_inherits.scm @@ -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) ) \ No newline at end of file diff --git a/scm/yaml_parser.scm b/scm/yaml_parser.scm new file mode 100644 index 0000000..f3b5086 --- /dev/null +++ b/scm/yaml_parser.scm @@ -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))) \ No newline at end of file