Preliminary start/stop handling.
This commit is contained in:
parent
e5045f893d
commit
6d5dcb6ca8
1 changed files with 28 additions and 9 deletions
|
@ -260,29 +260,48 @@
|
||||||
;; Parses given key-value line. Key is up to first space, value is the
|
;; Parses given key-value line. Key is up to first space, value is the
|
||||||
;; rest of the line. If the line doesn't contain anything, returns #f.
|
;; rest of the line. If the line doesn't contain anything, returns #f.
|
||||||
(define (parse-member-line l)
|
(define (parse-member-line l)
|
||||||
;;(print 'pm)
|
|
||||||
;;(print l)
|
|
||||||
(let ((sp (string-split l " ")))
|
(let ((sp (string-split l " ")))
|
||||||
(and sp
|
(and sp
|
||||||
(not (null? sp))
|
(not (null? sp))
|
||||||
(list (string->symbol (car sp))
|
(list (string->symbol (car sp))
|
||||||
(string-intersperse (cdr sp))))))
|
(string-intersperse (cdr sp))))))
|
||||||
|
|
||||||
;; TODO: student and suspend special handling - should create list of
|
;; If given symbol represents start/stop symbol of either kind,
|
||||||
;; (start date) (stop date) which will be later sorted by date and
|
;; returns a list of the symbol representing the type and start/stop
|
||||||
;; computation performed
|
;; symbol. It returns false otherwise.
|
||||||
|
(define (split-start/stop-symbol s)
|
||||||
|
(cond ((eq? s 'studentstart) '(student start))
|
||||||
|
((eq? s 'studentstop) '(student stop))
|
||||||
|
((eq? s 'suspendstart) '(suspend start))
|
||||||
|
((eq? s 'suspendstop) '(suspend stop))
|
||||||
|
(else #f)))
|
||||||
|
|
||||||
|
;; Processes member line adding given value v to the dictionary d
|
||||||
|
;; under key k. Special handling for start/stop symbols means given
|
||||||
|
;; value is prepended to given start/stop key (student/suspend) as
|
||||||
|
;; parsed month for later processing of student/suspend periods.
|
||||||
|
(define (process-member-line d k v)
|
||||||
|
(let ((ss (split-start/stop-symbol k)))
|
||||||
|
(cond (ss
|
||||||
|
(let ((pk (car ss))
|
||||||
|
(pd (cadr ss)))
|
||||||
|
(dict-set d pk
|
||||||
|
(cons (cons pd (string->month v))
|
||||||
|
(dict-ref d pk '())))))
|
||||||
|
(else
|
||||||
|
(dict-set d k v)))))
|
||||||
|
|
||||||
|
;; Processes all lines and returns a dictionary representing given
|
||||||
|
;; member.
|
||||||
(define (parse-member-lines ls)
|
(define (parse-member-lines ls)
|
||||||
(let loop ((ls ls)
|
(let loop ((ls ls)
|
||||||
(r (make-dict)))
|
(r (make-dict)))
|
||||||
;;(print '---)
|
|
||||||
;;(print r)
|
|
||||||
(if (null? ls)
|
(if (null? ls)
|
||||||
r
|
r
|
||||||
(let ((p (parse-member-line (car ls))))
|
(let ((p (parse-member-line (car ls))))
|
||||||
;;(print p)
|
|
||||||
(loop (cdr ls)
|
(loop (cdr ls)
|
||||||
(if p
|
(if p
|
||||||
(apply dict-set r p)
|
(apply process-member-line r p)
|
||||||
r))))))
|
r))))))
|
||||||
|
|
||||||
;; Loads lines from given file in (*members-directory*) and parses
|
;; Loads lines from given file in (*members-directory*) and parses
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue