diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-06-15 01:05:31 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-06-15 01:05:31 +0200 |
commit | 527dbb981e87ca70d3f425b965b08d3b3420198a (patch) | |
tree | db8435256c90024b054eed6211e06fc1f8e9631b /module/vcomponent/duration.scm | |
parent | Repaired ability to set config value to #f. (diff) | |
download | calp-527dbb981e87ca70d3f425b965b08d3b3420198a.tar.gz calp-527dbb981e87ca70d3f425b965b08d3b3420198a.tar.xz |
Work on parser.
Diffstat (limited to 'module/vcomponent/duration.scm')
-rw-r--r-- | module/vcomponent/duration.scm | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/module/vcomponent/duration.scm b/module/vcomponent/duration.scm index 049c8821..42bb4ca4 100644 --- a/module/vcomponent/duration.scm +++ b/module/vcomponent/duration.scm @@ -27,8 +27,8 @@ (define-peg-pattern time-pattern body (and (ignore "T") - (and (capture (and number "H")) - (? (and (capture (and number "M")) + (and (? (capture (and number "H"))) + (? (and (? (capture (and number "M"))) (? (capture (and number "S")))))))) (define-peg-pattern dur-pattern body @@ -42,7 +42,7 @@ (define (parse-duration str) (let ((m (match-pattern dur-pattern str))) (unless m - (error "~a doesn't appar to be a duration" str)) + (throw 'parse-error "~a doesn't appar to be a duration" str)) (unless (= (peg:end m) (string-length str)) (warning "Garbage at end of duration")) @@ -63,13 +63,16 @@ [(S) `(second: ,n)] [else (error "Invalid key")]))] [#\T '()]) - (cadr (member "P" tree)))))) + (cdr (member "P" tree)))))) (apply duration (cons* sign: sign (let loop ((rem lst)) (if (null? rem) '() - (if (eqv? hour: (car rem)) + ;; NOTE a potentially prettier way would be + ;; to capture the T above, and use that as + ;; the delimiter for the time. + (if (memv (car rem) '(hour: minute: second:)) (list time: (apply time rem)) (cons* (car rem) (cadr rem) (loop (cddr rem))))))))))) |