done
task
#!/usr/bin/env guile
!#
(use-modules (ice-9 regex) (ice-9 rdelim))
;;; Macro to loop over lines of current input port,
;;; matching against a series of regular expressions.
;;; Tries to be efficient by compiling all the REs outside the loop.
(define-syntax awkish
(lambda (stx)
(syntax-case stx (else)
((_ var (pat body ...) ... (else else-body ...))
(with-syntax (((re ...)
(datum->syntax #f (generate-temporaries #'(pat ...)))))
#'(let ((re (make-regexp pat)) ...)
(do ((var (read-line) (read-line)))
((eof-object? var))
(cond
((regexp-exec re var) body ...) ...
(else else-body ...)))))))))
;;; output utilities
(define colors '((red . 31) (green . 32) (yellow . 33) (blue . 34)
(magenta . 35) (cyan . 36)))
(define (colored col str)
(format #t "\x1B[Am
A\x1B[0m\n" (cdr (assq col colors)) str))
;;; the real work happens here
(awkish line
("compiling|compiled" (colored 'blue line))
("WARNING" (colored 'yellow line))
("(Entering|Leaving) test group" (colored 'cyan line))
("PASS" (colored 'green line))
("# of expected passes" (colored 'cyan line))
("FAIL" (colored 'red line))
(else (write-line line)))
Note use of symbolic color names to make it more obvious what color each matching line should be.