lilypond-common-includes/scm/yaml_parser.scm
2024-12-31 16:13:21 +01:00

12 lines
688 B
Scheme

(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 "'))))"))
; WTF? On Windows there is "py" and we need to specify the encoding, on linux there is "python3" or "python"
; but "python3" seems to work better. Be sure you have PyYAML installed.
(pipe (open-pipe* OPEN_READ (if windows? "py" "python3") "-X" "utf8" "-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)))