]> git.donarmstrong.com Git - lilypond.git/blob - scm/pysk.scm
* Another grand 2003 update.
[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--2003 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 (my-map f l)
53   (if (null? l)
54       '()
55       (if (pair? (cdr l))
56           (cons (f (car l)) (my-map f (cdr l)))
57           (cons (f (car l)) (f (cdr l)))
58           )
59   ))
60
61 (define (tuplify-list lst)
62   (if (null? lst)
63       '()
64       (if (pair? (cdr lst))
65           (cons (car lst) (tuplify-list (cdr lst)))
66           (if (eq? '() (cdr lst))
67               lst
68               (list (string-append "(" (car lst) ", " (cdr lst) ")" ))
69               ))
70           ))
71
72 (define (py-listify q)
73   (string-append
74    "["
75    (string-join
76     (tuplify-list (my-map pythonify q))   ",")
77    "]\n"
78    ))
79
80