Tom Willemse
c454bde37c
Write a small DSL for converting a simple lisp expression to an MPD query format. This turns, for example: (and (= artist "Katatonia") (= album "Last Fair Deal Gone Down")) Into: ((artist == "Katatonia") AND (album == "Last Fair Deal Gone Down")) The expressions inside ‘query’ are quasi-quoted, so that variable substitution is possible.
22 lines
629 B
Scheme
22 lines
629 B
Scheme
(define-structure mpd (export query)
|
|
(open scheme-with-scsh)
|
|
(begin
|
|
(define-syntax query
|
|
(syntax-rules ()
|
|
((_ a)
|
|
(mpd-query-1 `a))))
|
|
|
|
(define (mpd-query-equals params)
|
|
(apply format #f "~s == ~s" params))
|
|
|
|
(define (mpd-query-and params)
|
|
(format #f "~a AND ~a"
|
|
(mpd-query-1 (car params))
|
|
(mpd-query-1 (cadr params))))
|
|
|
|
(define (mpd-query-1 query)
|
|
(format #f "(~a)"
|
|
(let ((op (car query)))
|
|
(case op
|
|
('= (mpd-query-equals (cdr query)))
|
|
('and (mpd-query-and (cdr query)))))))))
|