diff --git a/brmsaptool.scm b/brmsaptool.scm index dc0e5b7..1b10341 100644 --- a/brmsaptool.scm +++ b/brmsaptool.scm @@ -260,29 +260,48 @@ ;; 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. (define (parse-member-line l) - ;;(print 'pm) - ;;(print l) (let ((sp (string-split l " "))) (and sp (not (null? sp)) (list (string->symbol (car sp)) (string-intersperse (cdr sp)))))) + +;; If given symbol represents start/stop symbol of either kind, +;; returns a list of the symbol representing the type and start/stop +;; 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))))) -;; TODO: student and suspend special handling - should create list of -;; (start date) (stop date) which will be later sorted by date and -;; computation performed +;; Processes all lines and returns a dictionary representing given +;; member. (define (parse-member-lines ls) (let loop ((ls ls) (r (make-dict))) - ;;(print '---) - ;;(print r) (if (null? ls) r (let ((p (parse-member-line (car ls)))) - ;;(print p) (loop (cdr ls) (if p - (apply dict-set r p) + (apply process-member-line r p) r)))))) ;; Loads lines from given file in (*members-directory*) and parses