(use (only srfi-14 char-set:digit) comparse) (define digit (in char-set:digit)) (define (as-number parser) (bind (as-string parser) (lambda (s) (result (string->number s))))) (define digits (as-number (one-or-more digit))) (define timestamp-hours (followed-by digits (is #\h))) (define timestamp-minutes (followed-by digits (is #\m))) (define timestamp-seconds (followed-by digits (is #\s))) (define (maybe* parser) (any-of parser item)) (define timestamp (sequence* ((hours (maybe timestamp-hours)) (minutes (maybe timestamp-minutes)) (seconds timestamp-seconds)) (result (list (or hours 0) (or minutes 0) seconds)))) ;; expected: (0 0 1) ;; actual: (0 0 1) (parse timestamp "1s") ;; expected: (0 1 2) ;; actual: #f (parse timestamp "1m2s") ;; expected: (1 2 3) ;; actual: #f (parse timestamp "1h2m3s")