]> git.donarmstrong.com Git - lilypond.git/blob - scm/pysk.scm
release: 1.5.23
[lilypond.git] / scm / pysk.scm
1 ;;; pysk.scm -- implement Python  output routines (for Sketch)
2 ;;;
3 ;;;  source file of the GNU LilyPond music typesetter
4 ;;; 
5 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9
10 (define-module (scm pysk)
11   )
12
13 (use-modules (scm ps)
14              (ice-9 regex)
15              (ice-9 string-fun)
16              (guile)
17              )
18
19 (define this-module (current-module))
20 (define-public (pysk-output-expression expr port)
21   (display (pythonify expr) port )
22   )
23
24 (define (ly-warn s) (display s))
25
26 (define (pythonify q)
27   (cond
28    ((string? q) (py-str q))
29    ((symbol? q) (py-str (symbol->string q)))
30    ((and (pair?  q)
31          (not (pair? (cdr q)))
32          (not (eq? '() (cdr q)))
33          ) (py-tuple q))
34    ((pair? q) (py-listify q))
35    ((number? q) (number->string q))
36    ((eq? q '()) '())
37    (else (begin
38            (ly-warn "Unknown object to pythonify:")
39            (write q)
40            (newline)
41            )
42   )))
43
44 (define (py-str s)
45   (string-append "'" s "'")
46   )
47
48 (define (py-tuple q)
49   (string-append "(" (pythonify (car  q)) "," (pythonify (cdr q)) ")")
50   )
51
52 (define (reduce-list list between)
53   "Create new list, inserting BETWEEN between elements of LIST"
54   (if (null? list)
55       '()
56       (if (null? (cdr list))
57           list
58           (cons (car list)
59                 (cons between (reduce-list (cdr list) between)))
60   
61   )))
62
63 (define (string-join str-list sep)
64   (apply string-append (reduce-list str-list sep))
65   )
66
67 (define (my-map f l)
68   (if (null? l)
69       '()
70       (if (pair? (cdr l))
71           (cons (f (car l)) (my-map f (cdr l)))
72           (cons (f (car l)) (f (cdr l)))
73           )
74   ))
75
76 (define (tuplify-list lst)
77   (if (null? lst)
78       '()
79       (if (pair? (cdr lst))
80           (cons (car lst) (tuplify-list (cdr lst)))
81           (if (eq? '() (cdr lst))
82               lst
83               (list (string-append "(" (car lst) ", " (cdr lst) ")" ))
84               ))
85           ))
86
87 (define (py-listify q)
88   (string-append
89    "["
90    (string-join
91     (tuplify-list (my-map pythonify q))   ",")
92    "]\n"
93    ))
94
95