aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent/duration.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-06-15 01:05:31 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-06-15 01:05:31 +0200
commit527dbb981e87ca70d3f425b965b08d3b3420198a (patch)
treedb8435256c90024b054eed6211e06fc1f8e9631b /module/vcomponent/duration.scm
parentRepaired ability to set config value to #f. (diff)
downloadcalp-527dbb981e87ca70d3f425b965b08d3b3420198a.tar.gz
calp-527dbb981e87ca70d3f425b965b08d3b3420198a.tar.xz
Work on parser.
Diffstat (limited to 'module/vcomponent/duration.scm')
-rw-r--r--module/vcomponent/duration.scm13
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)))))))))))