scsh-make/common-rules.scm

51 lines
1.5 KiB
Scheme

(define-record-type :common-rules
(make-common-rules ls)
is-common-rules?
(ls common-rules-ls))
(define (make-empty-common-rules)
(make-common-rules (list match-all-func)))
(define (error-if-nonexistant target)
(error "file (assumed leaf) doesn't exist:" target))
(define (match-all-func will-be-target)
(make-rule-cand will-be-target
(list)
(lambda args
(let ((target (car args))
(init-state (last args)))
(cons (file-not-exists? will-be-target) init-state)))
(lambda args
(let ((target (car args))
(cooked-state (last args)))
(error-if-nonexistant target)))))
(define (add-common-rules common-rules func)
(make-common-rules (cons func (common-rules-ls common-rules))))
(define (search-match-in-common-rules common-rules target)
(let ((common-rs (common-rules-ls common-rules)))
(if (null? common-rs)
#f
(let next-common-rule ((current (car common-rs))
(todo (cdr common-rs)))
(let ((maybe-target (current target)))
(if maybe-target
maybe-target
(if (null? todo)
#f
(next-common-rule (car todo) (cdr todo)))))))))
(define (common-rcs->common-rules common-rcs)
(let ((empty-rules (make-empty-common-rules)))
(if (null? common-rcs)
empty-rules
(let for-each-rc ((rc (car common-rcs))
(todo (cdr common-rcs))
(done empty-rules))
(let ((current (add-common-rules done rc)))
(if (null? todo)
current
(for-each-rc (car todo) (cdr todo) current)))))))