Coverage report: /home/ellis/comp/core/lib/organ/object/stat-cookie.lisp

KindCoveredAll%
expression035 0.0
branch02 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; Code:
2
 (in-package :organ)
3
 
4
 ;; the logic will be a bit weird here - we store 2 numbers (completed
5
 ;; vs remaining) but sometimes need to parse a percentage without
6
 ;; actually knowing the counts of completed vs remaining. To get
7
 ;; around this, we'll allow a float to be stored in the N1 slot, which
8
 ;; indicated that we parsed a percentage without knowing our counts.
9
 (define-org-object stat-cookie ((n1 0 :type number) (n2 0 :type fixnum)))
10
 
11
 (defmacro matches (name)
12
   `(make-matcher ,name))
13
 
14
 (define-matcher stat-cookie-percent (is #\%))
15
 
16
 (define-matcher stat-cookie-ratio (is #\/))
17
 
18
 (define-matcher int (in #\0 #\9))
19
 
20
 (define-matcher stat-cookie-start 
21
     (and (is #\[)
22
          (next (matches (or :int
23
                             :stat-cookie-ratio
24
                             :stat-cookie-percent)))))
25
 
26
 (define-matcher stat-cookie-end (is #\]))
27
 
28
 ;; this feels slow
29
 (define-org-parser (stat-cookie :from string)
30
   ;; either X/Y or X%
31
   (with-lexer-environment (input)
32
     (when (char= #\[ (consume))
33
       (let ((res (org-create :stat-cookie)))
34
         (setf (org-stat-cookie-n1 res)
35
               (parse-number
36
                (consume-until (matches (not :int)))))
37
         (case (consume)
38
           (#\/ (setf (org-stat-cookie-n2 res) (parse-number (consume-until (matches :stat-cookie-end)))))
39
           (#\% (setf (org-stat-cookie-n1 res) (/  (org-stat-cookie-n1 res) 100))))
40
         res))))
41